match-sorter
Advanced tools
Comparing version 1.4.1-beta.0 to 1.4.1
@@ -271,4 +271,4 @@ 'use strict'; | ||
matchSorter.default = matchSorter; | ||
module.exports = matchSorter; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
module.exports = matchSorter; | ||
} else if (typeof define === 'function' && define.amd) { | ||
@@ -275,0 +275,0 @@ // eslint-disable-line |
@@ -432,4 +432,4 @@ var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {} | ||
matchSorter.default = matchSorter; | ||
module.exports = matchSorter; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
module.exports = matchSorter; | ||
} else if (typeof define === 'function' && define.amd) { | ||
@@ -436,0 +436,0 @@ // eslint-disable-line |
@@ -1,2 +0,2 @@ | ||
function interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function createCommonjsModule(e,t){return t={exports:{}},e(t,t.exports),t.exports}function matchSorter(e,t){function r(e,r,n){var o=getHighestRanking(r,a,t,s),i=o.rank,b=o.keyIndex;return i>=l&&e.push({item:r,rank:i,index:n,keyIndex:b}),e}var s=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],a=s.keys,n=s.threshold,l=void 0===n?rankings.MATCHES:n,o=e.reduce(r,[]);return o.sort(sortRankedItems).map(function(e){var t=e.item;return t})}function getHighestRanking(e,t,r,s){if(!t)return{rank:getMatchRanking(e,r,s),keyIndex:-1};var a=getAllValuesToRank(e,t);return a.reduce(function(e,t,a){var n=e.rank,l=e.keyIndex,o=getMatchRanking(t,r,s);return o>n&&(n=o,l=a),{rank:n,keyIndex:l}},{rank:rankings.NO_MATCH,keyIndex:-1})}function getMatchRanking(e,t,r){return e=prepareValueForComparison(e,r),t=prepareValueForComparison(t,r),t.length>e.length?rankings.NO_MATCH:e===t?rankings.EQUAL:0===e.indexOf(t)?rankings.STARTS_WITH:e.indexOf(" "+t)!==-1?rankings.WORD_STARTS_WITH:e.indexOf(t)!==-1?rankings.CONTAINS:1===t.length?rankings.NO_MATCH:getAcronym(e).indexOf(t)!==-1?rankings.ACRONYM:stringsByCharOrder(e,t)}function getAcronym(e){var t="",r=e.split(" ");return r.forEach(function(e){var r=e.split("-");r.forEach(function(e){t+=e.substr(0,1)})}),t}function stringsByCharOrder(e,t){function r(e,t){for(var r=!1,a=s;a<t.length;a++){var n=t[a];if(n===e){r=!0,s=a+1;break}}return r}for(var s=0,a=0;a<t.length;a++){var n=t[a],l=r(n,e);if(!l)return rankings.NO_MATCH}return rankings.MATCHES}function sortRankedItems(e,t){var r=-1,s=1,a=e.rank,n=e.index,l=e.keyIndex,o=t.rank,i=t.index,b=t.keyIndex,f=a===o;return f?l===b?n<i?r:s:l<b?r:s:a>o?r:s}function prepareValueForComparison(e,t){var r=t.keepDiacritics;return e=""+e,r||(e=diacritics$1.clean(e)),e.toLowerCase()}function getItemValue(e,t){var r=t.indexOf(".")!==-1;return r?t.split(".").reduce(function(e,t){return e[t]},e):e[t]}function getAllValuesToRank(e,t){return t.reduce(function(t,r){return t.concat(getItemValue(e,r))},[])}var commonjsGlobal="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},diacritics=createCommonjsModule(function(e){!function(t,r){"undefined"!=typeof e&&e.exports?e.exports=r():"function"==typeof define&&define.amd?define(r):this[t]=r()}("Diacritics",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++)r=a[n],s+=r in e.map?e.map[r]:r;return s},e})}),diacritics$1=interopDefault(diacritics),globalObject=createCommonjsModule(function(module){!function(e){try{e("export default global")}catch(t){try{e("export default self")}catch(e){try{module.exports=commonjsGlobal}catch(e){try{self.global=self}catch(e){window.global=window}}}}}(eval)}),globalObject$1=interopDefault(globalObject),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},rankings={EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0};matchSorter.rankings=rankings,"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?(matchSorter.default=matchSorter,Object.defineProperty(exports,"__esModule",{value:!0}),module.exports=matchSorter):"function"==typeof define&&define.amd?define(function(){return matchSorter}):globalObject$1.matchSorter=matchSorter; | ||
function interopDefault(e){return e&&"object"==typeof e&&"default"in e?e["default"]:e}function createCommonjsModule(e,t){return t={exports:{}},e(t,t.exports),t.exports}function matchSorter(e,t){function r(e,r,n){var o=getHighestRanking(r,a,t,s),i=o.rank,b=o.keyIndex;return i>=l&&e.push({item:r,rank:i,index:n,keyIndex:b}),e}var s=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],a=s.keys,n=s.threshold,l=void 0===n?rankings.MATCHES:n,o=e.reduce(r,[]);return o.sort(sortRankedItems).map(function(e){var t=e.item;return t})}function getHighestRanking(e,t,r,s){if(!t)return{rank:getMatchRanking(e,r,s),keyIndex:-1};var a=getAllValuesToRank(e,t);return a.reduce(function(e,t,a){var n=e.rank,l=e.keyIndex,o=getMatchRanking(t,r,s);return o>n&&(n=o,l=a),{rank:n,keyIndex:l}},{rank:rankings.NO_MATCH,keyIndex:-1})}function getMatchRanking(e,t,r){return e=prepareValueForComparison(e,r),t=prepareValueForComparison(t,r),t.length>e.length?rankings.NO_MATCH:e===t?rankings.EQUAL:0===e.indexOf(t)?rankings.STARTS_WITH:e.indexOf(" "+t)!==-1?rankings.WORD_STARTS_WITH:e.indexOf(t)!==-1?rankings.CONTAINS:1===t.length?rankings.NO_MATCH:getAcronym(e).indexOf(t)!==-1?rankings.ACRONYM:stringsByCharOrder(e,t)}function getAcronym(e){var t="",r=e.split(" ");return r.forEach(function(e){var r=e.split("-");r.forEach(function(e){t+=e.substr(0,1)})}),t}function stringsByCharOrder(e,t){function r(e,t){for(var r=!1,a=s;a<t.length;a++){var n=t[a];if(n===e){r=!0,s=a+1;break}}return r}for(var s=0,a=0;a<t.length;a++){var n=t[a],l=r(n,e);if(!l)return rankings.NO_MATCH}return rankings.MATCHES}function sortRankedItems(e,t){var r=-1,s=1,a=e.rank,n=e.index,l=e.keyIndex,o=t.rank,i=t.index,b=t.keyIndex,f=a===o;return f?l===b?n<i?r:s:l<b?r:s:a>o?r:s}function prepareValueForComparison(e,t){var r=t.keepDiacritics;return e=""+e,r||(e=diacritics$1.clean(e)),e.toLowerCase()}function getItemValue(e,t){var r=t.indexOf(".")!==-1;return r?t.split(".").reduce(function(e,t){return e[t]},e):e[t]}function getAllValuesToRank(e,t){return t.reduce(function(t,r){return t.concat(getItemValue(e,r))},[])}var commonjsGlobal="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},diacritics=createCommonjsModule(function(e){!function(t,r){"undefined"!=typeof e&&e.exports?e.exports=r():"function"==typeof define&&define.amd?define(r):this[t]=r()}("Diacritics",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++)r=a[n],s+=r in e.map?e.map[r]:r;return s},e})}),diacritics$1=interopDefault(diacritics),globalObject=createCommonjsModule(function(module){!function(e){try{e("export default global")}catch(t){try{e("export default self")}catch(t){try{module.exports=commonjsGlobal}catch(t){try{self.global=self}catch(t){window.global=window}}}}}(eval)}),globalObject$1=interopDefault(globalObject),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},rankings={EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0};matchSorter.rankings=rankings,"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?(matchSorter["default"]=matchSorter,module.exports=matchSorter,Object.defineProperty(exports,"__esModule",{value:!0})):"function"==typeof define&&define.amd?define(function(){return matchSorter}):globalObject$1.matchSorter=matchSorter; | ||
//# sourceMappingURL=match-sorter.min.js.map |
@@ -5,14 +5,14 @@ { | ||
{ | ||
"raw": "diacritic", | ||
"raw": "diacritic@0.0.2", | ||
"scope": null, | ||
"escapedName": "diacritic", | ||
"name": "diacritic", | ||
"rawSpec": "", | ||
"spec": "latest", | ||
"type": "tag" | ||
"rawSpec": "0.0.2", | ||
"spec": "0.0.2", | ||
"type": "version" | ||
}, | ||
"/Users/kdodds/Developer/match-sorter" | ||
"/home/travis/build/kentcdodds/match-sorter" | ||
] | ||
], | ||
"_from": "diacritic@latest", | ||
"_from": "diacritic@0.0.2", | ||
"_id": "diacritic@0.0.2", | ||
@@ -29,12 +29,11 @@ "_inCache": true, | ||
"_requested": { | ||
"raw": "diacritic", | ||
"raw": "diacritic@0.0.2", | ||
"scope": null, | ||
"escapedName": "diacritic", | ||
"name": "diacritic", | ||
"rawSpec": "", | ||
"spec": "latest", | ||
"type": "tag" | ||
"rawSpec": "0.0.2", | ||
"spec": "0.0.2", | ||
"type": "version" | ||
}, | ||
"_requiredBy": [ | ||
"#USER", | ||
"/" | ||
@@ -45,4 +44,4 @@ ], | ||
"_shrinkwrap": null, | ||
"_spec": "diacritic", | ||
"_where": "/Users/kdodds/Developer/match-sorter", | ||
"_spec": "diacritic@0.0.2", | ||
"_where": "/home/travis/build/kentcdodds/match-sorter", | ||
"author": { | ||
@@ -49,0 +48,0 @@ "name": "Nijiko Yonskai" |
@@ -5,14 +5,14 @@ { | ||
{ | ||
"raw": "global-object", | ||
"raw": "global-object@1.0.0", | ||
"scope": null, | ||
"escapedName": "global-object", | ||
"name": "global-object", | ||
"rawSpec": "", | ||
"spec": "latest", | ||
"type": "tag" | ||
"rawSpec": "1.0.0", | ||
"spec": "1.0.0", | ||
"type": "version" | ||
}, | ||
"/Users/kdodds/Developer/match-sorter" | ||
"/home/travis/build/kentcdodds/match-sorter" | ||
] | ||
], | ||
"_from": "global-object@latest", | ||
"_from": "global-object@1.0.0", | ||
"_id": "global-object@1.0.0", | ||
@@ -30,12 +30,11 @@ "_inCache": true, | ||
"_requested": { | ||
"raw": "global-object", | ||
"raw": "global-object@1.0.0", | ||
"scope": null, | ||
"escapedName": "global-object", | ||
"name": "global-object", | ||
"rawSpec": "", | ||
"spec": "latest", | ||
"type": "tag" | ||
"rawSpec": "1.0.0", | ||
"spec": "1.0.0", | ||
"type": "version" | ||
}, | ||
"_requiredBy": [ | ||
"#USER", | ||
"/" | ||
@@ -46,4 +45,4 @@ ], | ||
"_shrinkwrap": null, | ||
"_spec": "global-object", | ||
"_where": "/Users/kdodds/Developer/match-sorter", | ||
"_spec": "global-object@1.0.0", | ||
"_where": "/home/travis/build/kentcdodds/match-sorter", | ||
"author": { | ||
@@ -50,0 +49,0 @@ "name": "Andrea Giammarchi" |
{ | ||
"name": "match-sorter", | ||
"version": "v1.4.1-beta.0", | ||
"version": "1.4.1", | ||
"description": "Simple, expected, and deterministic best-match sorting of an array in JavaScript", | ||
@@ -95,2 +95,2 @@ "main": "dist/cjs/index.js", | ||
"homepage": "https://github.com/kentcdodds/match-sorter#readme" | ||
} | ||
} |
119
README.md
@@ -12,3 +12,3 @@ # match-sorter | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors) | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors) | ||
[![PRs Welcome][prs-badge]][prs] | ||
@@ -45,4 +45,7 @@ [![Donate][donate-badge]][donate] | ||
## Installation | ||
## Getting Started | ||
### Installation | ||
This module is distributed via [npm][npm] which is bundled with [node][node] and should | ||
@@ -55,3 +58,3 @@ be installed as one of your project's `dependencies`: | ||
## Usage | ||
### Usage | ||
@@ -66,5 +69,13 @@ ```javascript | ||
matchSorter(list, 'z') // [] | ||
``` | ||
// You can also pass an options object: | ||
// **keys** (defaults to undefined and just uses the value itself as above) | ||
## Advanced options | ||
### keys: `[string]` | ||
_Default: `undefined`_ | ||
By default it just uses the value itself as above. Passing an array tells match-sorter which keys to use for the ranking. | ||
```javascript | ||
const objList = [ | ||
@@ -76,6 +87,12 @@ {name: 'Janice', color: 'Green'}, | ||
] | ||
matchSorter(objList, 'g', {keys: ['name', 'color']}) // [{name: 'George', color: 'Blue'}, {name: 'Janice', color: 'Green'}] | ||
matchSorter(objList, 're', {keys: ['color', 'name']}) // [{name: 'Jen', color: 'Red'}, {name: 'Janice', color: 'Green'}, {name: 'Fred', color: 'Orange'}] | ||
matchSorter(objList, 'g', {keys: ['name', 'color']}) | ||
// [{name: 'George', color: 'Blue'}, {name: 'Janice', color: 'Green'}] | ||
// You can specify a key that is an array of values and the best match from that value is the one that's used for the ranking | ||
matchSorter(objList, 're', {keys: ['color', 'name']}) | ||
// [{name: 'Jen', color: 'Red'}, {name: 'Janice', color: 'Green'}, {name: 'Fred', color: 'Orange'}] | ||
``` | ||
__Array of values__: When the specified key matches an array of values, the best match from the values of in the array is going to be used for the ranking. | ||
```javascript | ||
const iceCreamYum = [ | ||
@@ -86,5 +103,9 @@ {favoriteIceCream: ['mint', 'chocolate']}, | ||
] | ||
matchSorter(iceCreamYum, 'cc', {keys: 'favoriteIceCream'}) // [{favoriteIceCream: ['candy cane', 'brownie']}, {favoriteIceCream: ['mint', 'chocolate']}] | ||
matchSorter(iceCreamYum, 'cc', {keys: ['favoriteIceCream']}) | ||
// [{favoriteIceCream: ['candy cane', 'brownie']}, {favoriteIceCream: ['mint', 'chocolate']}] | ||
``` | ||
// this also works with **nested keys** | ||
__Nested Keys__: You can specify nested keys using dot-notation. | ||
```javascript | ||
const nestedObjList = [ | ||
@@ -96,37 +117,61 @@ {name: {first: 'Janice'}}, | ||
] | ||
matchSorter(nestedObjList, 'j', {keys: ['name.first']}) // [{name: {first: 'Janice'}}, {name: {first: 'Jen'}}] | ||
matchSorter(nestedObjList, 'j', {keys: ['name.first']}) | ||
// [{name: {first: 'Janice'}}, {name: {first: 'Jen'}}] | ||
``` | ||
// **threshold** (defaults to MATCH) | ||
### threshold: `number` | ||
_Default: `MATCHES`_ | ||
Thresholds can be used to specify the criteria used to rank the results. | ||
Available thresholds (from top to bottom) are: | ||
* EQUAL | ||
* STARTS_WITH | ||
* WORD_STARTS_WITH | ||
* CONTAINS | ||
* ACRONYM | ||
* MATCHES _(default value)_ | ||
* NO_MATCH | ||
```javascript | ||
const fruit = ['orange', 'apple', 'grape', 'banana'] | ||
matchSorter(fruit, 'ap', {threshold: matchSorter.rankings.NO_MATCH}) // ['apple', 'grape', 'orange', 'banana'] (returns all items, just sorted by best match) | ||
matchSorter(fruit, 'ap', {threshold: matchSorter.rankings.NO_MATCH}) | ||
// ['apple', 'grape', 'orange', 'banana'] (returns all items, just sorted by best match) | ||
const things = ['google', 'airbnb', 'apple', 'apply', 'app'], | ||
matchSorter(things, 'app', {threshold: matchSorter.rankings.EQUAL}) // ['app'] (only items that are equal) | ||
matchSorter(things, 'app', {threshold: matchSorter.rankings.EQUAL}) | ||
// ['app'] (only items that are equal) | ||
const otherThings = ['fiji apple', 'google', 'app', 'crabapple', 'apple', 'apply'] | ||
matchSorter(otherThings, 'app', {threshold: matchSorter.rankings.WORD_STARTS_WITH}) // ['app', 'apple', 'apply', 'fiji apple'] (everything that matches with "word starts with" or better) | ||
matchSorter(otherThings, 'app', {threshold: matchSorter.rankings.WORD_STARTS_WITH}) | ||
// ['app', 'apple', 'apply', 'fiji apple'] (everything that matches with "word starts with" or better) | ||
``` | ||
/* | ||
* Available thresholds (from top to bottom) are: | ||
* - EQUAL | ||
* - STARTS_WITH | ||
* - WORD_STARTS_WITH | ||
* - CONTAINS | ||
* - ACRONYM | ||
* - MATCHES | ||
* - NO_MATCH | ||
*/ | ||
### keepDiacritics: `boolean` | ||
// **keepDiacritics** (defaults to false) | ||
// by default, match-sorter will strip diacritics before doing any comparisons. | ||
// this is the default because it makes the most sense from a UX perspective. | ||
// You can disable this behavior by specifying keepDiacritics: false | ||
_Default: `false`_ | ||
By default, match-sorter will strip diacritics before doing any comparisons. | ||
This is the default because it makes the most sense from a UX perspective. | ||
You can disable this behavior by specifying `keepDiacritics: true` | ||
```javascript | ||
const thingsWithDiacritics = ['jalapeño', 'à la carte', 'café', 'papier-mâché', 'à la mode'] | ||
matchSorter(thingsWithDiacritics, 'aa') // ['jalapeño', 'à la carte', 'papier-mâché', 'à la mode'] | ||
matchSorter(thingsWithDiacritics, 'aa', {keepDiacritics: true}) // ['jalapeño', 'à la carte'] | ||
matchSorter(thingsWithDiacritics, 'à', {keepDiacritics: true}) // ['à la carte', 'à la mode'] | ||
matchSorter(thingsWithDiacritics, 'aa') | ||
// ['jalapeño', 'à la carte', 'papier-mâché', 'à la mode'] | ||
matchSorter(thingsWithDiacritics, 'aa', {keepDiacritics: true}) | ||
// ['jalapeño', 'à la carte'] | ||
matchSorter(thingsWithDiacritics, 'à', {keepDiacritics: true}) | ||
// ['à la carte', 'à la mode'] | ||
``` | ||
> In the examples above, we're using CommonJS. If you're using ES6 modules, then you can do: | ||
> | ||
> `import matchSorter, {rankings} from 'match-sorter'` | ||
## Using ES6? | ||
In the examples above, we're using CommonJS. If you're using ES6 modules, then you can do: | ||
`import matchSorter, {rankings} from 'match-sorter'` | ||
## Inspiration | ||
@@ -145,4 +190,4 @@ | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) 👀 | [<img src="https://avatars.githubusercontent.com/u/8263298?v=3" width="100px;"/><br /><sub>Conor Hastings</sub>](http://conorhastings.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings) [📖](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings) [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings) 👀 | | ||
| :---: | :---: | | ||
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) 👀 | [<img src="https://avatars.githubusercontent.com/u/8263298?v=3" width="100px;"/><br /><sub>Conor Hastings</sub>](http://conorhastings.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings) [📖](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings) [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings) 👀 | [<img src="https://avatars.githubusercontent.com/u/574806?v=3" width="100px;"/><br /><sub>Rogelio Guzman</sub>](https://github.com/rogeliog)<br />[📖](https://github.com/kentcdodds/match-sorter/commits?author=rogeliog) | | ||
| :---: | :---: | :---: | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
@@ -149,0 +194,0 @@ |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
95705
0
226
0