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.0.2 to 6.1.0

105

dist/match-sorter.cjs.js

@@ -230,3 +230,3 @@ 'use strict';

function findMatchingCharacter(matchChar, string, index) {
for (var j = index; j < string.length; j++) {
for (var j = index, J = string.length; j < J; j++) {
var stringChar = string[j];

@@ -257,3 +257,3 @@

for (var i = 1; i < stringToRank.length; i++) {
for (var i = 1, I = stringToRank.length; i < I; i++) {
var matchChar = stringToRank[i];

@@ -334,26 +334,71 @@ charNumber = findMatchingCharacter(matchChar, testString, charNumber);

if (typeof key === 'function') {
value = key(item); // eslint-disable-next-line no-negated-condition
value = key(item);
} else if (item == null) {
value = null;
} else if (Object.hasOwnProperty.call(item, key)) {
value = item[key];
} else if (key.includes('.')) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return getNestedValues(key, item);
} else {
value = getNestedValue(key, item);
value = null;
} // because `value` can also be undefined
if (value == null) {
return [];
}
// concat because `value` can be a string or an array
// eslint-disable-next-line
return value != null ? [].concat(value) : null;
if (Array.isArray(value)) {
return value;
}
return [String(value)];
}
/**
* Given key: "foo.bar.baz"
* And obj: {foo: {bar: {baz: 'buzz'}}}
* Given path: "foo.bar.baz"
* And item: {foo: {bar: {baz: 'buzz'}}}
* -> 'buzz'
* @param key a dot-separated set of keys
* @param obj the object to get the value from
* @param path a dot-separated set of keys
* @param item the item to get the value from
*/
function getNestedValue(key, obj) {
// @ts-expect-error really have no idea how to type this properly...
return key.split('.').reduce(function (itemObj, nestedKey) {
// @ts-expect-error lost on this one as well...
return itemObj ? itemObj[nestedKey] : null;
}, obj);
function getNestedValues(path, item) {
var keys = path.split('.');
var values = [item];
for (var i = 0, I = keys.length; i < I; i++) {
var nestedKey = keys[i];
var nestedValues = [];
for (var j = 0, J = values.length; j < J; j++) {
var nestedItem = values[j];
if (nestedItem == null) continue;
if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
var nestedValue = nestedItem[nestedKey];
if (nestedValue != null) {
nestedValues.push(nestedValue);
}
} else if (nestedKey === '*') {
// ensure that values is an array
nestedValues = nestedValues.concat(nestedItem);
}
}
values = nestedValues;
}
if (Array.isArray(values[0])) {
// keep allowing the implicit wildcard for an array of strings at the end of
// the path; don't use `.flat()` because that's not available in node.js v10
var result = [];
return result.concat.apply(result, values);
} // Based on our logic it should be an array of strings by now...
// assuming the user's path terminated in strings
return values;
}

@@ -369,16 +414,18 @@ /**

function getAllValuesToRank(item, keys) {
return keys.reduce(function (allVals, key) {
var values = getItemValues(item, key);
var allValues = [];
if (values) {
values.forEach(function (itemValue) {
allVals.push({
itemValue: itemValue,
attributes: getKeyAttributes(key)
});
for (var j = 0, J = keys.length; j < J; j++) {
var key = keys[j];
var attributes = getKeyAttributes(key);
var itemValues = getItemValues(item, key);
for (var i = 0, I = itemValues.length; i < I; i++) {
allValues.push({
itemValue: itemValues[i],
attributes: attributes
});
}
}
return allVals;
}, []);
return allValues;
}

@@ -403,2 +450,6 @@

}
/*
eslint
no-continue: "off",
*/

@@ -405,0 +456,0 @@ exports.defaultBaseSortFn = defaultBaseSortFn;

@@ -221,3 +221,3 @@ import _extends from '@babel/runtime/helpers/esm/extends';

function findMatchingCharacter(matchChar, string, index) {
for (var j = index; j < string.length; j++) {
for (var j = index, J = string.length; j < J; j++) {
var stringChar = string[j];

@@ -248,3 +248,3 @@

for (var i = 1; i < stringToRank.length; i++) {
for (var i = 1, I = stringToRank.length; i < I; i++) {
var matchChar = stringToRank[i];

@@ -325,26 +325,71 @@ charNumber = findMatchingCharacter(matchChar, testString, charNumber);

if (typeof key === 'function') {
value = key(item); // eslint-disable-next-line no-negated-condition
value = key(item);
} else if (item == null) {
value = null;
} else if (Object.hasOwnProperty.call(item, key)) {
value = item[key];
} else if (key.includes('.')) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return getNestedValues(key, item);
} else {
value = getNestedValue(key, item);
value = null;
} // because `value` can also be undefined
if (value == null) {
return [];
}
// concat because `value` can be a string or an array
// eslint-disable-next-line
return value != null ? [].concat(value) : null;
if (Array.isArray(value)) {
return value;
}
return [String(value)];
}
/**
* Given key: "foo.bar.baz"
* And obj: {foo: {bar: {baz: 'buzz'}}}
* Given path: "foo.bar.baz"
* And item: {foo: {bar: {baz: 'buzz'}}}
* -> 'buzz'
* @param key a dot-separated set of keys
* @param obj the object to get the value from
* @param path a dot-separated set of keys
* @param item the item to get the value from
*/
function getNestedValue(key, obj) {
// @ts-expect-error really have no idea how to type this properly...
return key.split('.').reduce(function (itemObj, nestedKey) {
// @ts-expect-error lost on this one as well...
return itemObj ? itemObj[nestedKey] : null;
}, obj);
function getNestedValues(path, item) {
var keys = path.split('.');
var values = [item];
for (var i = 0, I = keys.length; i < I; i++) {
var nestedKey = keys[i];
var nestedValues = [];
for (var j = 0, J = values.length; j < J; j++) {
var nestedItem = values[j];
if (nestedItem == null) continue;
if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
var nestedValue = nestedItem[nestedKey];
if (nestedValue != null) {
nestedValues.push(nestedValue);
}
} else if (nestedKey === '*') {
// ensure that values is an array
nestedValues = nestedValues.concat(nestedItem);
}
}
values = nestedValues;
}
if (Array.isArray(values[0])) {
// keep allowing the implicit wildcard for an array of strings at the end of
// the path; don't use `.flat()` because that's not available in node.js v10
var result = [];
return result.concat.apply(result, values);
} // Based on our logic it should be an array of strings by now...
// assuming the user's path terminated in strings
return values;
}

@@ -360,16 +405,18 @@ /**

function getAllValuesToRank(item, keys) {
return keys.reduce(function (allVals, key) {
var values = getItemValues(item, key);
var allValues = [];
if (values) {
values.forEach(function (itemValue) {
allVals.push({
itemValue: itemValue,
attributes: getKeyAttributes(key)
});
for (var j = 0, J = keys.length; j < J; j++) {
var key = keys[j];
var attributes = getKeyAttributes(key);
var itemValues = getItemValues(item, key);
for (var i = 0, I = itemValues.length; i < I; i++) {
allValues.push({
itemValue: itemValues[i],
attributes: attributes
});
}
}
return allVals;
}, []);
return allValues;
}

@@ -394,3 +441,7 @@

}
/*
eslint
no-continue: "off",
*/
export { defaultBaseSortFn, matchSorter, rankings };

@@ -663,3 +663,3 @@ (function (global, factory) {

function findMatchingCharacter(matchChar, string, index) {
for (var j = index; j < string.length; j++) {
for (var j = index, J = string.length; j < J; j++) {
var stringChar = string[j];

@@ -690,3 +690,3 @@

for (var i = 1; i < stringToRank.length; i++) {
for (var i = 1, I = stringToRank.length; i < I; i++) {
var matchChar = stringToRank[i];

@@ -767,26 +767,71 @@ charNumber = findMatchingCharacter(matchChar, testString, charNumber);

if (typeof key === 'function') {
value = key(item); // eslint-disable-next-line no-negated-condition
value = key(item);
} else if (item == null) {
value = null;
} else if (Object.hasOwnProperty.call(item, key)) {
value = item[key];
} else if (key.includes('.')) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return getNestedValues(key, item);
} else {
value = getNestedValue(key, item);
value = null;
} // because `value` can also be undefined
if (value == null) {
return [];
}
// concat because `value` can be a string or an array
// eslint-disable-next-line
return value != null ? [].concat(value) : null;
if (Array.isArray(value)) {
return value;
}
return [String(value)];
}
/**
* Given key: "foo.bar.baz"
* And obj: {foo: {bar: {baz: 'buzz'}}}
* Given path: "foo.bar.baz"
* And item: {foo: {bar: {baz: 'buzz'}}}
* -> 'buzz'
* @param key a dot-separated set of keys
* @param obj the object to get the value from
* @param path a dot-separated set of keys
* @param item the item to get the value from
*/
function getNestedValue(key, obj) {
// @ts-expect-error really have no idea how to type this properly...
return key.split('.').reduce(function (itemObj, nestedKey) {
// @ts-expect-error lost on this one as well...
return itemObj ? itemObj[nestedKey] : null;
}, obj);
function getNestedValues(path, item) {
var keys = path.split('.');
var values = [item];
for (var i = 0, I = keys.length; i < I; i++) {
var nestedKey = keys[i];
var nestedValues = [];
for (var j = 0, J = values.length; j < J; j++) {
var nestedItem = values[j];
if (nestedItem == null) continue;
if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
var nestedValue = nestedItem[nestedKey];
if (nestedValue != null) {
nestedValues.push(nestedValue);
}
} else if (nestedKey === '*') {
// ensure that values is an array
nestedValues = nestedValues.concat(nestedItem);
}
}
values = nestedValues;
}
if (Array.isArray(values[0])) {
// keep allowing the implicit wildcard for an array of strings at the end of
// the path; don't use `.flat()` because that's not available in node.js v10
var result = [];
return result.concat.apply(result, values);
} // Based on our logic it should be an array of strings by now...
// assuming the user's path terminated in strings
return values;
}

@@ -802,16 +847,18 @@ /**

function getAllValuesToRank(item, keys) {
return keys.reduce(function (allVals, key) {
var values = getItemValues(item, key);
var allValues = [];
if (values) {
values.forEach(function (itemValue) {
allVals.push({
itemValue: itemValue,
attributes: getKeyAttributes(key)
});
for (var j = 0, J = keys.length; j < J; j++) {
var key = keys[j];
var attributes = getKeyAttributes(key);
var itemValues = getItemValues(item, key);
for (var i = 0, I = itemValues.length; i < I; i++) {
allValues.push({
itemValue: itemValues[i],
attributes: attributes
});
}
}
return allVals;
}, []);
return allValues;
}

@@ -836,2 +883,6 @@

}
/*
eslint
no-continue: "off",
*/

@@ -838,0 +889,0 @@ exports.defaultBaseSortFn = defaultBaseSortFn;

@@ -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("|"),u=new RegExp(t,"g"),o=new RegExp(t,""),a=function(e){return e.replace(u,(function(e){return r[e]}))},i=a,c=function(e){return!!e.match(o)},f=a;i.has=c,i.remove=f;var l={CASE_SENSITIVE_EQUAL:7,EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0};A.rankings=l;var s=function(e,n){return String(e.rankedValue).localeCompare(String(n.rankedValue))};function A(e,r,t){void 0===t&&(t={});var u=t,o=u.keys,a=u.threshold,i=void 0===a?l.MATCHES:a,c=u.baseSort,f=void 0===c?s:c;return e.reduce((function(e,u,a){var c=function(e,n,r,t){if(!n){return{rankedValue:e,rank:d(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):function(e,n){return e.split(".").reduce((function(e,n){return e?e[n]:null}),n)}(n,e);return null!=r?[].concat(r):null}(e,r);return t&&t.forEach((function(e){n.push({itemValue:e,attributes:T(r)})})),n}),[])}(e,n).reduce((function(e,n,u){var o=e.rank,a=e.rankedValue,i=e.keyIndex,c=e.keyThreshold,f=n.itemValue,s=n.attributes,A=d(f,r,t),h=a,E=s.minRanking,T=s.maxRanking,k=s.threshold;return A<E&&A>=l.MATCHES?A=E:A>T&&(A=T),A>o&&(o=A,i=u,c=k,h=f),{rankedValue:h,rank:o,keyIndex:i,keyThreshold:c}}),{rankedValue:e,rank:l.NO_MATCH,keyIndex:-1,keyThreshold:t.threshold})}(u,o,r,t),f=c.rank,s=c.keyThreshold;f>=(void 0===s?i:s)&&e.push(n({},c,{item:u,index:a}));return e}),[]).sort((function(e,n){return function(e,n,r){var t=-1,u=1,o=e.rank,a=e.keyIndex,i=n.rank,c=n.keyIndex;return o===i?a===c?r(e,n):a<c?t:u:o>i?t:u}(e,n,f)})).map((function(e){return e.item}))}function d(e,n,r){return e=h(e,r),(n=h(n,r)).length>e.length?l.NO_MATCH:e===n?l.CASE_SENSITIVE_EQUAL:(e=e.toLowerCase())===(n=n.toLowerCase())?l.EQUAL:e.startsWith(n)?l.STARTS_WITH:e.includes(" "+n)?l.WORD_STARTS_WITH:e.includes(n)?l.CONTAINS:1===n.length?l.NO_MATCH:(t=e,u="",t.split(" ").forEach((function(e){e.split("-").forEach((function(e){u+=e.substr(0,1)}))})),u).includes(n)?l.ACRONYM: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}function o(e){var t=r/n.length;return l.MATCHES+t*(1/e)}var a=u(n[0],e,0);if(a<0)return l.NO_MATCH;t=a;for(var i=1;i<n.length;i++){if(!((t=u(n[i],e,t))>-1))return l.NO_MATCH}return o(t-a)}(e,n);var t,u}function h(e,n){return e=""+e,n.keepDiacritics||(e=i(e)),e}var E={maxRanking:1/0,minRanking:-1/0};function T(e){return"string"==typeof e?E:n({},E,e)}e.defaultBaseSortFn=s,e.matchSorter=A,e.rankings=l,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;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})}));
//# sourceMappingURL=match-sorter.umd.min.js.map
{
"name": "match-sorter",
"version": "6.0.2",
"version": "6.1.0",
"description": "Simple, expected, and deterministic best-match sorting of an array in JavaScript",

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

@@ -161,5 +161,21 @@ <div align="center">

// [{name: {first: 'Janice'}}, {name: {first: 'Jen'}}]
// matchSorter(nestedObjList, 'j', {keys: ['name[0].first']}) does not work
```
This even works with arrays of multiple nested objects: just specify the key
using dot-notation with the `*` wildcard instead of a numeric index.
```javascript
const nestedObjList = [
{aliases: [{name: {first: 'Janice'}},{name: {first: 'Jen'}}]},
{aliases: [{name: {first: 'Fred'}},{name: {first: 'Frederic'}}]},
{aliases: [{name: {first: 'George'}},{name: {first: 'Georgie'}}]},
]
matchSorter(nestedObjList, 'jen', {keys: ['aliases.*.name.first']})
// [{aliases: [{name: {first: 'Janice'}},{name: {first: 'Jen'}}]}]
matchSorter(nestedObjList, 'jen', {keys: ['aliases.0.name.first']})
// []
```
**Property Callbacks**: Alternatively, you may also pass in a callback function

@@ -457,2 +473,3 @@ that resolves the value of the key(s) you wish to match on. This is especially

<td align="center"><a href="https://github.com/PhilGarb"><img src="https://avatars3.githubusercontent.com/u/38015558?v=4" width="100px;" alt=""/><br /><sub><b>Philipp Garbowsky</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/commits?author=PhilGarb" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/mart-jansink"><img src="https://avatars3.githubusercontent.com/u/4381258?v=4" width="100px;" alt=""/><br /><sub><b>Mart</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/commits?author=mart-jansink" title="Code">💻</a> <a href="https://github.com/kentcdodds/match-sorter/commits?author=mart-jansink" title="Tests">⚠️</a> <a href="https://github.com/kentcdodds/match-sorter/commits?author=mart-jansink" title="Documentation">📖</a></td>
</tr>

@@ -459,0 +476,0 @@ </table>

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