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 4.2.0 to 4.2.1

15

dist/match-sorter.cjs.js

@@ -5,7 +5,10 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _extends = require('@babel/runtime/helpers/extends');
var removeAccents = require('remove-accents');
var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
var removeAccents = _interopDefault(require('remove-accents'));
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
var removeAccents__default = /*#__PURE__*/_interopDefaultLegacy(removeAccents);
var rankings = {

@@ -50,4 +53,2 @@ CASE_SENSITIVE_EQUAL: 9,

// not performing any search/sort if value(search term) is empty
if (!value) return items;
var _options = options,

@@ -441,3 +442,3 @@ keys = _options.keys,

if (!keepDiacritics) {
value = removeAccents(value);
value = removeAccents__default['default'](value);
}

@@ -515,3 +516,3 @@

return _extends({
return _extends__default['default']({
maxRanking: Infinity,

@@ -518,0 +519,0 @@ minRanking: -Infinity

@@ -43,4 +43,2 @@ import _extends from '@babel/runtime/helpers/esm/extends';

// not performing any search/sort if value(search term) is empty
if (!value) return items;
var _options = options,

@@ -47,0 +45,0 @@ keys = _options.keys,

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.matchSorter = {}));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.matchSorter = {}));
}(this, (function (exports) { 'use strict';

@@ -485,4 +485,2 @@

// not performing any search/sort if value(search term) is empty
if (!value) return items;
var _options = options,

@@ -489,0 +487,0 @@ keys = _options.keys,

@@ -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=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("|"),u=new RegExp(t,"g"),a=new RegExp(t,""),o=function(e){return e.replace(u,(function(e){return r[e]}))},i=o,A=function(e){return!!e.match(a)},c=o;i.has=A,i.remove=c;var f={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},s={CAMEL:.8,PASCAL:.6,KEBAB:.4,SNAKE:.2,NO_CASE:0};d.rankings=f,d.caseRankings=s;var E=function(e,n){return String(e.rankedItem).localeCompare(n.rankedItem)};function d(e,n,r){if(void 0===r&&(r={}),!n)return e;var t=r,u=t.keys,a=t.threshold,o=void 0===a?f.MATCHES:a,i=t.baseSort,A=void 0===i?E:i;return e.reduce((function(e,t,a){var i=function(e,n,r,t){if(!n)return{rankedItem:e,rank:l(e,r,t),keyIndex:-1,keyThreshold:t.threshold};return function(e,n){return n.reduce((function(n,r){var t=function(e,n){"object"==typeof n&&(n=n.key);var r;r="function"==typeof n?n(e):-1!==n.indexOf(".")?n.split(".").reduce((function(e,n){return e?e[n]:null}),e):e[n];return null!=r?[].concat(r):null}(e,r);return t&&t.forEach((function(e){n.push({itemValue:e,attributes:O(r)})})),n}),[])}(e,n).reduce((function(e,n,u){var a=e.rank,o=e.rankedItem,i=e.keyIndex,A=e.keyThreshold,c=n.itemValue,s=n.attributes,E=l(c,r,t),d=o,C=s.minRanking,O=s.maxRanking,k=s.threshold;return E<C&&E>=f.MATCHES?E=C:E>O&&(E=O),E>a&&(a=E,i=u,A=k,d=c),{rankedItem:d,rank:a,keyIndex:i,keyThreshold:A}}),{rank:f.NO_MATCH,keyIndex:-1,keyThreshold:t.threshold})}(t,u,n,r),A=i.rankedItem,c=i.rank,s=i.keyIndex,E=i.keyThreshold;c>=(void 0===E?o:E)&&e.push({rankedItem:A,item:t,rank:c,index:a,keyIndex:s});return e}),[]).sort((function(e,n){return function(e,n,r){var t=e.rank,u=e.keyIndex,a=n.rank,o=n.keyIndex;return t===a?u===o?r(e,n):u<o?-1:1:t>a?-1:1}(e,n,A)})).map((function(e){return e.item}))}function l(e,n,r){if(e=C(e,r),(n=C(n,r)).length>e.length)return f.NO_MATCH;if(e===n)return f.CASE_SENSITIVE_EQUAL;var t,u,a=function(e){var n=e.toLowerCase()!==e,r=e.indexOf("-")>=0,t=e.indexOf("_")>=0;if(!n&&!t&&r)return s.KEBAB;if(!n&&t&&!r)return s.SNAKE;if(n&&!r&&!t){return e[0].toUpperCase()===e[0]?s.PASCAL:s.CAMEL}return s.NO_CASE}(e),o=function(e,n,r){var t=e.toLowerCase().indexOf(n.toLowerCase());switch(r){case s.SNAKE:return"_"===e[t-1];case s.KEBAB:return"-"===e[t-1];case s.PASCAL:case s.CAMEL:return-1!==t&&e[t]===e[t].toUpperCase();default:return!1}}(e,n,a),i=function(e,n,r){var t=null;switch(r){case s.SNAKE:t="_";break;case s.KEBAB:t="-";break;case s.PASCAL:case s.CAMEL:t=/(?=[A-Z])/;break;default:t=null}var u=e.split(t);return n.toLowerCase().split("").reduce((function(e,n,r){var t=u[r];return e&&t&&t[0].toLowerCase()===n}),!0)}(e,n,a);return(e=e.toLowerCase())===(n=n.toLowerCase())?f.EQUAL+a:0===e.indexOf(n)?f.STARTS_WITH+a:-1!==e.indexOf(" "+n)?f.WORD_STARTS_WITH+a:o?f.STRING_CASE+a:a>0&&i?f.STRING_CASE_ACRONYM+a:-1!==e.indexOf(n)?f.CONTAINS+a:1===n.length?f.NO_MATCH:-1!==(t=e,u="",t.split(" ").forEach((function(e){e.split("-").forEach((function(e){u+=e.substr(0,1)}))})),u).indexOf(n)?f.ACRONYM+a:function(e,n){var r=0,t=0;function u(e,n,t){for(var u=t;u<n.length;u++){if(n[u]===e)return r+=1,u+1}return-1}var a=u(n[0],e,0);if(a<0)return f.NO_MATCH;t=a;for(var o=1;o<n.length;o++){var i=n[o];if(!((t=u(i,e,t))>-1))return f.NO_MATCH}return function(e){var t=r/n.length;return f.MATCHES+t*(1/e)}(t-a)}(e,n)}function C(e,n){return e=""+e,n.keepDiacritics||(e=i(e)),e}function O(e){return"string"==typeof e&&(e={key:e}),n({maxRanking:1/0,minRanking:-1/0},e)}e.default=d,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,A=function(e){return!!e.match(u)},c=o;i.has=A,i.remove=c;var f={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},s={CAMEL:.8,PASCAL:.6,KEBAB:.4,SNAKE:.2,NO_CASE:0};d.rankings=f,d.caseRankings=s;var E=function(e,n){return String(e.rankedItem).localeCompare(n.rankedItem)};function d(e,n,r){void 0===r&&(r={});var t=r,a=t.keys,u=t.threshold,o=void 0===u?f.MATCHES:u,i=t.baseSort,A=void 0===i?E:i;return e.reduce((function(e,t,u){var i=function(e,n,r,t){if(!n)return{rankedItem:e,rank:l(e,r,t),keyIndex:-1,keyThreshold:t.threshold};return function(e,n){return n.reduce((function(n,r){var t=function(e,n){"object"==typeof n&&(n=n.key);var r;r="function"==typeof n?n(e):-1!==n.indexOf(".")?n.split(".").reduce((function(e,n){return e?e[n]:null}),e):e[n];return null!=r?[].concat(r):null}(e,r);return t&&t.forEach((function(e){n.push({itemValue:e,attributes:O(r)})})),n}),[])}(e,n).reduce((function(e,n,a){var u=e.rank,o=e.rankedItem,i=e.keyIndex,A=e.keyThreshold,c=n.itemValue,s=n.attributes,E=l(c,r,t),d=o,C=s.minRanking,O=s.maxRanking,k=s.threshold;return E<C&&E>=f.MATCHES?E=C:E>O&&(E=O),E>u&&(u=E,i=a,A=k,d=c),{rankedItem:d,rank:u,keyIndex:i,keyThreshold:A}}),{rank:f.NO_MATCH,keyIndex:-1,keyThreshold:t.threshold})}(t,a,n,r),A=i.rankedItem,c=i.rank,s=i.keyIndex,E=i.keyThreshold;c>=(void 0===E?o:E)&&e.push({rankedItem:A,item:t,rank:c,index:u,keyIndex:s});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,A=n.keyIndex;return u===i?o===A?r(e,n):o<A?t:a:u>i?t:a}(e,n,A)})).map((function(e){return e.item}))}function l(e,n,r){if(e=C(e,r),(n=C(n,r)).length>e.length)return f.NO_MATCH;if(e===n)return f.CASE_SENSITIVE_EQUAL;var t,a,u=function(e){var n=e.toLowerCase()!==e,r=e.indexOf("-")>=0,t=e.indexOf("_")>=0;if(!n&&!t&&r)return s.KEBAB;if(!n&&t&&!r)return s.SNAKE;if(n&&!r&&!t){return e[0].toUpperCase()===e[0]?s.PASCAL:s.CAMEL}return s.NO_CASE}(e),o=function(e,n,r){var t=e.toLowerCase().indexOf(n.toLowerCase());switch(r){case s.SNAKE:return"_"===e[t-1];case s.KEBAB:return"-"===e[t-1];case s.PASCAL:case s.CAMEL:return-1!==t&&e[t]===e[t].toUpperCase();default:return!1}}(e,n,u),i=function(e,n,r){var t=null;switch(r){case s.SNAKE:t="_";break;case s.KEBAB:t="-";break;case s.PASCAL:case s.CAMEL:t=/(?=[A-Z])/;break;default:t=null}var a=e.split(t);return n.toLowerCase().split("").reduce((function(e,n,r){var t=a[r];return e&&t&&t[0].toLowerCase()===n}),!0)}(e,n,u);return(e=e.toLowerCase())===(n=n.toLowerCase())?f.EQUAL+u:0===e.indexOf(n)?f.STARTS_WITH+u:-1!==e.indexOf(" "+n)?f.WORD_STARTS_WITH+u:o?f.STRING_CASE+u:u>0&&i?f.STRING_CASE_ACRONYM+u:-1!==e.indexOf(n)?f.CONTAINS+u:1===n.length?f.NO_MATCH:-1!==(t=e,a="",t.split(" ").forEach((function(e){e.split("-").forEach((function(e){a+=e.substr(0,1)}))})),a).indexOf(n)?f.ACRONYM+u:function(e,n){var r=0,t=0;function a(e,n,t){for(var a=t;a<n.length;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;i<n.length;i++){if(!((t=a(n[i],e,t))>-1))return f.NO_MATCH}return u(t-o)}(e,n)}function C(e,n){return e=""+e,n.keepDiacritics||(e=i(e)),e}function O(e){return"string"==typeof e&&(e={key:e}),n({maxRanking:1/0,minRanking:-1/0},e)}e.default=d,e.rankings=f,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=match-sorter.umd.min.js.map
{
"name": "match-sorter",
"version": "4.2.0",
"version": "4.2.1",
"description": "Simple, expected, and deterministic best-match sorting of an array in JavaScript",

@@ -5,0 +5,0 @@ "main": "dist/match-sorter.cjs.js",

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

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

@@ -108,3 +108,3 @@ [![PRs Welcome][prs-badge]][prs]

const list = ['hi', 'hey', 'hello', 'sup', 'yo']
matchSorter(list, 'h') // ['hi', 'hey', 'hello']
matchSorter(list, 'h') // ['hello', 'hey', 'hi']
matchSorter(list, 'y') // ['yo', 'hey']

@@ -347,2 +347,41 @@ matchSorter(list, 'z') // []

## Recipes
### Match many words across multiple fields (table filtering)
By default, `match-sorter` will return matches from objects where one of the properties
matches _the entire_ search term. For multi-column data sets it can be beneficial to split
words in search string and match each word separately. This can be done by chaining
`match-sorter` calls.
The benefit of this is that a filter string of "two words" will match both "two" and "words", but
will return rows where the two words are found in _different_ columns as well as when both words
match in the same column. For single-column matches it will also return matches out of order
(column = "wordstwo" will match just as well as column="twowords", the latter getting a higher score).
```javascript
function fuzzySearchMutipleWords(
rows, // array of data [{a: "a", b: "b"}, {a: "c", b: "d"}]
keys, // keys to search ["a", "b"]
filterValue: string, // potentially multi-word search string "two words"
) {
if (!filterValue || !filterValue.length) {
return rows
}
const terms = filterValue.split(' ')
if (!terms) {
return rows
}
// reduceRight will mean sorting is done by score for the _first_ entered word.
return terms.reduceRight(
(results, term) => matchSorter(results, term, {keys}),
rows,
)
}
```
[Multi-column code sandbox](https://codesandbox.io/s/match-sorter-example-forked-1ko35)
## Inspiration

@@ -408,2 +447,3 @@

<td align="center"><a href="https://tannerlinsley.com"><img src="https://avatars0.githubusercontent.com/u/5580297?v=4" 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://github.com/SweVictor"><img src="https://avatars1.githubusercontent.com/u/449347?v=4" 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>
</tr>

@@ -414,3 +454,2 @@ </table>

<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

@@ -417,0 +456,0 @@

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