match-sorter
Advanced tools
Comparing version 6.3.1 to 6.3.2
@@ -1,2 +0,2 @@ | ||
declare type KeyAttributes = { | ||
type KeyAttributes = { | ||
threshold?: Ranking; | ||
@@ -33,3 +33,3 @@ maxRanking: Ranking; | ||
} | ||
declare type KeyOption<ItemType> = KeyAttributesOptions<ItemType> | ValueGetterKey<ItemType> | string; | ||
type KeyOption<ItemType> = KeyAttributesOptions<ItemType> | ValueGetterKey<ItemType> | string; | ||
interface MatchSorterOptions<ItemType = unknown> { | ||
@@ -52,3 +52,3 @@ keys?: ReadonlyArray<KeyOption<ItemType>>; | ||
}; | ||
declare type Ranking = typeof rankings[keyof typeof rankings]; | ||
type Ranking = typeof rankings[keyof typeof rankings]; | ||
declare const defaultBaseSortFn: BaseSorter<unknown>; | ||
@@ -55,0 +55,0 @@ /** |
@@ -24,6 +24,6 @@ 'use strict'; | ||
matchSorter.rankings = rankings; | ||
var defaultBaseSortFn = function defaultBaseSortFn(a, b) { | ||
return String(a.rankedValue).localeCompare(String(b.rankedValue)); | ||
}; | ||
/** | ||
@@ -36,4 +36,2 @@ * Takes an array of items and a value and returns a new array with the items that match the given value | ||
*/ | ||
function matchSorter(items, value, options) { | ||
@@ -43,15 +41,14 @@ if (options === void 0) { | ||
} | ||
var _options = options, | ||
keys = _options.keys, | ||
_options$threshold = _options.threshold, | ||
threshold = _options$threshold === void 0 ? rankings.MATCHES : _options$threshold, | ||
_options$baseSort = _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; | ||
keys = _options.keys, | ||
_options$threshold = _options.threshold, | ||
threshold = _options$threshold === void 0 ? rankings.MATCHES : _options$threshold, | ||
_options$baseSort = _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, []); | ||
@@ -62,11 +59,9 @@ return sorter(matchedItems).map(function (_ref) { | ||
}); | ||
function reduceItemsToRanked(matches, item, index) { | ||
var rankingInfo = getHighestRanking(item, keys, value, options); | ||
var rank = rankingInfo.rank, | ||
_rankingInfo$keyThres = rankingInfo.keyThreshold, | ||
keyThreshold = _rankingInfo$keyThres === void 0 ? threshold : _rankingInfo$keyThres; | ||
_rankingInfo$keyThres = rankingInfo.keyThreshold, | ||
keyThreshold = _rankingInfo$keyThres === void 0 ? threshold : _rankingInfo$keyThres; | ||
if (rank >= keyThreshold) { | ||
matches.push(_extends__default['default']({}, rankingInfo, { | ||
matches.push(_extends__default["default"]({}, rankingInfo, { | ||
item: item, | ||
@@ -76,6 +71,6 @@ index: index | ||
} | ||
return matches; | ||
} | ||
} | ||
/** | ||
@@ -89,4 +84,2 @@ * Gets the highest ranking for value for the given item based on its values for the given keys | ||
*/ | ||
function getHighestRanking(item, keys, value, options) { | ||
@@ -104,17 +97,15 @@ if (!keys) { | ||
} | ||
var valuesToRank = getAllValuesToRank(item, keys); | ||
return valuesToRank.reduce(function (_ref2, _ref3, i) { | ||
var rank = _ref2.rank, | ||
rankedValue = _ref2.rankedValue, | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
rankedValue = _ref2.rankedValue, | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
var itemValue = _ref3.itemValue, | ||
attributes = _ref3.attributes; | ||
attributes = _ref3.attributes; | ||
var newRank = getMatchRanking(itemValue, value, options); | ||
var newRankedValue = rankedValue; | ||
var minRanking = attributes.minRanking, | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
if (newRank < minRanking && newRank >= rankings.MATCHES) { | ||
@@ -125,3 +116,2 @@ newRank = minRanking; | ||
} | ||
if (newRank > rank) { | ||
@@ -133,3 +123,2 @@ rank = newRank; | ||
} | ||
return { | ||
@@ -148,2 +137,3 @@ rankedValue: newRankedValue, | ||
} | ||
/** | ||
@@ -156,36 +146,36 @@ * Gives a rankings score based on how well the two strings match. | ||
*/ | ||
function getMatchRanking(testString, stringToRank, options) { | ||
testString = prepareValueForComparison(testString, options); | ||
stringToRank = prepareValueForComparison(stringToRank, options); // too long | ||
stringToRank = prepareValueForComparison(stringToRank, options); | ||
// too long | ||
if (stringToRank.length > testString.length) { | ||
return rankings.NO_MATCH; | ||
} // case sensitive equals | ||
} | ||
// case sensitive equals | ||
if (testString === stringToRank) { | ||
return rankings.CASE_SENSITIVE_EQUAL; | ||
} // Lower casing before further comparison | ||
} | ||
// Lower casing before further comparison | ||
testString = testString.toLowerCase(); | ||
stringToRank = stringToRank.toLowerCase(); // case insensitive equals | ||
stringToRank = stringToRank.toLowerCase(); | ||
// case insensitive equals | ||
if (testString === stringToRank) { | ||
return rankings.EQUAL; | ||
} // starts with | ||
} | ||
// starts with | ||
if (testString.startsWith(stringToRank)) { | ||
return rankings.STARTS_WITH; | ||
} // word starts with | ||
} | ||
// word starts with | ||
if (testString.includes(" " + stringToRank)) { | ||
return rankings.WORD_STARTS_WITH; | ||
} // contains | ||
} | ||
// contains | ||
if (testString.includes(stringToRank)) { | ||
@@ -198,13 +188,14 @@ return rankings.CONTAINS; | ||
return rankings.NO_MATCH; | ||
} // acronym | ||
} | ||
// acronym | ||
if (getAcronym(testString).includes(stringToRank)) { | ||
return rankings.ACRONYM; | ||
} // will return a number between rankings.MATCHES and | ||
} | ||
// will return a number between rankings.MATCHES and | ||
// rankings.MATCHES + 1 depending on how close of a match it is. | ||
return getClosenessRanking(testString, stringToRank); | ||
} | ||
/** | ||
@@ -216,4 +207,2 @@ * Generates an acronym for a string. | ||
*/ | ||
function getAcronym(string) { | ||
@@ -230,2 +219,3 @@ var acronym = ''; | ||
} | ||
/** | ||
@@ -241,12 +231,8 @@ * Returns a score based on how spread apart the | ||
*/ | ||
function getClosenessRanking(testString, stringToRank) { | ||
var matchingInOrderCharCount = 0; | ||
var charNumber = 0; | ||
function findMatchingCharacter(matchChar, string, index) { | ||
for (var j = index, J = string.length; j < J; j++) { | ||
var stringChar = string[j]; | ||
if (stringChar === matchChar) { | ||
@@ -257,6 +243,4 @@ matchingInOrderCharCount += 1; | ||
} | ||
return -1; | ||
} | ||
function getRanking(spread) { | ||
@@ -268,11 +252,7 @@ var spreadPercentage = 1 / spread; | ||
} | ||
var firstIndex = findMatchingCharacter(stringToRank[0], testString, 0); | ||
if (firstIndex < 0) { | ||
return rankings.NO_MATCH; | ||
} | ||
charNumber = firstIndex; | ||
for (var i = 1, I = stringToRank.length; i < I; i++) { | ||
@@ -282,3 +262,2 @@ var matchChar = stringToRank[i]; | ||
var found = charNumber > -1; | ||
if (!found) { | ||
@@ -288,6 +267,6 @@ return rankings.NO_MATCH; | ||
} | ||
var spread = charNumber - firstIndex; | ||
return getRanking(spread); | ||
} | ||
/** | ||
@@ -299,4 +278,2 @@ * Sorts items that have a rank, index, and keyIndex | ||
*/ | ||
function sortRankedValues(a, b, baseSort) { | ||
@@ -306,7 +283,6 @@ var aFirst = -1; | ||
var aRank = a.rank, | ||
aKeyIndex = a.keyIndex; | ||
aKeyIndex = a.keyIndex; | ||
var bRank = b.rank, | ||
bKeyIndex = b.keyIndex; | ||
bKeyIndex = b.keyIndex; | ||
var same = aRank === bRank; | ||
if (same) { | ||
@@ -323,2 +299,3 @@ if (aKeyIndex === bKeyIndex) { | ||
} | ||
/** | ||
@@ -330,4 +307,2 @@ * Prepares value for comparison by stringifying it, removing diacritics (if specified) | ||
*/ | ||
function prepareValueForComparison(value, _ref4) { | ||
@@ -338,9 +313,8 @@ var keepDiacritics = _ref4.keepDiacritics; | ||
value = "" + value; // toString | ||
if (!keepDiacritics) { | ||
value = removeAccents__default['default'](value); | ||
value = removeAccents__default["default"](value); | ||
} | ||
return value; | ||
} | ||
/** | ||
@@ -352,4 +326,2 @@ * Gets value for key in item at arbitrarily nested keypath | ||
*/ | ||
function getItemValues(item, key) { | ||
@@ -359,5 +331,3 @@ if (typeof key === 'object') { | ||
} | ||
var value; | ||
if (typeof key === 'function') { | ||
@@ -374,15 +344,14 @@ value = key(item); | ||
value = null; | ||
} // because `value` can also be undefined | ||
} | ||
// because `value` can also be undefined | ||
if (value == null) { | ||
return []; | ||
} | ||
if (Array.isArray(value)) { | ||
return value; | ||
} | ||
return [String(value)]; | ||
} | ||
/** | ||
@@ -395,19 +364,13 @@ * Given path: "foo.bar.baz" | ||
*/ | ||
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) { | ||
@@ -421,6 +384,4 @@ nestedValues.push(nestedValue); | ||
} | ||
values = nestedValues; | ||
} | ||
if (Array.isArray(values[0])) { | ||
@@ -431,8 +392,8 @@ // keep allowing the implicit wildcard for an array of strings at the end of | ||
return result.concat.apply(result, values); | ||
} // Based on our logic it should be an array of strings by now... | ||
} | ||
// Based on our logic it should be an array of strings by now... | ||
// assuming the user's path terminated in strings | ||
return values; | ||
} | ||
/** | ||
@@ -444,7 +405,4 @@ * Gets all the values for the given keys in the given item and returns an array of those values | ||
*/ | ||
function getAllValuesToRank(item, keys) { | ||
var allValues = []; | ||
for (var j = 0, J = keys.length; j < J; j++) { | ||
@@ -454,3 +412,2 @@ var key = keys[j]; | ||
var itemValues = getItemValues(item, key); | ||
for (var i = 0, I = itemValues.length; i < I; i++) { | ||
@@ -463,6 +420,4 @@ allValues.push({ | ||
} | ||
return allValues; | ||
} | ||
var defaultKeyAttributes = { | ||
@@ -477,3 +432,2 @@ maxRanking: Infinity, | ||
*/ | ||
function getKeyAttributes(key) { | ||
@@ -483,5 +437,5 @@ if (typeof key === 'string') { | ||
} | ||
return _extends__default["default"]({}, defaultKeyAttributes, key); | ||
} | ||
return _extends__default['default']({}, defaultKeyAttributes, key); | ||
} | ||
/* | ||
@@ -488,0 +442,0 @@ eslint |
@@ -15,6 +15,6 @@ import _extends from '@babel/runtime/helpers/esm/extends'; | ||
matchSorter.rankings = rankings; | ||
var defaultBaseSortFn = function defaultBaseSortFn(a, b) { | ||
return String(a.rankedValue).localeCompare(String(b.rankedValue)); | ||
}; | ||
/** | ||
@@ -27,4 +27,2 @@ * Takes an array of items and a value and returns a new array with the items that match the given value | ||
*/ | ||
function matchSorter(items, value, options) { | ||
@@ -34,15 +32,14 @@ if (options === void 0) { | ||
} | ||
var _options = options, | ||
keys = _options.keys, | ||
_options$threshold = _options.threshold, | ||
threshold = _options$threshold === void 0 ? rankings.MATCHES : _options$threshold, | ||
_options$baseSort = _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; | ||
keys = _options.keys, | ||
_options$threshold = _options.threshold, | ||
threshold = _options$threshold === void 0 ? rankings.MATCHES : _options$threshold, | ||
_options$baseSort = _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, []); | ||
@@ -53,9 +50,7 @@ return sorter(matchedItems).map(function (_ref) { | ||
}); | ||
function reduceItemsToRanked(matches, item, index) { | ||
var rankingInfo = getHighestRanking(item, keys, value, options); | ||
var rank = rankingInfo.rank, | ||
_rankingInfo$keyThres = rankingInfo.keyThreshold, | ||
keyThreshold = _rankingInfo$keyThres === void 0 ? threshold : _rankingInfo$keyThres; | ||
_rankingInfo$keyThres = rankingInfo.keyThreshold, | ||
keyThreshold = _rankingInfo$keyThres === void 0 ? threshold : _rankingInfo$keyThres; | ||
if (rank >= keyThreshold) { | ||
@@ -67,6 +62,6 @@ matches.push(_extends({}, rankingInfo, { | ||
} | ||
return matches; | ||
} | ||
} | ||
/** | ||
@@ -80,4 +75,2 @@ * Gets the highest ranking for value for the given item based on its values for the given keys | ||
*/ | ||
function getHighestRanking(item, keys, value, options) { | ||
@@ -95,17 +88,15 @@ if (!keys) { | ||
} | ||
var valuesToRank = getAllValuesToRank(item, keys); | ||
return valuesToRank.reduce(function (_ref2, _ref3, i) { | ||
var rank = _ref2.rank, | ||
rankedValue = _ref2.rankedValue, | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
rankedValue = _ref2.rankedValue, | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
var itemValue = _ref3.itemValue, | ||
attributes = _ref3.attributes; | ||
attributes = _ref3.attributes; | ||
var newRank = getMatchRanking(itemValue, value, options); | ||
var newRankedValue = rankedValue; | ||
var minRanking = attributes.minRanking, | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
if (newRank < minRanking && newRank >= rankings.MATCHES) { | ||
@@ -116,3 +107,2 @@ newRank = minRanking; | ||
} | ||
if (newRank > rank) { | ||
@@ -124,3 +114,2 @@ rank = newRank; | ||
} | ||
return { | ||
@@ -139,2 +128,3 @@ rankedValue: newRankedValue, | ||
} | ||
/** | ||
@@ -147,36 +137,36 @@ * Gives a rankings score based on how well the two strings match. | ||
*/ | ||
function getMatchRanking(testString, stringToRank, options) { | ||
testString = prepareValueForComparison(testString, options); | ||
stringToRank = prepareValueForComparison(stringToRank, options); // too long | ||
stringToRank = prepareValueForComparison(stringToRank, options); | ||
// too long | ||
if (stringToRank.length > testString.length) { | ||
return rankings.NO_MATCH; | ||
} // case sensitive equals | ||
} | ||
// case sensitive equals | ||
if (testString === stringToRank) { | ||
return rankings.CASE_SENSITIVE_EQUAL; | ||
} // Lower casing before further comparison | ||
} | ||
// Lower casing before further comparison | ||
testString = testString.toLowerCase(); | ||
stringToRank = stringToRank.toLowerCase(); // case insensitive equals | ||
stringToRank = stringToRank.toLowerCase(); | ||
// case insensitive equals | ||
if (testString === stringToRank) { | ||
return rankings.EQUAL; | ||
} // starts with | ||
} | ||
// starts with | ||
if (testString.startsWith(stringToRank)) { | ||
return rankings.STARTS_WITH; | ||
} // word starts with | ||
} | ||
// word starts with | ||
if (testString.includes(" " + stringToRank)) { | ||
return rankings.WORD_STARTS_WITH; | ||
} // contains | ||
} | ||
// contains | ||
if (testString.includes(stringToRank)) { | ||
@@ -189,13 +179,14 @@ return rankings.CONTAINS; | ||
return rankings.NO_MATCH; | ||
} // acronym | ||
} | ||
// acronym | ||
if (getAcronym(testString).includes(stringToRank)) { | ||
return rankings.ACRONYM; | ||
} // will return a number between rankings.MATCHES and | ||
} | ||
// will return a number between rankings.MATCHES and | ||
// rankings.MATCHES + 1 depending on how close of a match it is. | ||
return getClosenessRanking(testString, stringToRank); | ||
} | ||
/** | ||
@@ -207,4 +198,2 @@ * Generates an acronym for a string. | ||
*/ | ||
function getAcronym(string) { | ||
@@ -221,2 +210,3 @@ var acronym = ''; | ||
} | ||
/** | ||
@@ -232,12 +222,8 @@ * Returns a score based on how spread apart the | ||
*/ | ||
function getClosenessRanking(testString, stringToRank) { | ||
var matchingInOrderCharCount = 0; | ||
var charNumber = 0; | ||
function findMatchingCharacter(matchChar, string, index) { | ||
for (var j = index, J = string.length; j < J; j++) { | ||
var stringChar = string[j]; | ||
if (stringChar === matchChar) { | ||
@@ -248,6 +234,4 @@ matchingInOrderCharCount += 1; | ||
} | ||
return -1; | ||
} | ||
function getRanking(spread) { | ||
@@ -259,11 +243,7 @@ var spreadPercentage = 1 / spread; | ||
} | ||
var firstIndex = findMatchingCharacter(stringToRank[0], testString, 0); | ||
if (firstIndex < 0) { | ||
return rankings.NO_MATCH; | ||
} | ||
charNumber = firstIndex; | ||
for (var i = 1, I = stringToRank.length; i < I; i++) { | ||
@@ -273,3 +253,2 @@ var matchChar = stringToRank[i]; | ||
var found = charNumber > -1; | ||
if (!found) { | ||
@@ -279,6 +258,6 @@ return rankings.NO_MATCH; | ||
} | ||
var spread = charNumber - firstIndex; | ||
return getRanking(spread); | ||
} | ||
/** | ||
@@ -290,4 +269,2 @@ * Sorts items that have a rank, index, and keyIndex | ||
*/ | ||
function sortRankedValues(a, b, baseSort) { | ||
@@ -297,7 +274,6 @@ var aFirst = -1; | ||
var aRank = a.rank, | ||
aKeyIndex = a.keyIndex; | ||
aKeyIndex = a.keyIndex; | ||
var bRank = b.rank, | ||
bKeyIndex = b.keyIndex; | ||
bKeyIndex = b.keyIndex; | ||
var same = aRank === bRank; | ||
if (same) { | ||
@@ -314,2 +290,3 @@ if (aKeyIndex === bKeyIndex) { | ||
} | ||
/** | ||
@@ -321,4 +298,2 @@ * Prepares value for comparison by stringifying it, removing diacritics (if specified) | ||
*/ | ||
function prepareValueForComparison(value, _ref4) { | ||
@@ -329,9 +304,8 @@ var keepDiacritics = _ref4.keepDiacritics; | ||
value = "" + value; // toString | ||
if (!keepDiacritics) { | ||
value = removeAccents(value); | ||
} | ||
return value; | ||
} | ||
/** | ||
@@ -343,4 +317,2 @@ * Gets value for key in item at arbitrarily nested keypath | ||
*/ | ||
function getItemValues(item, key) { | ||
@@ -350,5 +322,3 @@ if (typeof key === 'object') { | ||
} | ||
var value; | ||
if (typeof key === 'function') { | ||
@@ -365,15 +335,14 @@ value = key(item); | ||
value = null; | ||
} // because `value` can also be undefined | ||
} | ||
// because `value` can also be undefined | ||
if (value == null) { | ||
return []; | ||
} | ||
if (Array.isArray(value)) { | ||
return value; | ||
} | ||
return [String(value)]; | ||
} | ||
/** | ||
@@ -386,19 +355,13 @@ * Given path: "foo.bar.baz" | ||
*/ | ||
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) { | ||
@@ -412,6 +375,4 @@ nestedValues.push(nestedValue); | ||
} | ||
values = nestedValues; | ||
} | ||
if (Array.isArray(values[0])) { | ||
@@ -422,8 +383,8 @@ // keep allowing the implicit wildcard for an array of strings at the end of | ||
return result.concat.apply(result, values); | ||
} // Based on our logic it should be an array of strings by now... | ||
} | ||
// Based on our logic it should be an array of strings by now... | ||
// assuming the user's path terminated in strings | ||
return values; | ||
} | ||
/** | ||
@@ -435,7 +396,4 @@ * Gets all the values for the given keys in the given item and returns an array of those values | ||
*/ | ||
function getAllValuesToRank(item, keys) { | ||
var allValues = []; | ||
for (var j = 0, J = keys.length; j < J; j++) { | ||
@@ -445,3 +403,2 @@ var key = keys[j]; | ||
var itemValues = getItemValues(item, key); | ||
for (var i = 0, I = itemValues.length; i < I; i++) { | ||
@@ -454,6 +411,4 @@ allValues.push({ | ||
} | ||
return allValues; | ||
} | ||
var defaultKeyAttributes = { | ||
@@ -468,3 +423,2 @@ maxRanking: Infinity, | ||
*/ | ||
function getKeyAttributes(key) { | ||
@@ -474,5 +428,5 @@ if (typeof key === 'string') { | ||
} | ||
return _extends({}, defaultKeyAttributes, key); | ||
} | ||
/* | ||
@@ -479,0 +433,0 @@ eslint |
@@ -5,9 +5,8 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.matchSorter = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
})(this, (function (exports) { 'use strict'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -19,6 +18,4 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
@@ -43,2 +40,7 @@ } | ||
"Ȃ": "A", | ||
"Ả": "A", | ||
"Ạ": "A", | ||
"Ẩ": "A", | ||
"Ẫ": "A", | ||
"Ậ": "A", | ||
"Ç": "C", | ||
@@ -56,2 +58,8 @@ "Ḉ": "C", | ||
"Ȇ": "E", | ||
"Ẻ": "E", | ||
"Ẽ": "E", | ||
"Ẹ": "E", | ||
"Ể": "E", | ||
"Ễ": "E", | ||
"Ệ": "E", | ||
"Ì": "I", | ||
@@ -63,2 +71,4 @@ "Í": "I", | ||
"Ȋ": "I", | ||
"Ỉ": "I", | ||
"Ị": "I", | ||
"Ð": "D", | ||
@@ -76,2 +86,12 @@ "Ñ": "N", | ||
"Ȏ": "O", | ||
"Ỏ": "O", | ||
"Ọ": "O", | ||
"Ổ": "O", | ||
"Ỗ": "O", | ||
"Ộ": "O", | ||
"Ờ": "O", | ||
"Ở": "O", | ||
"Ỡ": "O", | ||
"Ớ": "O", | ||
"Ợ": "O", | ||
"Ù": "U", | ||
@@ -81,2 +101,7 @@ "Ú": "U", | ||
"Ü": "U", | ||
"Ủ": "U", | ||
"Ụ": "U", | ||
"Ử": "U", | ||
"Ữ": "U", | ||
"Ự": "U", | ||
"Ý": "Y", | ||
@@ -98,2 +123,7 @@ "à": "a", | ||
"ȃ": "a", | ||
"ả": "a", | ||
"ạ": "a", | ||
"ẩ": "a", | ||
"ẫ": "a", | ||
"ậ": "a", | ||
"ç": "c", | ||
@@ -111,2 +141,8 @@ "ḉ": "c", | ||
"ȇ": "e", | ||
"ẻ": "e", | ||
"ẽ": "e", | ||
"ẹ": "e", | ||
"ể": "e", | ||
"ễ": "e", | ||
"ệ": "e", | ||
"ì": "i", | ||
@@ -118,2 +154,4 @@ "í": "i", | ||
"ȋ": "i", | ||
"ỉ": "i", | ||
"ị": "i", | ||
"ð": "d", | ||
@@ -131,2 +169,12 @@ "ñ": "n", | ||
"ȏ": "o", | ||
"ỏ": "o", | ||
"ọ": "o", | ||
"ổ": "o", | ||
"ỗ": "o", | ||
"ộ": "o", | ||
"ờ": "o", | ||
"ở": "o", | ||
"ỡ": "o", | ||
"ớ": "o", | ||
"ợ": "o", | ||
"ù": "u", | ||
@@ -136,2 +184,7 @@ "ú": "u", | ||
"ü": "u", | ||
"ủ": "u", | ||
"ụ": "u", | ||
"ử": "u", | ||
"ữ": "u", | ||
"ự": "u", | ||
"ý": "y", | ||
@@ -436,3 +489,7 @@ "ÿ": "y", | ||
"Z̧": "Z", | ||
"z̧": "z" | ||
"z̧": "z", | ||
"й": "и", | ||
"Й": "И", | ||
"ё": "е", | ||
"Ё": "Е" | ||
}; | ||
@@ -442,13 +499,11 @@ var chars = Object.keys(characterMap).join('|'); | ||
var firstAccent = new RegExp(chars, ''); | ||
function matcher(match) { | ||
return characterMap[match]; | ||
} | ||
var removeAccents = function removeAccents(string) { | ||
return string.replace(allAccents, function (match) { | ||
return characterMap[match]; | ||
}); | ||
return string.replace(allAccents, matcher); | ||
}; | ||
var hasAccents = function hasAccents(string) { | ||
return !!string.match(firstAccent); | ||
}; | ||
var removeAccents_1 = removeAccents; | ||
@@ -471,6 +526,6 @@ var has = hasAccents; | ||
matchSorter.rankings = rankings; | ||
var defaultBaseSortFn = function defaultBaseSortFn(a, b) { | ||
return String(a.rankedValue).localeCompare(String(b.rankedValue)); | ||
}; | ||
/** | ||
@@ -483,4 +538,2 @@ * Takes an array of items and a value and returns a new array with the items that match the given value | ||
*/ | ||
function matchSorter(items, value, options) { | ||
@@ -490,15 +543,14 @@ if (options === void 0) { | ||
} | ||
var _options = options, | ||
keys = _options.keys, | ||
_options$threshold = _options.threshold, | ||
threshold = _options$threshold === void 0 ? rankings.MATCHES : _options$threshold, | ||
_options$baseSort = _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; | ||
keys = _options.keys, | ||
_options$threshold = _options.threshold, | ||
threshold = _options$threshold === void 0 ? rankings.MATCHES : _options$threshold, | ||
_options$baseSort = _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, []); | ||
@@ -509,9 +561,7 @@ return sorter(matchedItems).map(function (_ref) { | ||
}); | ||
function reduceItemsToRanked(matches, item, index) { | ||
var rankingInfo = getHighestRanking(item, keys, value, options); | ||
var rank = rankingInfo.rank, | ||
_rankingInfo$keyThres = rankingInfo.keyThreshold, | ||
keyThreshold = _rankingInfo$keyThres === void 0 ? threshold : _rankingInfo$keyThres; | ||
_rankingInfo$keyThres = rankingInfo.keyThreshold, | ||
keyThreshold = _rankingInfo$keyThres === void 0 ? threshold : _rankingInfo$keyThres; | ||
if (rank >= keyThreshold) { | ||
@@ -523,6 +573,6 @@ matches.push(_extends({}, rankingInfo, { | ||
} | ||
return matches; | ||
} | ||
} | ||
/** | ||
@@ -536,4 +586,2 @@ * Gets the highest ranking for value for the given item based on its values for the given keys | ||
*/ | ||
function getHighestRanking(item, keys, value, options) { | ||
@@ -551,17 +599,15 @@ if (!keys) { | ||
} | ||
var valuesToRank = getAllValuesToRank(item, keys); | ||
return valuesToRank.reduce(function (_ref2, _ref3, i) { | ||
var rank = _ref2.rank, | ||
rankedValue = _ref2.rankedValue, | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
rankedValue = _ref2.rankedValue, | ||
keyIndex = _ref2.keyIndex, | ||
keyThreshold = _ref2.keyThreshold; | ||
var itemValue = _ref3.itemValue, | ||
attributes = _ref3.attributes; | ||
attributes = _ref3.attributes; | ||
var newRank = getMatchRanking(itemValue, value, options); | ||
var newRankedValue = rankedValue; | ||
var minRanking = attributes.minRanking, | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
maxRanking = attributes.maxRanking, | ||
threshold = attributes.threshold; | ||
if (newRank < minRanking && newRank >= rankings.MATCHES) { | ||
@@ -572,3 +618,2 @@ newRank = minRanking; | ||
} | ||
if (newRank > rank) { | ||
@@ -580,3 +625,2 @@ rank = newRank; | ||
} | ||
return { | ||
@@ -595,2 +639,3 @@ rankedValue: newRankedValue, | ||
} | ||
/** | ||
@@ -603,36 +648,36 @@ * Gives a rankings score based on how well the two strings match. | ||
*/ | ||
function getMatchRanking(testString, stringToRank, options) { | ||
testString = prepareValueForComparison(testString, options); | ||
stringToRank = prepareValueForComparison(stringToRank, options); // too long | ||
stringToRank = prepareValueForComparison(stringToRank, options); | ||
// too long | ||
if (stringToRank.length > testString.length) { | ||
return rankings.NO_MATCH; | ||
} // case sensitive equals | ||
} | ||
// case sensitive equals | ||
if (testString === stringToRank) { | ||
return rankings.CASE_SENSITIVE_EQUAL; | ||
} // Lower casing before further comparison | ||
} | ||
// Lower casing before further comparison | ||
testString = testString.toLowerCase(); | ||
stringToRank = stringToRank.toLowerCase(); // case insensitive equals | ||
stringToRank = stringToRank.toLowerCase(); | ||
// case insensitive equals | ||
if (testString === stringToRank) { | ||
return rankings.EQUAL; | ||
} // starts with | ||
} | ||
// starts with | ||
if (testString.startsWith(stringToRank)) { | ||
return rankings.STARTS_WITH; | ||
} // word starts with | ||
} | ||
// word starts with | ||
if (testString.includes(" " + stringToRank)) { | ||
return rankings.WORD_STARTS_WITH; | ||
} // contains | ||
} | ||
// contains | ||
if (testString.includes(stringToRank)) { | ||
@@ -645,13 +690,14 @@ return rankings.CONTAINS; | ||
return rankings.NO_MATCH; | ||
} // acronym | ||
} | ||
// acronym | ||
if (getAcronym(testString).includes(stringToRank)) { | ||
return rankings.ACRONYM; | ||
} // will return a number between rankings.MATCHES and | ||
} | ||
// will return a number between rankings.MATCHES and | ||
// rankings.MATCHES + 1 depending on how close of a match it is. | ||
return getClosenessRanking(testString, stringToRank); | ||
} | ||
/** | ||
@@ -663,4 +709,2 @@ * Generates an acronym for a string. | ||
*/ | ||
function getAcronym(string) { | ||
@@ -677,2 +721,3 @@ var acronym = ''; | ||
} | ||
/** | ||
@@ -688,12 +733,8 @@ * Returns a score based on how spread apart the | ||
*/ | ||
function getClosenessRanking(testString, stringToRank) { | ||
var matchingInOrderCharCount = 0; | ||
var charNumber = 0; | ||
function findMatchingCharacter(matchChar, string, index) { | ||
for (var j = index, J = string.length; j < J; j++) { | ||
var stringChar = string[j]; | ||
if (stringChar === matchChar) { | ||
@@ -704,6 +745,4 @@ matchingInOrderCharCount += 1; | ||
} | ||
return -1; | ||
} | ||
function getRanking(spread) { | ||
@@ -715,11 +754,7 @@ var spreadPercentage = 1 / spread; | ||
} | ||
var firstIndex = findMatchingCharacter(stringToRank[0], testString, 0); | ||
if (firstIndex < 0) { | ||
return rankings.NO_MATCH; | ||
} | ||
charNumber = firstIndex; | ||
for (var i = 1, I = stringToRank.length; i < I; i++) { | ||
@@ -729,3 +764,2 @@ var matchChar = stringToRank[i]; | ||
var found = charNumber > -1; | ||
if (!found) { | ||
@@ -735,6 +769,6 @@ return rankings.NO_MATCH; | ||
} | ||
var spread = charNumber - firstIndex; | ||
return getRanking(spread); | ||
} | ||
/** | ||
@@ -746,4 +780,2 @@ * Sorts items that have a rank, index, and keyIndex | ||
*/ | ||
function sortRankedValues(a, b, baseSort) { | ||
@@ -753,7 +785,6 @@ var aFirst = -1; | ||
var aRank = a.rank, | ||
aKeyIndex = a.keyIndex; | ||
aKeyIndex = a.keyIndex; | ||
var bRank = b.rank, | ||
bKeyIndex = b.keyIndex; | ||
bKeyIndex = b.keyIndex; | ||
var same = aRank === bRank; | ||
if (same) { | ||
@@ -770,2 +801,3 @@ if (aKeyIndex === bKeyIndex) { | ||
} | ||
/** | ||
@@ -777,4 +809,2 @@ * Prepares value for comparison by stringifying it, removing diacritics (if specified) | ||
*/ | ||
function prepareValueForComparison(value, _ref4) { | ||
@@ -785,9 +815,8 @@ var keepDiacritics = _ref4.keepDiacritics; | ||
value = "" + value; // toString | ||
if (!keepDiacritics) { | ||
value = removeAccents_1(value); | ||
} | ||
return value; | ||
} | ||
/** | ||
@@ -799,4 +828,2 @@ * Gets value for key in item at arbitrarily nested keypath | ||
*/ | ||
function getItemValues(item, key) { | ||
@@ -806,5 +833,3 @@ if (typeof key === 'object') { | ||
} | ||
var value; | ||
if (typeof key === 'function') { | ||
@@ -821,15 +846,14 @@ value = key(item); | ||
value = null; | ||
} // because `value` can also be undefined | ||
} | ||
// because `value` can also be undefined | ||
if (value == null) { | ||
return []; | ||
} | ||
if (Array.isArray(value)) { | ||
return value; | ||
} | ||
return [String(value)]; | ||
} | ||
/** | ||
@@ -842,19 +866,13 @@ * Given path: "foo.bar.baz" | ||
*/ | ||
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) { | ||
@@ -868,6 +886,4 @@ nestedValues.push(nestedValue); | ||
} | ||
values = nestedValues; | ||
} | ||
if (Array.isArray(values[0])) { | ||
@@ -878,8 +894,8 @@ // keep allowing the implicit wildcard for an array of strings at the end of | ||
return result.concat.apply(result, values); | ||
} // Based on our logic it should be an array of strings by now... | ||
} | ||
// Based on our logic it should be an array of strings by now... | ||
// assuming the user's path terminated in strings | ||
return values; | ||
} | ||
/** | ||
@@ -891,7 +907,4 @@ * Gets all the values for the given keys in the given item and returns an array of those values | ||
*/ | ||
function getAllValuesToRank(item, keys) { | ||
var allValues = []; | ||
for (var j = 0, J = keys.length; j < J; j++) { | ||
@@ -901,3 +914,2 @@ var key = keys[j]; | ||
var itemValues = getItemValues(item, key); | ||
for (var i = 0, I = itemValues.length; i < I; i++) { | ||
@@ -910,6 +922,4 @@ allValues.push({ | ||
} | ||
return allValues; | ||
} | ||
var defaultKeyAttributes = { | ||
@@ -924,3 +934,2 @@ maxRanking: Infinity, | ||
*/ | ||
function getKeyAttributes(key) { | ||
@@ -930,5 +939,5 @@ if (typeof key === 'string') { | ||
} | ||
return _extends({}, defaultKeyAttributes, key); | ||
} | ||
/* | ||
@@ -945,3 +954,3 @@ eslint | ||
}))); | ||
})); | ||
//# sourceMappingURL=match-sorter.umd.js.map |
@@ -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},n.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,d=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=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}),[]);return d(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})})); | ||
!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?Object.assign.bind():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},n.apply(this,arguments)}var 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","й":"и","Й":"И","ё":"е","Ё":"Е"},t=Object.keys(r).join("|"),a=new RegExp(t,"g"),o=new RegExp(t,"");function u(e){return r[e]}var i=function(e){return e.replace(a,u)},l=i,c=function(e){return!!e.match(o)},s=i;l.has=c,l.remove=s;var f={CASE_SENSITIVE_EQUAL:7,EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0};O.rankings=f;var A=function(e,n){return String(e.rankedValue).localeCompare(String(n.rankedValue))};function O(e,r,t){void 0===t&&(t={});var a=t,o=a.keys,u=a.threshold,i=void 0===u?f.MATCHES:u,l=a.baseSort,c=void 0===l?A:l,s=a.sorter,O=void 0===s?function(e){return e.sort((function(e,n){return function(e,n,r){var t=-1,a=1,o=e.rank,u=e.keyIndex,i=n.rank,l=n.keyIndex;return o===i?u===l?r(e,n):u<l?t:a:o>i?t:a}(e,n,c)}))}:s,d=e.reduce((function(e,a,u){var l=function(e,n,r,t){if(!n){return{rankedValue:e,rank:h(e,r,t),keyIndex:-1,keyThreshold:t.threshold}}var a=function(e,n){for(var r=[],t=0,a=n.length;t<a;t++)for(var o=n[t],u=T(o),i=E(e,o),l=0,c=i.length;l<c;l++)r.push({itemValue:i[l],attributes:u});return r}(e,n);return a.reduce((function(e,n,a){var o=e.rank,u=e.rankedValue,i=e.keyIndex,l=e.keyThreshold,c=n.itemValue,s=n.attributes,A=h(c,r,t),O=u,d=s.minRanking,E=s.maxRanking,y=s.threshold;return A<d&&A>=f.MATCHES?A=d:A>E&&(A=E),A>o&&(o=A,i=a,l=y,O=c),{rankedValue:O,rank:o,keyIndex:i,keyThreshold:l}}),{rankedValue:e,rank:f.NO_MATCH,keyIndex:-1,keyThreshold:t.threshold})}(a,o,r,t),c=l.rank,s=l.keyThreshold;return c>=(void 0===s?i:s)&&e.push(n({},l,{item:a,index:u})),e}),[]);return O(d).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,o=n.length;a<o;a++){if(n[a]===e)return r+=1,a+1}return-1}function o(e){var t=1/e,a=r/n.length;return f.MATCHES+a*t}var u=a(n[0],e,0);if(u<0)return f.NO_MATCH;t=u;for(var i=1,l=n.length;i<l;i++){if(!((t=a(n[i],e,t))>-1))return f.NO_MATCH}return o(t-u)}(e,n);var t,a}function d(e,n){return e=""+e,n.keepDiacritics||(e=l(e)),e}function E(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,o=r.length;a<o;a++){for(var u=r[a],i=[],l=0,c=t.length;l<c;l++){var s=t[l];if(null!=s)if(Object.hasOwnProperty.call(s,u)){var f=s[u];null!=f&&i.push(f)}else"*"===u&&(i=i.concat(s))}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 y={maxRanking:1/0,minRanking:-1/0};function T(e){return"string"==typeof e?y:n({},y,e)}e.defaultBaseSortFn=A,e.matchSorter=O,e.rankings=f,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=match-sorter.umd.min.js.map |
{ | ||
"name": "match-sorter", | ||
"version": "6.3.1", | ||
"version": "6.3.2", | ||
"description": "Simple, expected, and deterministic best-match sorting of an array in JavaScript", | ||
@@ -31,3 +31,3 @@ "main": "dist/match-sorter.cjs.js", | ||
"@babel/runtime": "^7.12.5", | ||
"remove-accents": "0.4.2" | ||
"remove-accents": "0.5.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
@@ -278,4 +278,2 @@ <div align="center"> | ||
- WORD_STARTS_WITH | ||
- STRING_CASE | ||
- STRING_CASE_ACRONYM | ||
- CONTAINS | ||
@@ -407,3 +405,3 @@ - ACRONYM | ||
```javascript | ||
function fuzzySearchMutipleWords( | ||
function fuzzySearchMultipleWords( | ||
rows, // array of data [{a: "a", b: "b"}, {a: "c", b: "d"}] | ||
@@ -503,2 +501,3 @@ keys, // keys to search ["a", "b"] | ||
<td align="center"><a href="https://github.com/diesieben07"><img src="https://avatars.githubusercontent.com/u/1915984?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Take Weiland</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/commits?author=diesieben07" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/AmitAber"><img src="https://avatars.githubusercontent.com/u/8988867?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Amit Abershitz</b></sub></a><br /><a href="https://github.com/kentcdodds/match-sorter/commits?author=AmitAber" title="Documentation">📖</a></td> | ||
</tr> | ||
@@ -505,0 +504,0 @@ </table> |
Sorry, the diff of this file is not supported yet
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
176594
1754
543
+ Addedremove-accents@0.5.0(transitive)
- Removedremove-accents@0.4.2(transitive)
Updatedremove-accents@0.5.0