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 7.0.0 to 8.0.0

29

dist/match-sorter.cjs.js

@@ -219,2 +219,3 @@ 'use strict';

let matchingInOrderCharCount = 0;
let charNumber = 0;
function findMatchingCharacter(matchChar, string, index) {

@@ -230,27 +231,19 @@ for (let j = index, J = string.length; j < J; j++) {

}
let skipped = 0;
function getRanking(spread) {
const spreadPercentage = 1 / spread;
const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
const matchPercentage = (stringToRank.length - skipped) / stringToRank.length;
const ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage * matchPercentage;
const ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage;
return ranking;
}
let firstIndex = 0;
let charNumber = 0;
let nextCharNumber = 0;
for (let i = 0, I = stringToRank.length; i < I; i++) {
const firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
if (firstIndex < 0) {
return rankings.NO_MATCH;
}
charNumber = firstIndex;
for (let i = 1, I = stringToRank.length; i < I; i++) {
const matchChar = stringToRank[i];
nextCharNumber = findMatchingCharacter(matchChar, testString, charNumber);
const found = nextCharNumber > -1;
if (found) {
charNumber = nextCharNumber;
if (i === 0) {
firstIndex = charNumber;
}
} else if (skipped > 0 || stringToRank.length <= 3) {
// if search term is short, require finding all characters
charNumber = findMatchingCharacter(matchChar, testString, charNumber);
const found = charNumber > -1;
if (!found) {
return rankings.NO_MATCH;
} else {
skipped += 1;
}

@@ -257,0 +250,0 @@ }

@@ -217,2 +217,3 @@ import removeAccents from 'remove-accents';

let matchingInOrderCharCount = 0;
let charNumber = 0;
function findMatchingCharacter(matchChar, string, index) {

@@ -228,27 +229,19 @@ for (let j = index, J = string.length; j < J; j++) {

}
let skipped = 0;
function getRanking(spread) {
const spreadPercentage = 1 / spread;
const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
const matchPercentage = (stringToRank.length - skipped) / stringToRank.length;
const ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage * matchPercentage;
const ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage;
return ranking;
}
let firstIndex = 0;
let charNumber = 0;
let nextCharNumber = 0;
for (let i = 0, I = stringToRank.length; i < I; i++) {
const firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
if (firstIndex < 0) {
return rankings.NO_MATCH;
}
charNumber = firstIndex;
for (let i = 1, I = stringToRank.length; i < I; i++) {
const matchChar = stringToRank[i];
nextCharNumber = findMatchingCharacter(matchChar, testString, charNumber);
const found = nextCharNumber > -1;
if (found) {
charNumber = nextCharNumber;
if (i === 0) {
firstIndex = charNumber;
}
} else if (skipped > 0 || stringToRank.length <= 3) {
// if search term is short, require finding all characters
charNumber = findMatchingCharacter(matchChar, testString, charNumber);
const found = charNumber > -1;
if (!found) {
return rankings.NO_MATCH;
} else {
skipped += 1;
}

@@ -255,0 +248,0 @@ }

@@ -706,2 +706,3 @@ (function (global, factory) {

let matchingInOrderCharCount = 0;
let charNumber = 0;
function findMatchingCharacter(matchChar, string, index) {

@@ -717,27 +718,19 @@ for (let j = index, J = string.length; j < J; j++) {

}
let skipped = 0;
function getRanking(spread) {
const spreadPercentage = 1 / spread;
const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
const matchPercentage = (stringToRank.length - skipped) / stringToRank.length;
const ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage * matchPercentage;
const ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage;
return ranking;
}
let firstIndex = 0;
let charNumber = 0;
let nextCharNumber = 0;
for (let i = 0, I = stringToRank.length; i < I; i++) {
const firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
if (firstIndex < 0) {
return rankings.NO_MATCH;
}
charNumber = firstIndex;
for (let i = 1, I = stringToRank.length; i < I; i++) {
const matchChar = stringToRank[i];
nextCharNumber = findMatchingCharacter(matchChar, testString, charNumber);
const found = nextCharNumber > -1;
if (found) {
charNumber = nextCharNumber;
if (i === 0) {
firstIndex = charNumber;
}
} else if (skipped > 0 || stringToRank.length <= 3) {
// if search term is short, require finding all characters
charNumber = findMatchingCharacter(matchChar, testString, charNumber);
const found = charNumber > -1;
if (!found) {
return rankings.NO_MATCH;
} else {
skipped += 1;
}

@@ -744,0 +737,0 @@ }

@@ -8,3 +8,3 @@ !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(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t={exports:{}},r={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Ấ":"A","Ắ":"A","Ẳ":"A","Ẵ":"A","Ặ":"A","Æ":"AE","Ầ":"A","Ằ":"A","Ȃ":"A","Ả":"A","Ạ":"A","Ẩ":"A","Ẫ":"A","Ậ":"A","Ç":"C","Ḉ":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ế":"E","Ḗ":"E","Ề":"E","Ḕ":"E","Ḝ":"E","Ȇ":"E","Ẻ":"E","Ẽ":"E","Ẹ":"E","Ể":"E","Ễ":"E","Ệ":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ḯ":"I","Ȋ":"I","Ỉ":"I","Ị":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ố":"O","Ṍ":"O","Ṓ":"O","Ȏ":"O","Ỏ":"O","Ọ":"O","Ổ":"O","Ỗ":"O","Ộ":"O","Ờ":"O","Ở":"O","Ỡ":"O","Ớ":"O","Ợ":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ủ":"U","Ụ":"U","Ử":"U","Ữ":"U","Ự":"U","Ý":"Y","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","ấ":"a","ắ":"a","ẳ":"a","ẵ":"a","ặ":"a","æ":"ae","ầ":"a","ằ":"a","ȃ":"a","ả":"a","ạ":"a","ẩ":"a","ẫ":"a","ậ":"a","ç":"c","ḉ":"c","è":"e","é":"e","ê":"e","ë":"e","ế":"e","ḗ":"e","ề":"e","ḕ":"e","ḝ":"e","ȇ":"e","ẻ":"e","ẽ":"e","ẹ":"e","ể":"e","ễ":"e","ệ":"e","ì":"i","í":"i","î":"i","ï":"i","ḯ":"i","ȋ":"i","ỉ":"i","ị":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ố":"o","ṍ":"o","ṓ":"o","ȏ":"o","ỏ":"o","ọ":"o","ổ":"o","ỗ":"o","ộ":"o","ờ":"o","ở":"o","ỡ":"o","ớ":"o","ợ":"o","ù":"u","ú":"u","û":"u","ü":"u","ủ":"u","ụ":"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","й":"и","Й":"И","ё":"е","Ё":"Е"},o=Object.keys(r).join("|"),u=new RegExp(o,"g"),a=new RegExp(o,"");function i(e){return r[e]}var l=function(e){return e.replace(u,i)};t.exports=l,t.exports.has=function(e){return!!e.match(a)},t.exports.remove=l;var s=n(t.exports);

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

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

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