match-sorter
Advanced tools
Comparing version 2.2.3 to 2.3.0
@@ -233,5 +233,7 @@ 'use strict'; | ||
rank = _getHighestRanking.rank, | ||
keyIndex = _getHighestRanking.keyIndex; | ||
keyIndex = _getHighestRanking.keyIndex, | ||
_getHighestRanking$ke = _getHighestRanking.keyThreshold, | ||
keyThreshold = _getHighestRanking$ke === undefined ? threshold : _getHighestRanking$ke; | ||
if (rank >= threshold) { | ||
if (rank >= keyThreshold) { | ||
matches.push({ item: item, rank: rank, index: index, keyIndex: keyIndex }); | ||
@@ -253,7 +255,11 @@ } | ||
* @param {Object} options - options to control the ranking | ||
* @return {Number} - the highest ranking | ||
* @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking | ||
*/ | ||
function getHighestRanking(item, keys, value, options) { | ||
if (!keys) { | ||
return { rank: getMatchRanking(item, value, options), keyIndex: -1 }; | ||
return { | ||
rank: getMatchRanking(item, value, options), | ||
keyIndex: -1, | ||
keyThreshold: options.threshold | ||
}; | ||
} | ||
@@ -263,3 +269,4 @@ var valuesToRank = getAllValuesToRank(item, keys); | ||
var rank = _ref2.rank, | ||
keyIndex = _ref2.keyIndex; | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
var itemValue = _ref3.itemValue, | ||
@@ -270,3 +277,4 @@ attributes = _ref3.attributes; | ||
var minRanking = attributes.minRanking, | ||
maxRanking = attributes.maxRanking; | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
@@ -281,5 +289,6 @@ if (newRank < minRanking && newRank >= rankings.MATCHES) { | ||
keyIndex = i; | ||
keyThreshold = threshold; | ||
} | ||
return { rank: rank, keyIndex: keyIndex }; | ||
}, { rank: rankings.NO_MATCH, keyIndex: -1 }); | ||
return { rank: rank, keyIndex: keyIndex, keyThreshold: keyThreshold }; | ||
}, { rank: rankings.NO_MATCH, keyIndex: -1, keyThreshold: options.threshold }); | ||
} | ||
@@ -286,0 +295,0 @@ |
@@ -231,5 +231,7 @@ function createCommonjsModule(fn, module) { | ||
rank = _getHighestRanking.rank, | ||
keyIndex = _getHighestRanking.keyIndex; | ||
keyIndex = _getHighestRanking.keyIndex, | ||
_getHighestRanking$ke = _getHighestRanking.keyThreshold, | ||
keyThreshold = _getHighestRanking$ke === undefined ? threshold : _getHighestRanking$ke; | ||
if (rank >= threshold) { | ||
if (rank >= keyThreshold) { | ||
matches.push({ item: item, rank: rank, index: index, keyIndex: keyIndex }); | ||
@@ -251,7 +253,11 @@ } | ||
* @param {Object} options - options to control the ranking | ||
* @return {Number} - the highest ranking | ||
* @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking | ||
*/ | ||
function getHighestRanking(item, keys, value, options) { | ||
if (!keys) { | ||
return { rank: getMatchRanking(item, value, options), keyIndex: -1 }; | ||
return { | ||
rank: getMatchRanking(item, value, options), | ||
keyIndex: -1, | ||
keyThreshold: options.threshold | ||
}; | ||
} | ||
@@ -261,3 +267,4 @@ var valuesToRank = getAllValuesToRank(item, keys); | ||
var rank = _ref2.rank, | ||
keyIndex = _ref2.keyIndex; | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
var itemValue = _ref3.itemValue, | ||
@@ -268,3 +275,4 @@ attributes = _ref3.attributes; | ||
var minRanking = attributes.minRanking, | ||
maxRanking = attributes.maxRanking; | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
@@ -279,5 +287,6 @@ if (newRank < minRanking && newRank >= rankings.MATCHES) { | ||
keyIndex = i; | ||
keyThreshold = threshold; | ||
} | ||
return { rank: rank, keyIndex: keyIndex }; | ||
}, { rank: rankings.NO_MATCH, keyIndex: -1 }); | ||
return { rank: rank, keyIndex: keyIndex, keyThreshold: keyThreshold }; | ||
}, { rank: rankings.NO_MATCH, keyIndex: -1, keyThreshold: options.threshold }); | ||
} | ||
@@ -284,0 +293,0 @@ |
@@ -237,5 +237,7 @@ (function (global, factory) { | ||
rank = _getHighestRanking.rank, | ||
keyIndex = _getHighestRanking.keyIndex; | ||
keyIndex = _getHighestRanking.keyIndex, | ||
_getHighestRanking$ke = _getHighestRanking.keyThreshold, | ||
keyThreshold = _getHighestRanking$ke === undefined ? threshold : _getHighestRanking$ke; | ||
if (rank >= threshold) { | ||
if (rank >= keyThreshold) { | ||
matches.push({ item: item, rank: rank, index: index, keyIndex: keyIndex }); | ||
@@ -257,7 +259,11 @@ } | ||
* @param {Object} options - options to control the ranking | ||
* @return {Number} - the highest ranking | ||
* @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking | ||
*/ | ||
function getHighestRanking(item, keys, value, options) { | ||
if (!keys) { | ||
return { rank: getMatchRanking(item, value, options), keyIndex: -1 }; | ||
return { | ||
rank: getMatchRanking(item, value, options), | ||
keyIndex: -1, | ||
keyThreshold: options.threshold | ||
}; | ||
} | ||
@@ -267,3 +273,4 @@ var valuesToRank = getAllValuesToRank(item, keys); | ||
var rank = _ref2.rank, | ||
keyIndex = _ref2.keyIndex; | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
var itemValue = _ref3.itemValue, | ||
@@ -274,3 +281,4 @@ attributes = _ref3.attributes; | ||
var minRanking = attributes.minRanking, | ||
maxRanking = attributes.maxRanking; | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
@@ -285,5 +293,6 @@ if (newRank < minRanking && newRank >= rankings.MATCHES) { | ||
keyIndex = i; | ||
keyThreshold = threshold; | ||
} | ||
return { rank: rank, keyIndex: keyIndex }; | ||
}, { rank: rankings.NO_MATCH, keyIndex: -1 }); | ||
return { rank: rank, keyIndex: keyIndex, keyThreshold: keyThreshold }; | ||
}, { rank: rankings.NO_MATCH, keyIndex: -1, keyThreshold: options.threshold }); | ||
} | ||
@@ -290,0 +299,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.matchSorter=t()}(this,function(){"use strict";var e,t=(function(e){!function(t,r){e.exports?e.exports=r():this.Diacritics=r()}(0,function(){for(var e={map:{}},t=[{base:" ",letters:" "},{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"Th",letters:"Þ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"ff",letters:"ff"},{base:"fi",letters:"fi"},{base:"fl",letters:"fl"},{base:"ffi",letters:"ffi"},{base:"ffl",letters:"ffl"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nñnⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥлԉ"},{base:"nj",letters:"nj"},{base:"o",letters:"߀oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oe",letters:"Œœ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"ss",letters:"ß"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"th",letters:"þ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],r=0,s=t.length;r<s;r++)for(var a=t[r].letters.split(""),n=0,l=a.length;n<l;n++)e.map[a[n]]=t[r].base;return e.clean=function(t){if(!t||!t.length||t.length<1)return"";for(var r,s="",a=t.split(""),n=0,l=a.length;n<l;n++)s+=(r=a[n])in e.map?e.map[r]:r;return s},e})}(e={exports:{}},e.exports),e.exports),r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},a={CASE_SENSITIVE_EQUAL:9,EQUAL:8,STARTS_WITH:7,WORD_STARTS_WITH:6,STRING_CASE:5,STRING_CASE_ACRONYM:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0},n={CAMEL:.8,PASCAL:.6,KEBAB:.4,SNAKE:.2,NO_CASE:0};function l(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t)return e;var l=n.keys,i=n.threshold,u=void 0===i?a.MATCHES:i;return e.reduce(function(e,o,i){var f=function(e,t,n,l){if(!t)return{rank:b(e,n,l),keyIndex:-1};return function(e,t){return t.reduce(function(t,a){var n=function(e,t){"object"===(void 0===t?"undefined":r(t))&&(t=t.key);var s=void 0;s="function"==typeof t?t(e):-1!==t.indexOf(".")?t.split(".").reduce(function(e,t){return e?e[t]:null},e):e[t];return null!=s?[].concat(s):null}(e,a);return n&&n.forEach(function(e){t.push({itemValue:e,attributes:function(e){"string"==typeof e&&(e={key:e});return s({maxRanking:1/0,minRanking:-1/0},e)}(a)})}),t},[])}(e,t).reduce(function(e,t,r){var s=e.rank,o=e.keyIndex,i=t.itemValue,u=t.attributes,f=b(i,n,l),c=u.minRanking,A=u.maxRanking;return f<c&&f>=a.MATCHES?f=c:f>A&&(f=A),f>s&&(s=f,o=r),{rank:s,keyIndex:o}},{rank:a.NO_MATCH,keyIndex:-1})}(o,l,t,n),c=f.rank,A=f.keyIndex;return c>=u&&e.push({item:o,rank:c,index:i,keyIndex:A}),e},[]).sort(o).map(function(e){return e.item})}function b(e,t,r){if(e=i(e,r),(t=i(t,r)).length>e.length)return a.NO_MATCH;if(e===t)return a.CASE_SENSITIVE_EQUAL;var s,l,b=function(e){var t=e.toLowerCase()!==e,r=e.indexOf("-")>=0,s=e.indexOf("_")>=0;if(!t&&!s&&r)return n.KEBAB;if(!t&&s&&!r)return n.SNAKE;if(t&&!r&&!s){var a=e[0].toUpperCase()===e[0];return a?n.PASCAL:n.CAMEL}return n.NO_CASE}(e),o=function(e,t,r){var s=e.toLowerCase().indexOf(t.toLowerCase());switch(r){case n.SNAKE:return"_"===e[s-1];case n.KEBAB:return"-"===e[s-1];case n.PASCAL:case n.CAMEL:return-1!==s&&e[s]===e[s].toUpperCase();default:return!1}}(e,t,b),u=function(e,t,r){var s=null;switch(r){case n.SNAKE:s="_";break;case n.KEBAB:s="-";break;case n.PASCAL:case n.CAMEL:s=/(?=[A-Z])/;break;default:s=null}var a=e.split(s);return t.toLowerCase().split("").reduce(function(e,t,r){var s=a[r];return e&&s&&s[0].toLowerCase()===t},!0)}(e,t,b);return(e=e.toLowerCase())===(t=t.toLowerCase())?a.EQUAL+b:0===e.indexOf(t)?a.STARTS_WITH+b:-1!==e.indexOf(" "+t)?a.WORD_STARTS_WITH+b:o?a.STRING_CASE+b:b>0&&u?a.STRING_CASE_ACRONYM+b:-1!==e.indexOf(t)?a.CONTAINS+b:1===t.length?a.NO_MATCH:-1!==(s=e,l="",s.split(" ").forEach(function(e){e.split("-").forEach(function(e){l+=e.substr(0,1)})}),l).indexOf(t)?a.ACRONYM+b:function(e,t){var r=0;function s(e,t,r){for(var s=r;s<t.length;s++){var a=t[s];if(a===e)return s+1}return-1}var n=s(t[0],e,0);if(n<0)return a.NO_MATCH;r=n;for(var l=1;l<t.length;l++){var b=t[l],o=(r=s(b,e,r))>-1;if(!o)return a.NO_MATCH}return function(e){var r=e-t.length+1,s=a.MATCHES+1/r;return s}(r-n)}(e,t)}function o(e,t){var r=e.rank,s=e.index,a=e.keyIndex,n=t.rank,l=t.index,b=t.keyIndex;return r===n?a===b?s<l?-1:1:a<b?-1:1:r>n?-1:1}function i(e,r){return e=""+e,r.keepDiacritics||(e=t.clean(e)),e}l.rankings=a,l.caseRankings=n;var u=Object.freeze({default:l,rankings:a}),f=l;return Object.assign(f,Object.keys(u).reduce(function(e,t){return"default"!==t&&(e[t]=u[t]),e},{})),f}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.matchSorter=t()}(this,function(){"use strict";var e,t=(function(e){!function(t,r){e.exports?e.exports=r():this.Diacritics=r()}(0,function(){for(var e={map:{}},t=[{base:" ",letters:" "},{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"Th",letters:"Þ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"ff",letters:"ff"},{base:"fi",letters:"fi"},{base:"fl",letters:"fl"},{base:"ffi",letters:"ffi"},{base:"ffl",letters:"ffl"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nñnⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥлԉ"},{base:"nj",letters:"nj"},{base:"o",letters:"߀oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oe",letters:"Œœ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"ss",letters:"ß"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"th",letters:"þ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],r=0,s=t.length;r<s;r++)for(var a=t[r].letters.split(""),n=0,l=a.length;n<l;n++)e.map[a[n]]=t[r].base;return e.clean=function(t){if(!t||!t.length||t.length<1)return"";for(var r,s="",a=t.split(""),n=0,l=a.length;n<l;n++)s+=(r=a[n])in e.map?e.map[r]:r;return s},e})}(e={exports:{}},e.exports),e.exports),r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},a={CASE_SENSITIVE_EQUAL:9,EQUAL:8,STARTS_WITH:7,WORD_STARTS_WITH:6,STRING_CASE:5,STRING_CASE_ACRONYM:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0},n={CAMEL:.8,PASCAL:.6,KEBAB:.4,SNAKE:.2,NO_CASE:0};function l(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t)return e;var l=n.keys,i=n.threshold,u=void 0===i?a.MATCHES:i;return e.reduce(function(e,b,i){var f=function(e,t,n,l){if(!t)return{rank:o(e,n,l),keyIndex:-1,keyThreshold:l.threshold};return function(e,t){return t.reduce(function(t,a){var n=function(e,t){"object"===(void 0===t?"undefined":r(t))&&(t=t.key);var s=void 0;s="function"==typeof t?t(e):-1!==t.indexOf(".")?t.split(".").reduce(function(e,t){return e?e[t]:null},e):e[t];return null!=s?[].concat(s):null}(e,a);return n&&n.forEach(function(e){t.push({itemValue:e,attributes:function(e){"string"==typeof e&&(e={key:e});return s({maxRanking:1/0,minRanking:-1/0},e)}(a)})}),t},[])}(e,t).reduce(function(e,t,r){var s=e.rank,b=e.keyIndex,i=e.keyThreshold,u=t.itemValue,f=t.attributes,c=o(u,n,l),A=f.minRanking,d=f.maxRanking,h=f.threshold;return c<A&&c>=a.MATCHES?c=A:c>d&&(c=d),c>s&&(s=c,b=r,i=h),{rank:s,keyIndex:b,keyThreshold:i}},{rank:a.NO_MATCH,keyIndex:-1,keyThreshold:l.threshold})}(b,l,t,n),c=f.rank,A=f.keyIndex,d=f.keyThreshold;return c>=(void 0===d?u:d)&&e.push({item:b,rank:c,index:i,keyIndex:A}),e},[]).sort(b).map(function(e){return e.item})}function o(e,t,r){if(e=i(e,r),(t=i(t,r)).length>e.length)return a.NO_MATCH;if(e===t)return a.CASE_SENSITIVE_EQUAL;var s,l,o=function(e){var t=e.toLowerCase()!==e,r=e.indexOf("-")>=0,s=e.indexOf("_")>=0;if(!t&&!s&&r)return n.KEBAB;if(!t&&s&&!r)return n.SNAKE;if(t&&!r&&!s){var a=e[0].toUpperCase()===e[0];return a?n.PASCAL:n.CAMEL}return n.NO_CASE}(e),b=function(e,t,r){var s=e.toLowerCase().indexOf(t.toLowerCase());switch(r){case n.SNAKE:return"_"===e[s-1];case n.KEBAB:return"-"===e[s-1];case n.PASCAL:case n.CAMEL:return-1!==s&&e[s]===e[s].toUpperCase();default:return!1}}(e,t,o),u=function(e,t,r){var s=null;switch(r){case n.SNAKE:s="_";break;case n.KEBAB:s="-";break;case n.PASCAL:case n.CAMEL:s=/(?=[A-Z])/;break;default:s=null}var a=e.split(s);return t.toLowerCase().split("").reduce(function(e,t,r){var s=a[r];return e&&s&&s[0].toLowerCase()===t},!0)}(e,t,o);return(e=e.toLowerCase())===(t=t.toLowerCase())?a.EQUAL+o:0===e.indexOf(t)?a.STARTS_WITH+o:-1!==e.indexOf(" "+t)?a.WORD_STARTS_WITH+o:b?a.STRING_CASE+o:o>0&&u?a.STRING_CASE_ACRONYM+o:-1!==e.indexOf(t)?a.CONTAINS+o:1===t.length?a.NO_MATCH:-1!==(s=e,l="",s.split(" ").forEach(function(e){e.split("-").forEach(function(e){l+=e.substr(0,1)})}),l).indexOf(t)?a.ACRONYM+o:function(e,t){var r=0;function s(e,t,r){for(var s=r;s<t.length;s++){var a=t[s];if(a===e)return s+1}return-1}var n=s(t[0],e,0);if(n<0)return a.NO_MATCH;r=n;for(var l=1;l<t.length;l++){var o=t[l],b=(r=s(o,e,r))>-1;if(!b)return a.NO_MATCH}return function(e){var r=e-t.length+1,s=a.MATCHES+1/r;return s}(r-n)}(e,t)}function b(e,t){var r=e.rank,s=e.index,a=e.keyIndex,n=t.rank,l=t.index,o=t.keyIndex;return r===n?a===o?s<l?-1:1:a<o?-1:1:r>n?-1:1}function i(e,r){return e=""+e,r.keepDiacritics||(e=t.clean(e)),e}l.rankings=a,l.caseRankings=n;var u=Object.freeze({default:l,rankings:a}),f=l;return Object.assign(f,Object.keys(u).reduce(function(e,t){return"default"!==t&&(e[t]=u[t]),e},{})),f}); | ||
//# sourceMappingURL=match-sorter.umd.min.js.map |
{ | ||
"name": "match-sorter", | ||
"version": "2.2.3", | ||
"version": "2.3.0", | ||
"description": "Simple, expected, and deterministic best-match sorting of an array in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/match-sorter.cjs.js", |
@@ -18,3 +18,3 @@ <div align="center"> | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors) | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors) | ||
[![PRs Welcome][prs-badge]][prs] | ||
@@ -58,17 +58,16 @@ [![Donate][donate-badge]][donate] | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
* [Getting Started](#getting-started) | ||
* [Installation](#installation) | ||
* [Usage](#usage) | ||
* [Advanced options](#advanced-options) | ||
* [keys: `[string]`](#keys-string) | ||
* [threshold: `number`](#threshold-number) | ||
* [keepDiacritics: `boolean`](#keepdiacritics-boolean) | ||
* [Using ES6?](#using-es6) | ||
* [Inspiration](#inspiration) | ||
* [Other Solutions](#other-solutions) | ||
* [Contributors](#contributors) | ||
* [LICENSE](#license) | ||
- [Getting Started](#getting-started) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Advanced options](#advanced-options) | ||
- [keys: `[string]`](#keys-string) | ||
- [threshold: `number`](#threshold-number) | ||
- [keepDiacritics: `boolean`](#keepdiacritics-boolean) | ||
- [Using ES6?](#using-es6) | ||
- [Inspiration](#inspiration) | ||
- [Other Solutions](#other-solutions) | ||
- [Contributors](#contributors) | ||
- [LICENSE](#license) | ||
@@ -165,2 +164,12 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
**Threshold**: You may specify an individual threshold for specific keys. A key will only match if it meets the specified threshold. _For more information regarding thresholds [see below](#threshold-number)_ | ||
```javascript | ||
const list = [{name: 'Fred', color: 'Orange'}, {name: 'Jen', color: 'Red'}] | ||
matchSorter(list, 'ed', { | ||
keys: [{threshold: rankings.STARTS_WITH, key: 'name'}, 'color'], | ||
}) | ||
//[{name: 'Jen', color: 'Red'}] | ||
``` | ||
**Min and Max Ranking**: You may restrict specific keys to a minimum or maximum ranking by passing in an object. A key with a minimum rank will only get promoted if there is at least a simple match. | ||
@@ -204,12 +213,12 @@ | ||
* CASE_SENSITIVE_EQUAL | ||
* EQUAL | ||
* STARTS_WITH | ||
* WORD_STARTS_WITH | ||
* STRING_CASE | ||
* STRING_CASE_ACRONYM | ||
* CONTAINS | ||
* ACRONYM | ||
* MATCHES _(default value)_ | ||
* NO_MATCH | ||
- CASE_SENSITIVE_EQUAL | ||
- EQUAL | ||
- STARTS_WITH | ||
- WORD_STARTS_WITH | ||
- STRING_CASE | ||
- STRING_CASE_ACRONYM | ||
- CONTAINS | ||
- ACRONYM | ||
- MATCHES _(default value)_ | ||
- NO_MATCH | ||
@@ -276,7 +285,6 @@ ```javascript | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
<!-- prettier-ignore --> | ||
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds "Tests") [👀](#review-kentcdodds "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/8263298?v=3" width="100px;"/><br /><sub><b>Conor Hastings</b></sub>](http://conorhastings.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings "Code") [📖](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings "Documentation") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings "Tests") [👀](#review-conorhastings "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/574806?v=3" width="100px;"/><br /><sub><b>Rogelio Guzman</b></sub>](https://github.com/rogeliog)<br />[📖](https://github.com/kentcdodds/match-sorter/commits?author=rogeliog "Documentation") | [<img src="https://avatars.githubusercontent.com/u/1416436?v=3" width="100px;"/><br /><sub><b>Claudéric Demers</b></sub>](http://ced.io)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=clauderic "Code") [📖](https://github.com/kentcdodds/match-sorter/commits?author=clauderic "Documentation") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=clauderic "Tests") | [<img src="https://avatars3.githubusercontent.com/u/4150097?v=3" width="100px;"/><br /><sub><b>Kevin Davis</b></sub>](kevindav.us)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=osfan501 "Code") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=osfan501 "Tests") | [<img src="https://avatars1.githubusercontent.com/u/19157735?v=3" width="100px;"/><br /><sub><b>Denver Chen</b></sub>](https://github.com/nfdjps)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=nfdjps "Code") [📖](https://github.com/kentcdodds/match-sorter/commits?author=nfdjps "Documentation") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=nfdjps "Tests") | [<img src="https://avatars0.githubusercontent.com/u/12719057?v=4" width="100px;"/><br /><sub><b>Christian Ruigrok</b></sub>](http://ruigrok.info)<br />[🐛](https://github.com/kentcdodds/match-sorter/issues?q=author%3AChrisRu "Bug reports") [💻](https://github.com/kentcdodds/match-sorter/commits?author=ChrisRu "Code") [📖](https://github.com/kentcdodds/match-sorter/commits?author=ChrisRu "Documentation") | | ||
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | | ||
| [<img src="https://avatars1.githubusercontent.com/u/2084833?v=4" width="100px;"/><br /><sub><b>Hozefa</b></sub>](https://github.com/hozefaj)<br />[🐛](https://github.com/kentcdodds/match-sorter/issues?q=author%3Ahozefaj "Bug reports") [💻](https://github.com/kentcdodds/match-sorter/commits?author=hozefaj "Code") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=hozefaj "Tests") [🤔](#ideas-hozefaj "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/9403361?v=4" width="100px;"/><br /><sub><b>pushpinder107</b></sub>](https://github.com/pushpinder107)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=pushpinder107 "Code") | | ||
| [<img src="https://avatars1.githubusercontent.com/u/2084833?v=4" width="100px;"/><br /><sub><b>Hozefa</b></sub>](https://github.com/hozefaj)<br />[🐛](https://github.com/kentcdodds/match-sorter/issues?q=author%3Ahozefaj "Bug reports") [💻](https://github.com/kentcdodds/match-sorter/commits?author=hozefaj "Code") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=hozefaj "Tests") [🤔](#ideas-hozefaj "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/9403361?v=4" width="100px;"/><br /><sub><b>pushpinder107</b></sub>](https://github.com/pushpinder107)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=pushpinder107 "Code") | [<img src="https://avatars3.githubusercontent.com/u/200528?v=4" width="100px;"/><br /><sub><b>Mordy Tikotzky</b></sub>](https://github.com/tikotzky)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=tikotzky "Code") [📖](https://github.com/kentcdodds/match-sorter/commits?author=tikotzky "Documentation") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=tikotzky "Tests") | | ||
@@ -283,0 +291,0 @@ <!-- ALL-CONTRIBUTORS-LIST:END --> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
194638
1947
332