@koine/utils 2.0.0-beta.80 → 2.0.0-beta.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Defer.cjs.js +20 -10
- package/Defer.esm.js +20 -10
- package/Emitter.cjs.js +18 -19
- package/Emitter.d.ts +1 -1
- package/Emitter.esm.js +18 -19
- package/accentsSets.cjs.d.ts +2 -0
- package/accentsSets.cjs.default.js +1 -0
- package/accentsSets.cjs.js +20 -0
- package/accentsSets.cjs.mjs +2 -0
- package/accentsSets.esm.js +15 -0
- package/addOrReplaceAtIdx.cjs.js +7 -14
- package/addOrReplaceAtIdx.esm.js +7 -14
- package/areEqual.cjs.js +28 -43
- package/areEqual.esm.js +28 -43
- package/arrayFilterFalsy.cjs.js +6 -1
- package/arrayFilterFalsy.d.ts +1 -1
- package/arrayFilterFalsy.esm.js +6 -1
- package/arrayFindLastIndex.cjs.js +13 -8
- package/arrayFindLastIndex.d.ts +1 -1
- package/arrayFindLastIndex.esm.js +13 -8
- package/arrayOfAll.cjs.js +16 -1
- package/arrayOfAll.esm.js +16 -1
- package/arraySum.cjs.js +6 -1
- package/arraySum.esm.js +6 -1
- package/arrayToLookup.cjs.js +5 -4
- package/arrayToLookup.esm.js +5 -4
- package/arrayUniqueByProperties.cjs.js +8 -1
- package/arrayUniqueByProperties.esm.js +8 -1
- package/buildUrlQueryString.cjs.js +10 -17
- package/buildUrlQueryString.esm.js +10 -17
- package/capitalize.cjs.js +7 -2
- package/capitalize.d.ts +1 -1
- package/capitalize.esm.js +7 -2
- package/changeCaseCamel.cjs.js +7 -17
- package/changeCaseCamel.esm.js +7 -17
- package/changeCaseCapital.cjs.js +7 -10
- package/changeCaseCapital.esm.js +7 -10
- package/changeCaseConstant.cjs.js +7 -6
- package/changeCaseConstant.esm.js +7 -6
- package/changeCaseDot.cjs.js +7 -1
- package/changeCaseDot.esm.js +7 -1
- package/changeCaseHelpers.cjs.js +32 -71
- package/changeCaseHelpers.esm.js +32 -71
- package/changeCaseKebab.cjs.js +7 -1
- package/changeCaseKebab.esm.js +7 -1
- package/changeCaseNone.cjs.js +7 -6
- package/changeCaseNone.esm.js +7 -6
- package/changeCasePascal.cjs.js +7 -9
- package/changeCasePascal.esm.js +7 -9
- package/changeCasePascalSnake.cjs.js +7 -1
- package/changeCasePascalSnake.esm.js +7 -1
- package/changeCasePath.cjs.js +7 -1
- package/changeCasePath.esm.js +7 -1
- package/changeCaseSentence.cjs.js +7 -15
- package/changeCaseSentence.esm.js +8 -16
- package/changeCaseSnake.cjs.js +7 -1
- package/changeCaseSnake.esm.js +7 -1
- package/changeCaseTrain.cjs.js +7 -1
- package/changeCaseTrain.esm.js +7 -1
- package/chunkByChunks.cjs.js +5 -31
- package/chunkByChunks.esm.js +5 -31
- package/chunkBySize.cjs.js +4 -7
- package/chunkBySize.esm.js +4 -7
- package/clamp.cjs.js +6 -1
- package/clamp.esm.js +6 -1
- package/clsx.cjs.js +8 -39
- package/clsx.esm.js +8 -39
- package/convertRange.cjs.js +14 -1
- package/convertRange.esm.js +14 -1
- package/cookie.cjs.js +44 -1
- package/cookie.esm.js +44 -1
- package/createPalette.cjs.js +17 -11
- package/createPalette.esm.js +17 -11
- package/debounce.cjs.js +7 -17
- package/debounce.esm.js +7 -17
- package/debouncePromise.cjs.js +16 -51
- package/debouncePromise.esm.js +16 -51
- package/debounceRaf.cjs.js +10 -12
- package/debounceRaf.esm.js +10 -12
- package/decode.cjs.js +4 -1
- package/decode.esm.js +4 -1
- package/encode.cjs.js +4 -1
- package/encode.esm.js +4 -1
- package/ensureInt.cjs.js +5 -1
- package/ensureInt.esm.js +5 -1
- package/errorToString.cjs.js +6 -1
- package/errorToString.esm.js +6 -1
- package/escapeRegExp.cjs.js +7 -1
- package/escapeRegExp.esm.js +7 -1
- package/findDuplicatedIndexes.cjs.js +3 -10
- package/findDuplicatedIndexes.esm.js +3 -10
- package/forin.cjs.js +6 -5
- package/forin.esm.js +6 -5
- package/gbToBytes.cjs.js +5 -1
- package/gbToBytes.esm.js +5 -1
- package/getEmptyArray.cjs.js +6 -3
- package/getEmptyArray.esm.js +6 -3
- package/getKeys.cjs.js +8 -1
- package/getKeys.d.ts +1 -1
- package/getKeys.esm.js +8 -1
- package/getMediaQueryWidthResolvers.cjs.js +27 -41
- package/getMediaQueryWidthResolvers.esm.js +27 -41
- package/getMediaQueryWidthTailwindScreens.cjs.js +6 -25
- package/getMediaQueryWidthTailwindScreens.esm.js +6 -25
- package/getNonce.cjs.js +4 -1
- package/getNonce.esm.js +4 -1
- package/getParamAmong.cjs.js +11 -4
- package/getParamAmong.esm.js +11 -4
- package/getParamAsInt.cjs.js +10 -7
- package/getParamAsInt.esm.js +10 -7
- package/getParamAsString.cjs.js +9 -1
- package/getParamAsString.esm.js +9 -1
- package/getType.cjs.js +13 -1
- package/getType.esm.js +13 -1
- package/getUrlHashParams.cjs.js +6 -8
- package/getUrlHashParams.esm.js +6 -8
- package/getUrlHashPathname.cjs.js +7 -1
- package/getUrlHashPathname.esm.js +7 -1
- package/getUrlPathnameParts.cjs.js +10 -4
- package/getUrlPathnameParts.esm.js +10 -4
- package/getUrlQueryParams.cjs.js +12 -20
- package/getUrlQueryParams.esm.js +12 -20
- package/hashAny.cjs.d.ts +2 -0
- package/hashAny.cjs.default.js +1 -0
- package/hashAny.cjs.js +40 -0
- package/hashAny.cjs.mjs +2 -0
- package/hashAny.d.ts +2 -0
- package/hashAny.esm.js +35 -0
- package/imgEmptyPixel.cjs.js +5 -1
- package/imgEmptyPixel.esm.js +5 -1
- package/index.cjs.js +5 -3
- package/index.d.ts +2 -1
- package/index.esm.js +3 -2
- package/invariant.cjs.js +17 -16
- package/invariant.esm.js +17 -16
- package/isAbsoluteUrl.cjs.js +5 -2
- package/isAbsoluteUrl.esm.js +5 -2
- package/isAnyObject.cjs.js +5 -1
- package/isAnyObject.esm.js +5 -1
- package/isArray.cjs.js +5 -1
- package/isArray.esm.js +5 -1
- package/isBlob.cjs.js +5 -1
- package/isBlob.esm.js +5 -1
- package/isBoolean.cjs.js +5 -1
- package/isBoolean.esm.js +5 -1
- package/isBrowser.cjs.js +4 -1
- package/isBrowser.esm.js +4 -1
- package/isBrowserNow.cjs.js +4 -1
- package/isBrowserNow.esm.js +4 -1
- package/isDate.cjs.js +5 -1
- package/isDate.esm.js +5 -1
- package/isEmptyArray.cjs.js +5 -1
- package/isEmptyArray.esm.js +5 -1
- package/isEmptyObject.cjs.js +5 -1
- package/isEmptyObject.esm.js +5 -1
- package/isEmptyString.cjs.js +5 -1
- package/isEmptyString.esm.js +5 -1
- package/isError.cjs.js +5 -1
- package/isError.esm.js +5 -1
- package/isExternalUrl.cjs.js +9 -9
- package/isExternalUrl.esm.js +9 -9
- package/isFile.cjs.js +5 -1
- package/isFile.esm.js +5 -1
- package/isFloat.cjs.js +5 -1
- package/isFloat.esm.js +5 -1
- package/isFormData.cjs.js +5 -1
- package/isFormData.esm.js +5 -1
- package/isFullArray.cjs.js +5 -1
- package/isFullArray.esm.js +5 -1
- package/isFullObject.cjs.js +5 -1
- package/isFullObject.esm.js +5 -1
- package/isFullString.cjs.js +5 -1
- package/isFullString.esm.js +5 -1
- package/isFunction.cjs.js +5 -1
- package/isFunction.esm.js +5 -1
- package/isInt.cjs.js +5 -1
- package/isInt.esm.js +5 -1
- package/isMap.cjs.js +5 -1
- package/isMap.esm.js +5 -1
- package/isNaNValue.cjs.js +5 -1
- package/isNaNValue.esm.js +5 -1
- package/isNegativeNumber.cjs.js +5 -1
- package/isNegativeNumber.esm.js +5 -1
- package/isNull.cjs.js +5 -1
- package/isNull.esm.js +5 -1
- package/isNullOrUndefined.cjs.js +5 -1
- package/isNullOrUndefined.esm.js +5 -1
- package/isNumber.cjs.js +7 -1
- package/isNumber.esm.js +7 -1
- package/isNumericLiteral.cjs.js +8 -1
- package/isNumericLiteral.esm.js +8 -1
- package/isObject.cjs.js +5 -1
- package/isObject.esm.js +5 -1
- package/isObjectLike.cjs.js +7 -1
- package/isObjectLike.esm.js +7 -1
- package/isObjectStringKeyed.cjs.js +9 -1
- package/isObjectStringKeyed.esm.js +9 -1
- package/isOneOf.cjs.js +3 -7
- package/isOneOf.esm.js +3 -7
- package/isPlainObject.cjs.js +5 -4
- package/isPlainObject.esm.js +5 -4
- package/isPositiveNumber.cjs.js +5 -1
- package/isPositiveNumber.esm.js +5 -1
- package/isPrimitive.cjs.js +5 -6
- package/isPrimitive.esm.js +5 -6
- package/isPromise.cjs.js +5 -1
- package/isPromise.esm.js +5 -1
- package/isRegExp.cjs.js +5 -1
- package/isRegExp.esm.js +5 -1
- package/isServer.cjs.js +4 -1
- package/isServer.esm.js +4 -1
- package/isServerNow.cjs.js +4 -1
- package/isServerNow.esm.js +4 -1
- package/isSet.cjs.js +5 -1
- package/isSet.esm.js +5 -1
- package/isString.cjs.js +5 -1
- package/isString.esm.js +5 -1
- package/isSymbol.cjs.js +5 -1
- package/isSymbol.esm.js +5 -1
- package/isType.cjs.js +9 -11
- package/isType.esm.js +9 -11
- package/isUndefined.cjs.js +5 -1
- package/isUndefined.esm.js +5 -1
- package/isWeakMap.cjs.js +5 -1
- package/isWeakMap.esm.js +5 -1
- package/isWeakSet.cjs.js +5 -1
- package/isWeakSet.esm.js +5 -1
- package/kbToBytes.cjs.js +5 -1
- package/kbToBytes.esm.js +5 -1
- package/lowercase.cjs.js +5 -1
- package/lowercase.d.ts +1 -1
- package/lowercase.esm.js +5 -1
- package/mapListBy.cjs.js +5 -4
- package/mapListBy.esm.js +5 -4
- package/matchSorter.cjs.js +94 -239
- package/matchSorter.d.ts +1 -1
- package/matchSorter.esm.js +92 -237
- package/mbToBytes.cjs.js +5 -1
- package/mbToBytes.esm.js +5 -1
- package/mergeObjects.cjs.js +8 -26
- package/mergeObjects.esm.js +8 -26
- package/mergeUrlQueryParams.cjs.js +5 -12
- package/mergeUrlQueryParams.esm.js +5 -12
- package/moveSortableArrayItemByKey.cjs.js +7 -8
- package/moveSortableArrayItemByKey.esm.js +7 -8
- package/noop.cjs.js +5 -1
- package/noop.esm.js +5 -1
- package/normaliseUrl.cjs.js +9 -1
- package/normaliseUrl.esm.js +9 -1
- package/normaliseUrlPathname.cjs.js +8 -1
- package/normaliseUrlPathname.esm.js +8 -1
- package/objectFlat.cjs.js +8 -16
- package/objectFlat.esm.js +8 -16
- package/objectFlip.cjs.js +4 -4
- package/objectFlip.esm.js +4 -4
- package/objectMergeWithDefaults.cjs.js +29 -19
- package/objectMergeWithDefaults.d.ts +1 -1
- package/objectMergeWithDefaults.esm.js +29 -19
- package/objectOmit.cjs.js +9 -7
- package/objectOmit.esm.js +9 -7
- package/objectPick.cjs.js +6 -8
- package/objectPick.esm.js +6 -8
- package/objectSort.cjs.js +8 -1
- package/objectSort.esm.js +8 -1
- package/objectSortByKeysMatching.cjs.js +9 -1
- package/objectSortByKeysMatching.esm.js +9 -1
- package/objectToArray.cjs.js +6 -1
- package/objectToArray.esm.js +6 -1
- package/package.json +10 -5
- package/parseCookie.cjs.js +13 -32
- package/parseCookie.esm.js +13 -32
- package/parseURL.cjs.js +6 -13
- package/parseURL.esm.js +6 -13
- package/quaranteneProps.cjs.js +17 -15
- package/quaranteneProps.esm.js +17 -15
- package/randomInt.cjs.js +5 -1
- package/randomInt.esm.js +5 -1
- package/randomKey.cjs.js +6 -4
- package/randomKey.esm.js +6 -4
- package/readCookie.cjs.js +5 -33
- package/readCookie.esm.js +5 -33
- package/removeAccents.cjs.js +4 -9
- package/removeAccents.d.ts +1 -1
- package/removeAccents.esm.js +4 -9
- package/removeCookie.cjs.js +3 -7
- package/removeCookie.esm.js +3 -7
- package/removeDuplicates.cjs.js +8 -1
- package/removeDuplicates.esm.js +8 -1
- package/removeDuplicatesByKey.cjs.js +6 -12
- package/removeDuplicatesByKey.esm.js +6 -12
- package/removeDuplicatesComparing.cjs.js +3 -4
- package/removeDuplicatesComparing.esm.js +3 -4
- package/removeIndexesFromArray.cjs.js +4 -9
- package/removeIndexesFromArray.esm.js +4 -9
- package/removeTrailingSlash.cjs.js +5 -1
- package/removeTrailingSlash.esm.js +5 -1
- package/removeUrlQueryParams.cjs.js +5 -11
- package/removeUrlQueryParams.esm.js +5 -11
- package/render.cjs.js +52 -112
- package/render.esm.js +52 -112
- package/round.cjs.js +11 -3
- package/round.esm.js +11 -3
- package/roundTo.cjs.js +22 -10
- package/roundTo.esm.js +22 -10
- package/serializeCookie.cjs.js +13 -67
- package/serializeCookie.esm.js +13 -67
- package/setCookie.cjs.js +11 -41
- package/setCookie.esm.js +11 -41
- package/shuffle.cjs.js +15 -16
- package/shuffle.esm.js +15 -16
- package/slugify.cjs.js +20 -9
- package/slugify.esm.js +20 -9
- package/split.cjs.js +6 -1
- package/split.esm.js +6 -1
- package/splitReverse.cjs.js +6 -1
- package/splitReverse.esm.js +6 -1
- package/swapMap.cjs.js +5 -7
- package/swapMap.esm.js +5 -7
- package/throttle.cjs.js +6 -14
- package/throttle.d.ts +1 -1
- package/throttle.esm.js +6 -14
- package/titleCase.cjs.js +6 -3
- package/titleCase.esm.js +6 -3
- package/toNumber.cjs.js +5 -1
- package/toNumber.esm.js +5 -1
- package/toRgba.cjs.js +5 -7
- package/toRgba.esm.js +5 -7
- package/transformToUrlPathname.cjs.js +9 -3
- package/transformToUrlPathname.esm.js +9 -3
- package/truncate.cjs.js +5 -5
- package/truncate.esm.js +5 -5
- package/tryUntil.cjs.js +14 -14
- package/tryUntil.esm.js +14 -14
- package/uid.cjs.js +5 -5
- package/uid.esm.js +5 -5
- package/updateLinkParams.cjs.js +7 -5
- package/updateLinkParams.esm.js +7 -5
- package/updateUrlQueryParams.cjs.js +5 -7
- package/updateUrlQueryParams.esm.js +5 -7
- package/uppercase.cjs.js +6 -1
- package/uppercase.d.ts +1 -1
- package/uppercase.esm.js +6 -1
- package/uuid.cjs.js +6 -4
- package/uuid.esm.js +6 -4
- package/uuidNumeric.cjs.js +4 -1
- package/uuidNumeric.esm.js +4 -1
- package/wait.cjs.js +5 -1
- package/wait.esm.js +5 -1
- package/accentSets.cjs.d.ts +0 -2
- package/accentSets.cjs.default.js +0 -1
- package/accentSets.cjs.js +0 -36
- package/accentSets.cjs.mjs +0 -2
- package/accentSets.esm.js +0 -31
- /package/{accentSets.d.ts → accentsSets.d.ts} +0 -0
package/matchSorter.cjs.js
CHANGED
|
@@ -5,244 +5,99 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var isString = require('./isString.cjs.js');
|
|
6
6
|
var removeAccents = require('./removeAccents.cjs.js');
|
|
7
7
|
require('./getType.cjs.js');
|
|
8
|
-
require('./
|
|
8
|
+
require('./accentsSets.cjs.js');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const wordsInString = string.split(" ");
|
|
101
|
-
wordsInString.forEach((wordInString) => {
|
|
102
|
-
const splitByHyphenWords = wordInString.split("-");
|
|
103
|
-
splitByHyphenWords.forEach((splitByHyphenWord) => {
|
|
104
|
-
acronym += splitByHyphenWord.substring(0, 1);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
return acronym;
|
|
108
|
-
};
|
|
109
|
-
let getClosenessRanking = (testString, stringToRank) => {
|
|
110
|
-
let matchingInOrderCharCount = 0;
|
|
111
|
-
let charNumber = 0;
|
|
112
|
-
function findMatchingCharacter(matchChar, string, index) {
|
|
113
|
-
for (let j = index, J = string.length; j < J; j++) {
|
|
114
|
-
const stringChar = string[j];
|
|
115
|
-
if (stringChar === matchChar) {
|
|
116
|
-
matchingInOrderCharCount += 1;
|
|
117
|
-
return j + 1;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return -1;
|
|
121
|
-
}
|
|
122
|
-
function getRanking(spread) {
|
|
123
|
-
const spreadPercentage = 1 / spread;
|
|
124
|
-
const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
|
|
125
|
-
const ranking = RANKING_MATCHES + inOrderPercentage * spreadPercentage;
|
|
126
|
-
return ranking;
|
|
127
|
-
}
|
|
128
|
-
const firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
|
|
129
|
-
if (firstIndex < 0) {
|
|
130
|
-
return RANKING_NO_MATCH;
|
|
131
|
-
}
|
|
132
|
-
charNumber = firstIndex;
|
|
133
|
-
for (let i = 1, I = stringToRank.length; i < I; i++) {
|
|
134
|
-
const matchChar = stringToRank[i];
|
|
135
|
-
charNumber = findMatchingCharacter(matchChar, testString, charNumber);
|
|
136
|
-
const found = charNumber > -1;
|
|
137
|
-
if (!found) {
|
|
138
|
-
return RANKING_NO_MATCH;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const spread = charNumber - firstIndex;
|
|
142
|
-
return getRanking(spread);
|
|
143
|
-
};
|
|
144
|
-
let sortRankedValues = (a, b, baseSort) => {
|
|
145
|
-
const aFirst = -1;
|
|
146
|
-
const bFirst = 1;
|
|
147
|
-
const { rank: aRank, keyIndex: aKeyIndex } = a;
|
|
148
|
-
const { rank: bRank, keyIndex: bKeyIndex } = b;
|
|
149
|
-
const same = aRank === bRank;
|
|
150
|
-
if (same) {
|
|
151
|
-
if (aKeyIndex === bKeyIndex) {
|
|
152
|
-
return baseSort(a, b);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
return aKeyIndex < bKeyIndex ? aFirst : bFirst;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
return aRank > bRank ? aFirst : bFirst;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
let prepareValueForComparison = (value, { keepDiacritics }) => {
|
|
163
|
-
value = `${value}`;
|
|
164
|
-
if (!keepDiacritics) {
|
|
165
|
-
value = removeAccents.removeAccents(value);
|
|
166
|
-
}
|
|
167
|
-
return value;
|
|
168
|
-
};
|
|
169
|
-
let getItemValues = (item, key) => {
|
|
170
|
-
if (typeof key === "object") {
|
|
171
|
-
key = key.key;
|
|
172
|
-
}
|
|
173
|
-
let value;
|
|
174
|
-
if (typeof key === "function") {
|
|
175
|
-
value = key(item);
|
|
176
|
-
}
|
|
177
|
-
else if (item == null) {
|
|
178
|
-
value = null;
|
|
179
|
-
}
|
|
180
|
-
else if (Object.hasOwnProperty.call(item, key)) {
|
|
181
|
-
value = item[key];
|
|
182
|
-
}
|
|
183
|
-
else if (key.includes(".")) {
|
|
184
|
-
return getNestedValues(key, item);
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
value = null;
|
|
188
|
-
}
|
|
189
|
-
if (value == null) {
|
|
190
|
-
return [];
|
|
191
|
-
}
|
|
192
|
-
if (Array.isArray(value)) {
|
|
193
|
-
return value;
|
|
194
|
-
}
|
|
195
|
-
return [String(value)];
|
|
196
|
-
};
|
|
197
|
-
let getNestedValues = (path, item) => {
|
|
198
|
-
const keys = path.split(".");
|
|
199
|
-
let values = [item];
|
|
200
|
-
for (let i = 0, I = keys.length; i < I; i++) {
|
|
201
|
-
const nestedKey = keys[i];
|
|
202
|
-
let nestedValues = [];
|
|
203
|
-
for (let j = 0, J = values.length; j < J; j++) {
|
|
204
|
-
const nestedItem = values[j];
|
|
205
|
-
if (nestedItem == null)
|
|
206
|
-
continue;
|
|
207
|
-
if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
|
|
208
|
-
const nestedValue = nestedItem[nestedKey];
|
|
209
|
-
if (nestedValue != null) {
|
|
210
|
-
nestedValues.push(nestedValue);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
else if (nestedKey === "*") {
|
|
214
|
-
nestedValues = nestedValues.concat(nestedItem);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
values = nestedValues;
|
|
218
|
-
}
|
|
219
|
-
if (Array.isArray(values[0])) {
|
|
220
|
-
const result = [];
|
|
221
|
-
return result.concat(...values);
|
|
222
|
-
}
|
|
223
|
-
return values;
|
|
224
|
-
};
|
|
225
|
-
let getAllValuesToRank = (item, keys) => {
|
|
226
|
-
const allValues = [];
|
|
227
|
-
for (let j = 0, J = keys.length; j < J; j++) {
|
|
228
|
-
const key = keys[j];
|
|
229
|
-
const attributes = getKeyAttributes(key);
|
|
230
|
-
const itemValues = getItemValues(item, key);
|
|
231
|
-
for (let i = 0, I = itemValues.length; i < I; i++) {
|
|
232
|
-
allValues.push({
|
|
233
|
-
itemValue: itemValues[i],
|
|
234
|
-
attributes,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return allValues;
|
|
239
|
-
};
|
|
240
|
-
const defaultKeyAttributes = {
|
|
241
|
-
maxRanking: Infinity,
|
|
242
|
-
minRanking: -Infinity,
|
|
243
|
-
};
|
|
244
|
-
let getKeyAttributes = (key) => isString.isString(key) ? defaultKeyAttributes : { ...defaultKeyAttributes, ...key };
|
|
10
|
+
let r=(e,t)=>String(e.rankedValue).localeCompare(String(t.rankedValue)),/**
|
|
11
|
+
* Takes an array of items and a value and returns a new array with the items that match the given value
|
|
12
|
+
* @param {Array} items - the items to sort
|
|
13
|
+
* @param {String} value - the value to use for ranking
|
|
14
|
+
* @param {Object} options - Some options to configure the sorter
|
|
15
|
+
* @return {Array} - the new sorted array
|
|
16
|
+
*/l=(e,t,l={})=>{let{keys:u,threshold:a=1,baseSort:o=r,sorter:s=e=>e.sort((e,t)=>i(e,t,o))}=l;return s(e.reduce(function(e,r,o){let i=n(r,u,t,l),{rank:s,keyThreshold:h=a}=i;return s>=h&&e.push({...i,item:r,index:o}),e},[])).map(({item:e})=>e)},/**
|
|
17
|
+
* Gets the highest ranking for value for the given item based on its values for the given keys
|
|
18
|
+
* @param {*} item - the item to rank
|
|
19
|
+
* @param {Array} keys - the keys to get values from the item for the ranking
|
|
20
|
+
* @param {String} value - the value to rank against
|
|
21
|
+
* @param {Object} options - options to control the ranking
|
|
22
|
+
* @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking
|
|
23
|
+
*/n=(e,t,r,l)=>t?c(e,t).reduce(({rank:e,rankedValue:t,keyIndex:n,keyThreshold:a},{itemValue:o,attributes:i},s)=>{let h=u(o,r,l),f=t,{minRanking:c,maxRanking:d,threshold:k}=i;return h<c&&h>=1?h=c:h>d&&(h=d),h>e&&(e=h,n=s,a=k,f=o),{rankedValue:f,rank:e,keyIndex:n,keyThreshold:a}},{rankedValue:e,rank:0,keyIndex:-1,keyThreshold:l.threshold}):{// ends up being duplicate of 'item' in matches but consistent
|
|
24
|
+
rankedValue:// if keys is not specified, then we assume the item given is ready to be matched
|
|
25
|
+
e,rank:u(e,r,l),keyIndex:-1,keyThreshold:l.threshold},/**
|
|
26
|
+
* Gives a rankings score based on how well the two strings match.
|
|
27
|
+
* @param {String} testString - the string to test against
|
|
28
|
+
* @param {String} stringToRank - the string to rank
|
|
29
|
+
* @param {Object} options - options for the match (like keepDiacritics for comparison)
|
|
30
|
+
* @returns {Number} the ranking for how well stringToRank matches testString
|
|
31
|
+
*/u=(e,t,r)=>// too long
|
|
32
|
+
(e=s(e,r),(t=s(t,r)).length>e.length)?0:// case sensitive equals
|
|
33
|
+
e===t?7:// case insensitive equals
|
|
34
|
+
// Lower casing before further comparison
|
|
35
|
+
(e=e.toLowerCase())===(t=t.toLowerCase())?6:// starts with
|
|
36
|
+
e.startsWith(t)?5:// word starts with
|
|
37
|
+
e.includes(` ${t}`)?4:// contains
|
|
38
|
+
e.includes(t)?3:1===t.length?0:// If the only character in the given stringToRank
|
|
39
|
+
// isn't even contained in the testString, then
|
|
40
|
+
// it's definitely not a match.
|
|
41
|
+
// acronym
|
|
42
|
+
a(e).includes(t)?2:// will return a number between RANKING_MATCHES and
|
|
43
|
+
// RANKING_MATCHES + 1 depending on how close of a match it is.
|
|
44
|
+
o(e,t),/**
|
|
45
|
+
* Generates an acronym for a string.
|
|
46
|
+
*
|
|
47
|
+
* @param {String} string the string for which to produce the acronym
|
|
48
|
+
* @returns {String} the acronym
|
|
49
|
+
*/a=e=>{let t="";return e.split(" ").forEach(e=>{e.split("-").forEach(e=>{t+=e.substring(0,1);});}),t},/**
|
|
50
|
+
* Returns a score based on how spread apart the
|
|
51
|
+
* characters from the stringToRank are within the testString.
|
|
52
|
+
* A number close to RANKING_MATCHES represents a loose match. A number close
|
|
53
|
+
* to RANKING_MATCHES + 1 represents a tighter match.
|
|
54
|
+
* @param {String} testString - the string to test against
|
|
55
|
+
* @param {String} stringToRank - the string to rank
|
|
56
|
+
* @returns {Number} the number between RANKING_MATCHES and
|
|
57
|
+
* RANKING_MATCHES + 1 for how well stringToRank matches testString
|
|
58
|
+
*/o=(e,t)=>{let r=0,l=0;function n(e,t,l){for(let n=l,u=t.length;n<u;n++)if(t[n]===e)return r+=1,n+1;return -1}let u=n(t[0],e,0);if(u<0)return 0;l=u;for(let r=1,u=t.length;r<u;r++)if(!((l=n(t[r],e,l))>-1))return 0;return 1+1/(l-u)*(r/t.length)},/**
|
|
59
|
+
* Sorts items that have a rank, index, and keyIndex
|
|
60
|
+
* @param {Object} a - the first item to sort
|
|
61
|
+
* @param {Object} b - the second item to sort
|
|
62
|
+
* @return {Number} -1 if a should come first, 1 if b should come first, 0 if equal
|
|
63
|
+
*/i=(e,t,r)=>{let{rank:l,keyIndex:n}=e,{rank:u,keyIndex:a}=t;return l!==u?l>u?-1:1:n===a?// use the base sort function as a tie-breaker
|
|
64
|
+
r(e,t):n<a?-1:1},/**
|
|
65
|
+
* Prepares value for comparison by stringifying it, removing diacritics (if specified)
|
|
66
|
+
* @param {String} value - the value to clean
|
|
67
|
+
* @param {Object} options - {keepDiacritics: whether to remove diacritics}
|
|
68
|
+
* @return {String} the prepared value
|
|
69
|
+
*/s=(e,{keepDiacritics:r})=>(// value might not actually be a string at this point (we don't get to choose)
|
|
70
|
+
// so part of preparing the value for comparison is ensure that it is a string
|
|
71
|
+
e=`${e}`,// toString
|
|
72
|
+
r||(e=removeAccents.removeAccents(e)),e),/**
|
|
73
|
+
* Gets value for key in item at arbitrarily nested keypath
|
|
74
|
+
* @param {Object} item - the item
|
|
75
|
+
* @param {Object|Function} key - the potentially nested keypath or property callback
|
|
76
|
+
* @return {Array} - an array containing the value(s) at the nested keypath
|
|
77
|
+
*/h=(e,t)=>{let r;if("object"==typeof t&&(t=t.key),"function"==typeof t)r=t(e);else if(null==e)r=null;else if(Object.hasOwnProperty.call(e,t))r=e[t];else {if(t.includes("."))// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
78
|
+
return f(t,e);r=null;}return(// because `value` can also be undefined
|
|
79
|
+
null==r?[]:Array.isArray(r)?r:[String(r)])},/**
|
|
80
|
+
* Given path: "foo.bar.baz"
|
|
81
|
+
* And item: {foo: {bar: {baz: 'buzz'}}}
|
|
82
|
+
* -> 'buzz'
|
|
83
|
+
* @param path a dot-separated set of keys
|
|
84
|
+
* @param item the item to get the value from
|
|
85
|
+
*/f=(e,t)=>{let r=e.split("."),l=[t];for(let e=0,t=r.length;e<t;e++){let t=r[e],n=[];for(let e=0,r=l.length;e<r;e++){let r=l[e];if(null!=r){if(Object.hasOwnProperty.call(r,t)){let e=r[t];null!=e&&n.push(e);}else "*"===t&&// ensure that values is an array
|
|
86
|
+
(n=n.concat(r));}}l=n;}return Array.isArray(l[0])?// keep allowing the implicit wildcard for an array of strings at the end of
|
|
87
|
+
// the path; don't use `.flat()` because that's not available in node.js v10
|
|
88
|
+
[].concat(...l):// Based on our logic it should be an array of strings by now...
|
|
89
|
+
// assuming the user's path terminated in strings
|
|
90
|
+
l},/**
|
|
91
|
+
* Gets all the values for the given keys in the given item and returns an array of those values
|
|
92
|
+
* @param item - the item from which the values will be retrieved
|
|
93
|
+
* @param keys - the keys to use to retrieve the values
|
|
94
|
+
* @return objects with {itemValue, attributes}
|
|
95
|
+
*/c=(e,t)=>{let r=[];for(let l=0,n=t.length;l<n;l++){let n=t[l],u=k(n),a=h(e,n);for(let e=0,t=a.length;e<t;e++)r.push({itemValue:a[e],attributes:u});}return r},d={maxRanking:1/0,minRanking:-1/0},/**
|
|
96
|
+
* Gets all the attributes for the given key
|
|
97
|
+
* @param key - the key from which the attributes will be retrieved
|
|
98
|
+
* @return object containing the key's attributes
|
|
99
|
+
*/k=t=>isString.isString(t)?d:{...d,...t};
|
|
245
100
|
|
|
246
|
-
exports["default"] =
|
|
247
|
-
exports.defaultBaseSortFn =
|
|
248
|
-
exports.matchSorter =
|
|
101
|
+
exports["default"] = l;
|
|
102
|
+
exports.defaultBaseSortFn = r;
|
|
103
|
+
exports.matchSorter = l;
|
package/matchSorter.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ declare const RANKING_MATCHES = 1;
|
|
|
48
48
|
declare const RANKING_NO_MATCH = 0;
|
|
49
49
|
type Ranking = typeof RANKING_CASE_SENSITIVE_EQUAL | typeof RANKING_EQUAL | typeof RANKING_STARTS_WITH | typeof RANKING_WORD_STARTS_WITH | typeof RANKING_CONTAINS | typeof RANKING_ACRONYM | typeof RANKING_MATCHES | typeof RANKING_NO_MATCH;
|
|
50
50
|
declare let defaultBaseSortFn: BaseSorter<unknown>;
|
|
51
|
-
declare let matchSorter: <ItemType = string>(items:
|
|
51
|
+
declare let matchSorter: <ItemType = string>(items: ReadonlyArray<ItemType>, value: string, options?: MatchSorterOptions<ItemType>) => Array<ItemType>;
|
|
52
52
|
export { matchSorter, defaultBaseSortFn };
|
|
53
53
|
export type { MatchSorterOptions, KeyAttributesOptions, KeyOption, KeyAttributes, RankingInfo, ValueGetterKey, };
|
|
54
54
|
export default matchSorter;
|