Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

match-sorter

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

match-sorter - npm Package Compare versions

Comparing version 6.2.0 to 6.3.0

4

dist/index.d.ts

@@ -24,2 +24,5 @@ declare type KeyAttributes = {

}
interface Sorter<ItemType> {
(matchItems: Array<RankedItem<ItemType>>): Array<RankedItem<ItemType>>;
}
interface KeyAttributesOptions<ItemType> {

@@ -37,2 +40,3 @@ key?: string | ValueGetterKey<ItemType>;

keepDiacritics?: boolean;
sorter?: Sorter<ItemType>;
}

@@ -39,0 +43,0 @@ declare const rankings: {

12

dist/match-sorter.cjs.js

@@ -47,7 +47,11 @@ 'use strict';

_options$baseSort = _options.baseSort,
baseSort = _options$baseSort === void 0 ? defaultBaseSortFn : _options$baseSort;
baseSort = _options$baseSort === void 0 ? defaultBaseSortFn : _options$baseSort,
_options$sorter = _options.sorter,
sorter = _options$sorter === void 0 ? function (matchedItems) {
return matchedItems.sort(function (a, b) {
return sortRankedValues(a, b, baseSort);
});
} : _options$sorter;
var matchedItems = items.reduce(reduceItemsToRanked, []);
return matchedItems.sort(function (a, b) {
return sortRankedValues(a, b, baseSort);
}).map(function (_ref) {
return sorter(matchedItems).map(function (_ref) {
var item = _ref.item;

@@ -54,0 +58,0 @@ return item;

@@ -38,7 +38,11 @@ import _extends from '@babel/runtime/helpers/esm/extends';

_options$baseSort = _options.baseSort,
baseSort = _options$baseSort === void 0 ? defaultBaseSortFn : _options$baseSort;
baseSort = _options$baseSort === void 0 ? defaultBaseSortFn : _options$baseSort,
_options$sorter = _options.sorter,
sorter = _options$sorter === void 0 ? function (matchedItems) {
return matchedItems.sort(function (a, b) {
return sortRankedValues(a, b, baseSort);
});
} : _options$sorter;
var matchedItems = items.reduce(reduceItemsToRanked, []);
return matchedItems.sort(function (a, b) {
return sortRankedValues(a, b, baseSort);
}).map(function (_ref) {
return sorter(matchedItems).map(function (_ref) {
var item = _ref.item;

@@ -45,0 +49,0 @@ return item;

@@ -480,7 +480,11 @@ (function (global, factory) {

_options$baseSort = _options.baseSort,
baseSort = _options$baseSort === void 0 ? defaultBaseSortFn : _options$baseSort;
baseSort = _options$baseSort === void 0 ? defaultBaseSortFn : _options$baseSort,
_options$sorter = _options.sorter,
sorter = _options$sorter === void 0 ? function (matchedItems) {
return matchedItems.sort(function (a, b) {
return sortRankedValues(a, b, baseSort);
});
} : _options$sorter;
var matchedItems = items.reduce(reduceItemsToRanked, []);
return matchedItems.sort(function (a, b) {
return sortRankedValues(a, b, baseSort);
}).map(function (_ref) {
return sorter(matchedItems).map(function (_ref) {
var item = _ref.item;

@@ -487,0 +491,0 @@ return item;

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).matchSorter={})}(this,(function(e){"use strict";function n(){return(n=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}var r={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Ấ":"A","Ắ":"A","Ẳ":"A","Ẵ":"A","Ặ":"A","Æ":"AE","Ầ":"A","Ằ":"A","Ȃ":"A","Ç":"C","Ḉ":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ế":"E","Ḗ":"E","Ề":"E","Ḕ":"E","Ḝ":"E","Ȇ":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ḯ":"I","Ȋ":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ố":"O","Ṍ":"O","Ṓ":"O","Ȏ":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","ấ":"a","ắ":"a","ẳ":"a","ẵ":"a","ặ":"a","æ":"ae","ầ":"a","ằ":"a","ȃ":"a","ç":"c","ḉ":"c","è":"e","é":"e","ê":"e","ë":"e","ế":"e","ḗ":"e","ề":"e","ḕ":"e","ḝ":"e","ȇ":"e","ì":"i","í":"i","î":"i","ï":"i","ḯ":"i","ȋ":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ố":"o","ṍ":"o","ṓ":"o","ȏ":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Ĉ":"C","ĉ":"c","Ċ":"C","ċ":"c","Č":"C","č":"c","C̆":"C","c̆":"c","Ď":"D","ď":"d","Đ":"D","đ":"d","Ē":"E","ē":"e","Ĕ":"E","ĕ":"e","Ė":"E","ė":"e","Ę":"E","ę":"e","Ě":"E","ě":"e","Ĝ":"G","Ǵ":"G","ĝ":"g","ǵ":"g","Ğ":"G","ğ":"g","Ġ":"G","ġ":"g","Ģ":"G","ģ":"g","Ĥ":"H","ĥ":"h","Ħ":"H","ħ":"h","Ḫ":"H","ḫ":"h","Ĩ":"I","ĩ":"i","Ī":"I","ī":"i","Ĭ":"I","ĭ":"i","Į":"I","į":"i","İ":"I","ı":"i","IJ":"IJ","ij":"ij","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","Ḱ":"K","ḱ":"k","K̆":"K","k̆":"k","Ĺ":"L","ĺ":"l","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ŀ":"L","ŀ":"l","Ł":"l","ł":"l","Ḿ":"M","ḿ":"m","M̆":"M","m̆":"m","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","ʼn":"n","N̆":"N","n̆":"n","Ō":"O","ō":"o","Ŏ":"O","ŏ":"o","Ő":"O","ő":"o","Œ":"OE","œ":"oe","P̆":"P","p̆":"p","Ŕ":"R","ŕ":"r","Ŗ":"R","ŗ":"r","Ř":"R","ř":"r","R̆":"R","r̆":"r","Ȓ":"R","ȓ":"r","Ś":"S","ś":"s","Ŝ":"S","ŝ":"s","Ş":"S","Ș":"S","ș":"s","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","ț":"t","Ț":"T","Ť":"T","ť":"t","Ŧ":"T","ŧ":"t","T̆":"T","t̆":"t","Ũ":"U","ũ":"u","Ū":"U","ū":"u","Ŭ":"U","ŭ":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ȗ":"U","ȗ":"u","V̆":"V","v̆":"v","Ŵ":"W","ŵ":"w","Ẃ":"W","ẃ":"w","X̆":"X","x̆":"x","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Y̆":"Y","y̆":"y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","ſ":"s","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Ǎ":"A","ǎ":"a","Ǐ":"I","ǐ":"i","Ǒ":"O","ǒ":"o","Ǔ":"U","ǔ":"u","Ǖ":"U","ǖ":"u","Ǘ":"U","ǘ":"u","Ǚ":"U","ǚ":"u","Ǜ":"U","ǜ":"u","Ứ":"U","ứ":"u","Ṹ":"U","ṹ":"u","Ǻ":"A","ǻ":"a","Ǽ":"AE","ǽ":"ae","Ǿ":"O","ǿ":"o","Þ":"TH","þ":"th","Ṕ":"P","ṕ":"p","Ṥ":"S","ṥ":"s","X́":"X","x́":"x","Ѓ":"Г","ѓ":"г","Ќ":"К","ќ":"к","A̋":"A","a̋":"a","E̋":"E","e̋":"e","I̋":"I","i̋":"i","Ǹ":"N","ǹ":"n","Ồ":"O","ồ":"o","Ṑ":"O","ṑ":"o","Ừ":"U","ừ":"u","Ẁ":"W","ẁ":"w","Ỳ":"Y","ỳ":"y","Ȁ":"A","ȁ":"a","Ȅ":"E","ȅ":"e","Ȉ":"I","ȉ":"i","Ȍ":"O","ȍ":"o","Ȑ":"R","ȑ":"r","Ȕ":"U","ȕ":"u","B̌":"B","b̌":"b","Č̣":"C","č̣":"c","Ê̌":"E","ê̌":"e","F̌":"F","f̌":"f","Ǧ":"G","ǧ":"g","Ȟ":"H","ȟ":"h","J̌":"J","ǰ":"j","Ǩ":"K","ǩ":"k","M̌":"M","m̌":"m","P̌":"P","p̌":"p","Q̌":"Q","q̌":"q","Ř̩":"R","ř̩":"r","Ṧ":"S","ṧ":"s","V̌":"V","v̌":"v","W̌":"W","w̌":"w","X̌":"X","x̌":"x","Y̌":"Y","y̌":"y","A̧":"A","a̧":"a","B̧":"B","b̧":"b","Ḑ":"D","ḑ":"d","Ȩ":"E","ȩ":"e","Ɛ̧":"E","ɛ̧":"e","Ḩ":"H","ḩ":"h","I̧":"I","i̧":"i","Ɨ̧":"I","ɨ̧":"i","M̧":"M","m̧":"m","O̧":"O","o̧":"o","Q̧":"Q","q̧":"q","U̧":"U","u̧":"u","X̧":"X","x̧":"x","Z̧":"Z","z̧":"z"},t=Object.keys(r).join("|"),a=new RegExp(t,"g"),u=new RegExp(t,""),o=function(e){return e.replace(a,(function(e){return r[e]}))},i=o,l=function(e){return!!e.match(u)},c=o;i.has=l,i.remove=c;var f={CASE_SENSITIVE_EQUAL:7,EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0};A.rankings=f;var s=function(e,n){return String(e.rankedValue).localeCompare(String(n.rankedValue))};function A(e,r,t){void 0===t&&(t={});var a=t,u=a.keys,o=a.threshold,i=void 0===o?f.MATCHES:o,l=a.baseSort,c=void 0===l?s:l;return e.reduce((function(e,a,o){var l=function(e,n,r,t){if(!n){return{rankedValue:e,rank:h(e,r,t),keyIndex:-1,keyThreshold:t.threshold}}return function(e,n){for(var r=[],t=0,a=n.length;t<a;t++)for(var u=n[t],o=y(u),i=O(e,u),l=0,c=i.length;l<c;l++)r.push({itemValue:i[l],attributes:o});return r}(e,n).reduce((function(e,n,a){var u=e.rank,o=e.rankedValue,i=e.keyIndex,l=e.keyThreshold,c=n.itemValue,s=n.attributes,A=h(c,r,t),d=o,O=s.minRanking,E=s.maxRanking,y=s.threshold;return A<O&&A>=f.MATCHES?A=O:A>E&&(A=E),A>u&&(u=A,i=a,l=y,d=c),{rankedValue:d,rank:u,keyIndex:i,keyThreshold:l}}),{rankedValue:e,rank:f.NO_MATCH,keyIndex:-1,keyThreshold:t.threshold})}(a,u,r,t),c=l.rank,s=l.keyThreshold;c>=(void 0===s?i:s)&&e.push(n({},l,{item:a,index:o}));return e}),[]).sort((function(e,n){return function(e,n,r){var t=-1,a=1,u=e.rank,o=e.keyIndex,i=n.rank,l=n.keyIndex;return u===i?o===l?r(e,n):o<l?t:a:u>i?t:a}(e,n,c)})).map((function(e){return e.item}))}function h(e,n,r){return e=d(e,r),(n=d(n,r)).length>e.length?f.NO_MATCH:e===n?f.CASE_SENSITIVE_EQUAL:(e=e.toLowerCase())===(n=n.toLowerCase())?f.EQUAL:e.startsWith(n)?f.STARTS_WITH:e.includes(" "+n)?f.WORD_STARTS_WITH:e.includes(n)?f.CONTAINS:1===n.length?f.NO_MATCH:(t=e,a="",t.split(" ").forEach((function(e){e.split("-").forEach((function(e){a+=e.substr(0,1)}))})),a).includes(n)?f.ACRONYM:function(e,n){var r=0,t=0;function a(e,n,t){for(var a=t,u=n.length;a<u;a++){if(n[a]===e)return r+=1,a+1}return-1}function u(e){var t=r/n.length;return f.MATCHES+t*(1/e)}var o=a(n[0],e,0);if(o<0)return f.NO_MATCH;t=o;for(var i=1,l=n.length;i<l;i++){if(!((t=a(n[i],e,t))>-1))return f.NO_MATCH}return u(t-o)}(e,n);var t,a}function d(e,n){return e=""+e,n.keepDiacritics||(e=i(e)),e}function O(e,n){var r;if("object"==typeof n&&(n=n.key),"function"==typeof n)r=n(e);else if(null==e)r=null;else if(Object.hasOwnProperty.call(e,n))r=e[n];else{if(n.includes("."))return function(e,n){for(var r=e.split("."),t=[n],a=0,u=r.length;a<u;a++){for(var o=r[a],i=[],l=0,c=t.length;l<c;l++){var f=t[l];if(null!=f)if(Object.hasOwnProperty.call(f,o)){var s=f[o];null!=s&&i.push(s)}else"*"===o&&(i=i.concat(f))}t=i}if(Array.isArray(t[0])){var A=[];return A.concat.apply(A,t)}return t}(n,e);r=null}return null==r?[]:Array.isArray(r)?r:[String(r)]}var E={maxRanking:1/0,minRanking:-1/0};function y(e){return"string"==typeof e?E:n({},E,e)}e.defaultBaseSortFn=s,e.matchSorter=A,e.rankings=f,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).matchSorter={})}(this,(function(e){"use strict";function n(){return(n=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}var r={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Ấ":"A","Ắ":"A","Ẳ":"A","Ẵ":"A","Ặ":"A","Æ":"AE","Ầ":"A","Ằ":"A","Ȃ":"A","Ç":"C","Ḉ":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ế":"E","Ḗ":"E","Ề":"E","Ḕ":"E","Ḝ":"E","Ȇ":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ḯ":"I","Ȋ":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ố":"O","Ṍ":"O","Ṓ":"O","Ȏ":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","ấ":"a","ắ":"a","ẳ":"a","ẵ":"a","ặ":"a","æ":"ae","ầ":"a","ằ":"a","ȃ":"a","ç":"c","ḉ":"c","è":"e","é":"e","ê":"e","ë":"e","ế":"e","ḗ":"e","ề":"e","ḕ":"e","ḝ":"e","ȇ":"e","ì":"i","í":"i","î":"i","ï":"i","ḯ":"i","ȋ":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ố":"o","ṍ":"o","ṓ":"o","ȏ":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Ĉ":"C","ĉ":"c","Ċ":"C","ċ":"c","Č":"C","č":"c","C̆":"C","c̆":"c","Ď":"D","ď":"d","Đ":"D","đ":"d","Ē":"E","ē":"e","Ĕ":"E","ĕ":"e","Ė":"E","ė":"e","Ę":"E","ę":"e","Ě":"E","ě":"e","Ĝ":"G","Ǵ":"G","ĝ":"g","ǵ":"g","Ğ":"G","ğ":"g","Ġ":"G","ġ":"g","Ģ":"G","ģ":"g","Ĥ":"H","ĥ":"h","Ħ":"H","ħ":"h","Ḫ":"H","ḫ":"h","Ĩ":"I","ĩ":"i","Ī":"I","ī":"i","Ĭ":"I","ĭ":"i","Į":"I","į":"i","İ":"I","ı":"i","IJ":"IJ","ij":"ij","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","Ḱ":"K","ḱ":"k","K̆":"K","k̆":"k","Ĺ":"L","ĺ":"l","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ŀ":"L","ŀ":"l","Ł":"l","ł":"l","Ḿ":"M","ḿ":"m","M̆":"M","m̆":"m","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","ʼn":"n","N̆":"N","n̆":"n","Ō":"O","ō":"o","Ŏ":"O","ŏ":"o","Ő":"O","ő":"o","Œ":"OE","œ":"oe","P̆":"P","p̆":"p","Ŕ":"R","ŕ":"r","Ŗ":"R","ŗ":"r","Ř":"R","ř":"r","R̆":"R","r̆":"r","Ȓ":"R","ȓ":"r","Ś":"S","ś":"s","Ŝ":"S","ŝ":"s","Ş":"S","Ș":"S","ș":"s","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","ț":"t","Ț":"T","Ť":"T","ť":"t","Ŧ":"T","ŧ":"t","T̆":"T","t̆":"t","Ũ":"U","ũ":"u","Ū":"U","ū":"u","Ŭ":"U","ŭ":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ȗ":"U","ȗ":"u","V̆":"V","v̆":"v","Ŵ":"W","ŵ":"w","Ẃ":"W","ẃ":"w","X̆":"X","x̆":"x","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Y̆":"Y","y̆":"y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","ſ":"s","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Ǎ":"A","ǎ":"a","Ǐ":"I","ǐ":"i","Ǒ":"O","ǒ":"o","Ǔ":"U","ǔ":"u","Ǖ":"U","ǖ":"u","Ǘ":"U","ǘ":"u","Ǚ":"U","ǚ":"u","Ǜ":"U","ǜ":"u","Ứ":"U","ứ":"u","Ṹ":"U","ṹ":"u","Ǻ":"A","ǻ":"a","Ǽ":"AE","ǽ":"ae","Ǿ":"O","ǿ":"o","Þ":"TH","þ":"th","Ṕ":"P","ṕ":"p","Ṥ":"S","ṥ":"s","X́":"X","x́":"x","Ѓ":"Г","ѓ":"г","Ќ":"К","ќ":"к","A̋":"A","a̋":"a","E̋":"E","e̋":"e","I̋":"I","i̋":"i","Ǹ":"N","ǹ":"n","Ồ":"O","ồ":"o","Ṑ":"O","ṑ":"o","Ừ":"U","ừ":"u","Ẁ":"W","ẁ":"w","Ỳ":"Y","ỳ":"y","Ȁ":"A","ȁ":"a","Ȅ":"E","ȅ":"e","Ȉ":"I","ȉ":"i","Ȍ":"O","ȍ":"o","Ȑ":"R","ȑ":"r","Ȕ":"U","ȕ":"u","B̌":"B","b̌":"b","Č̣":"C","č̣":"c","Ê̌":"E","ê̌":"e","F̌":"F","f̌":"f","Ǧ":"G","ǧ":"g","Ȟ":"H","ȟ":"h","J̌":"J","ǰ":"j","Ǩ":"K","ǩ":"k","M̌":"M","m̌":"m","P̌":"P","p̌":"p","Q̌":"Q","q̌":"q","Ř̩":"R","ř̩":"r","Ṧ":"S","ṧ":"s","V̌":"V","v̌":"v","W̌":"W","w̌":"w","X̌":"X","x̌":"x","Y̌":"Y","y̌":"y","A̧":"A","a̧":"a","B̧":"B","b̧":"b","Ḑ":"D","ḑ":"d","Ȩ":"E","ȩ":"e","Ɛ̧":"E","ɛ̧":"e","Ḩ":"H","ḩ":"h","I̧":"I","i̧":"i","Ɨ̧":"I","ɨ̧":"i","M̧":"M","m̧":"m","O̧":"O","o̧":"o","Q̧":"Q","q̧":"q","U̧":"U","u̧":"u","X̧":"X","x̧":"x","Z̧":"Z","z̧":"z"},t=Object.keys(r).join("|"),a=new RegExp(t,"g"),u=new RegExp(t,""),o=function(e){return e.replace(a,(function(e){return r[e]}))},i=o,l=function(e){return!!e.match(u)},c=o;i.has=l,i.remove=c;var f={CASE_SENSITIVE_EQUAL:7,EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0};A.rankings=f;var s=function(e,n){return String(e.rankedValue).localeCompare(String(n.rankedValue))};function A(e,r,t){void 0===t&&(t={});var a=t,u=a.keys,o=a.threshold,i=void 0===o?f.MATCHES:o,l=a.baseSort,c=void 0===l?s:l,A=a.sorter;return(void 0===A?function(e){return e.sort((function(e,n){return function(e,n,r){var t=-1,a=1,u=e.rank,o=e.keyIndex,i=n.rank,l=n.keyIndex;return u===i?o===l?r(e,n):o<l?t:a:u>i?t:a}(e,n,c)}))}:A)(e.reduce((function(e,a,o){var l=function(e,n,r,t){if(!n){return{rankedValue:e,rank:h(e,r,t),keyIndex:-1,keyThreshold:t.threshold}}return function(e,n){for(var r=[],t=0,a=n.length;t<a;t++)for(var u=n[t],o=y(u),i=O(e,u),l=0,c=i.length;l<c;l++)r.push({itemValue:i[l],attributes:o});return r}(e,n).reduce((function(e,n,a){var u=e.rank,o=e.rankedValue,i=e.keyIndex,l=e.keyThreshold,c=n.itemValue,s=n.attributes,A=h(c,r,t),d=o,O=s.minRanking,E=s.maxRanking,y=s.threshold;return A<O&&A>=f.MATCHES?A=O:A>E&&(A=E),A>u&&(u=A,i=a,l=y,d=c),{rankedValue:d,rank:u,keyIndex:i,keyThreshold:l}}),{rankedValue:e,rank:f.NO_MATCH,keyIndex:-1,keyThreshold:t.threshold})}(a,u,r,t),c=l.rank,s=l.keyThreshold;c>=(void 0===s?i:s)&&e.push(n({},l,{item:a,index:o}));return e}),[])).map((function(e){return e.item}))}function h(e,n,r){return e=d(e,r),(n=d(n,r)).length>e.length?f.NO_MATCH:e===n?f.CASE_SENSITIVE_EQUAL:(e=e.toLowerCase())===(n=n.toLowerCase())?f.EQUAL:e.startsWith(n)?f.STARTS_WITH:e.includes(" "+n)?f.WORD_STARTS_WITH:e.includes(n)?f.CONTAINS:1===n.length?f.NO_MATCH:(t=e,a="",t.split(" ").forEach((function(e){e.split("-").forEach((function(e){a+=e.substr(0,1)}))})),a).includes(n)?f.ACRONYM:function(e,n){var r=0,t=0;function a(e,n,t){for(var a=t,u=n.length;a<u;a++){if(n[a]===e)return r+=1,a+1}return-1}function u(e){var t=r/n.length;return f.MATCHES+t*(1/e)}var o=a(n[0],e,0);if(o<0)return f.NO_MATCH;t=o;for(var i=1,l=n.length;i<l;i++){if(!((t=a(n[i],e,t))>-1))return f.NO_MATCH}return u(t-o)}(e,n);var t,a}function d(e,n){return e=""+e,n.keepDiacritics||(e=i(e)),e}function O(e,n){var r;if("object"==typeof n&&(n=n.key),"function"==typeof n)r=n(e);else if(null==e)r=null;else if(Object.hasOwnProperty.call(e,n))r=e[n];else{if(n.includes("."))return function(e,n){for(var r=e.split("."),t=[n],a=0,u=r.length;a<u;a++){for(var o=r[a],i=[],l=0,c=t.length;l<c;l++){var f=t[l];if(null!=f)if(Object.hasOwnProperty.call(f,o)){var s=f[o];null!=s&&i.push(s)}else"*"===o&&(i=i.concat(f))}t=i}if(Array.isArray(t[0])){var A=[];return A.concat.apply(A,t)}return t}(n,e);r=null}return null==r?[]:Array.isArray(r)?r:[String(r)]}var E={maxRanking:1/0,minRanking:-1/0};function y(e){return"string"==typeof e?E:n({},E,e)}e.defaultBaseSortFn=s,e.matchSorter=A,e.rankings=f,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=match-sorter.umd.min.js.map
{
"name": "match-sorter",
"version": "6.2.0",
"version": "6.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",

@@ -71,2 +71,3 @@ <div align="center">

- [baseSort: `function(itemA, itemB): -1 | 0 | 1`](#basesort-functionitema-itemb--1--0--1)
- [sorter: `function(rankedItems): rankedItems`](#sorter-functionrankeditems-rankeditems)
- [Recipes](#recipes)

@@ -348,2 +349,27 @@ - [Match PascalCase, camelCase, snake_case, or kebab-case as words](#match-pascalcase-camelcase-snake_case-or-kebab-case-as-words)

### sorter: `function(rankedItems): rankedItems`
_Default:
`matchedItems => matchedItems.sort((a, b) => sortRankedValues(a, b, baseSort))`_
By default, match-sorter uses an internal `sortRankedValues` function to sort
items after matching them.
_You can customize the core sorting behavior by specifying a custom `sorter`
function:_
Disable sorting entirely:
```javascript
const list = ['appl', 'C apple', 'B apple', 'A apple', 'app', 'applebutter']
matchSorter(list, 'apple', {sorter: rankedItems => rankedItems})
// ['C apple', 'B apple', 'A apple', 'applebutter']
```
Return the unsorted rankedItems, but in reverse order:
```javascript
const list = ['appl', 'C apple', 'B apple', 'A apple', 'app', 'applebutter']
matchSorter(list, 'apple', {sorter: rankedItems => [...rankedItems].reverse()})
// ['applebutter', 'A apple', 'B apple', 'C apple']
```
## Recipes

@@ -465,3 +491,3 @@

<td align="center"><a href="https://michaeldeboey.be"><img src="https://avatars3.githubusercontent.com/u/6643991?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michaël De Boey</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/commits?author=MichaelDeBoey" title="Code">💻</a> <a href="https://github.com/kentcdodds/match-sorter/pulls?q=is%3Apr+reviewed-by%3AMichaelDeBoey" title="Reviewed Pull Requests">👀</a></td>
<td align="center"><a href="https://tannerlinsley.com"><img src="https://avatars0.githubusercontent.com/u/5580297?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tanner Linsley</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/commits?author=tannerlinsley" title="Code">💻</a></td>
<td align="center"><a href="https://tannerlinsley.com"><img src="https://avatars0.githubusercontent.com/u/5580297?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tanner Linsley</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/commits?author=tannerlinsley" title="Code">💻</a> <a href="https://github.com/kentcdodds/match-sorter/commits?author=tannerlinsley" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/SweVictor"><img src="https://avatars1.githubusercontent.com/u/449347?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Victor</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/commits?author=SweVictor" title="Documentation">📖</a></td>

@@ -468,0 +494,0 @@ <td align="center"><a href="https://github.com/RebeccaStevens"><img src="https://avatars1.githubusercontent.com/u/7224206?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rebecca Stevens</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/issues?q=author%3ARebeccaStevens" title="Bug reports">🐛</a> <a href="https://github.com/kentcdodds/match-sorter/commits?author=RebeccaStevens" title="Documentation">📖</a></td>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc