@koine/utils 2.0.0-beta.2 → 2.0.0-beta.4
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.js +23 -18
- package/Defer.mjs +6 -5
- package/Emitter.js +31 -20
- package/Emitter.mjs +13 -16
- package/README.md +5 -1
- package/accentSets.js +129 -37
- package/accentSets.mjs +113 -29
- package/addOrReplaceAtIdx.js +27 -10
- package/addOrReplaceAtIdx.mjs +9 -6
- package/areEqual.js +35 -41
- package/areEqual.mjs +16 -22
- package/arrayOfAll.js +20 -11
- package/arrayOfAll.mjs +1 -6
- package/arraySum.js +20 -9
- package/arraySum.mjs +1 -4
- package/arrayToLookup.js +21 -9
- package/arrayToLookup.mjs +2 -4
- package/buildUrlQueryString.js +32 -29
- package/buildUrlQueryString.mjs +11 -14
- package/capitalize.js +21 -9
- package/capitalize.mjs +3 -5
- package/changeUrlPath.js +23 -17
- package/changeUrlPath.mjs +2 -3
- package/chunkByChunks.js +35 -24
- package/chunkByChunks.mjs +17 -20
- package/chunkBySize.js +21 -8
- package/chunkBySize.mjs +3 -4
- package/clamp.js +19 -6
- package/clamp.mjs +1 -2
- package/clsx.js +29 -23
- package/clsx.mjs +11 -14
- package/convertRange.js +20 -7
- package/convertRange.mjs +2 -3
- package/cookie.js +13 -5
- package/cookie.mjs +3 -2
- package/createPalette.js +27 -19
- package/createPalette.mjs +9 -6
- package/debounce.js +27 -21
- package/debounce.mjs +9 -17
- package/debouncePromise.js +20 -11
- package/debouncePromise.mjs +1 -2
- package/debounceRaf.js +23 -14
- package/debounceRaf.mjs +5 -10
- package/decode.js +20 -7
- package/decode.mjs +2 -3
- package/encode.js +20 -7
- package/encode.mjs +2 -3
- package/ensureInt.js +20 -9
- package/ensureInt.mjs +1 -4
- package/env.js +1 -1
- package/env.mjs +0 -1
- package/errorToString.js +21 -14
- package/errorToString.mjs +1 -4
- package/findDuplicatedIndexes.js +22 -9
- package/findDuplicatedIndexes.mjs +4 -5
- package/forin.js +20 -7
- package/forin.mjs +2 -3
- package/gbToBytes.js +20 -7
- package/gbToBytes.mjs +1 -2
- package/getEmptyArray.js +25 -16
- package/getEmptyArray.mjs +4 -3
- package/getKeys.js +20 -6
- package/getKeys.mjs +1 -2
- package/getMediaQueryWidthResolvers.js +62 -53
- package/getMediaQueryWidthResolvers.mjs +44 -49
- package/getMediaQueryWidthTailwindScreens.js +36 -18
- package/getMediaQueryWidthTailwindScreens.mjs +18 -14
- package/getNonce.js +20 -10
- package/getNonce.mjs +1 -2
- package/getParamAmong.js +22 -19
- package/getParamAmong.mjs +2 -4
- package/getParamAsInt.js +22 -19
- package/getParamAsInt.mjs +2 -4
- package/getParamAsString.js +21 -16
- package/getParamAsString.mjs +1 -2
- package/getType.js +19 -12
- package/getType.mjs +2 -4
- package/getUrlHashParams.js +20 -13
- package/getUrlHashParams.mjs +2 -4
- package/getUrlHashPathname.js +20 -8
- package/getUrlHashPathname.mjs +1 -3
- package/getUrlPathnameParts.js +23 -23
- package/getUrlPathnameParts.mjs +2 -7
- package/getUrlQueryParams.js +26 -33
- package/getUrlQueryParams.mjs +7 -18
- package/imgEmptyPixel.js +20 -6
- package/imgEmptyPixel.mjs +1 -2
- package/index.js +531 -266
- package/index.mjs +2 -2
- package/invariant.js +24 -12
- package/invariant.mjs +6 -8
- package/isAnyObject.js +21 -12
- package/isAnyObject.mjs +1 -2
- package/isArray.js +21 -12
- package/isArray.mjs +1 -2
- package/isBlob.js +21 -12
- package/isBlob.mjs +1 -2
- package/isBoolean.js +21 -12
- package/isBoolean.mjs +1 -2
- package/isBrowser.js +20 -6
- package/isBrowser.mjs +1 -2
- package/isBrowserNow.js +21 -11
- package/isBrowserNow.mjs +1 -2
- package/isDate.js +21 -12
- package/isDate.mjs +1 -2
- package/isEmptyArray.js +21 -12
- package/isEmptyArray.mjs +1 -2
- package/isEmptyObject.js +21 -12
- package/isEmptyObject.mjs +1 -2
- package/isEmptyString.js +19 -6
- package/isEmptyString.mjs +1 -2
- package/isError.js +21 -12
- package/isError.mjs +1 -2
- package/isExternalUrl.js +24 -18
- package/isExternalUrl.mjs +4 -6
- package/isFile.js +21 -12
- package/isFile.mjs +1 -2
- package/isFloat.js +21 -12
- package/isFloat.mjs +1 -2
- package/isFormData.js +21 -12
- package/isFormData.mjs +1 -2
- package/isFullArray.js +21 -12
- package/isFullArray.mjs +1 -2
- package/isFullObject.js +21 -12
- package/isFullObject.mjs +1 -2
- package/isFullString.js +21 -12
- package/isFullString.mjs +1 -2
- package/isFunction.js +18 -9
- package/isFunction.mjs +1 -2
- package/isInt.js +21 -12
- package/isInt.mjs +1 -2
- package/isMap.js +21 -12
- package/isMap.mjs +1 -2
- package/isNaNValue.js +21 -12
- package/isNaNValue.mjs +1 -2
- package/isNegativeNumber.js +21 -12
- package/isNegativeNumber.mjs +1 -2
- package/isNull.js +21 -12
- package/isNull.mjs +1 -2
- package/isNullOrUndefined.js +23 -13
- package/isNullOrUndefined.mjs +1 -2
- package/isNumber.js +21 -14
- package/isNumber.mjs +1 -2
- package/isObject.js +21 -12
- package/isObject.mjs +1 -2
- package/isObjectLike.js +21 -14
- package/isObjectLike.mjs +1 -2
- package/isOneOf.js +19 -11
- package/isOneOf.mjs +1 -7
- package/isPlainObject.js +22 -15
- package/isPlainObject.mjs +3 -6
- package/isPositiveNumber.js +21 -12
- package/isPositiveNumber.mjs +1 -2
- package/isPrimitive.js +26 -22
- package/isPrimitive.mjs +5 -11
- package/isPromise.js +21 -12
- package/isPromise.mjs +1 -2
- package/isRegExp.js +21 -12
- package/isRegExp.mjs +1 -2
- package/isServer.js +22 -11
- package/isServer.mjs +1 -2
- package/isServerNow.js +21 -11
- package/isServerNow.mjs +1 -2
- package/isSet.js +21 -12
- package/isSet.mjs +1 -2
- package/isString.js +21 -12
- package/isString.mjs +1 -2
- package/isSymbol.js +21 -12
- package/isSymbol.mjs +1 -2
- package/isType.js +22 -17
- package/isType.mjs +3 -5
- package/isUndefined.js +21 -12
- package/isUndefined.mjs +1 -2
- package/isWeakMap.js +21 -12
- package/isWeakMap.mjs +1 -2
- package/isWeakSet.js +21 -12
- package/isWeakSet.mjs +1 -2
- package/kbToBytes.js +20 -7
- package/kbToBytes.mjs +1 -2
- package/location.js +6 -2
- package/location.mjs +3 -1
- package/lowercase.js +20 -9
- package/lowercase.mjs +1 -4
- package/mapListBy.js +21 -10
- package/mapListBy.mjs +2 -5
- package/matchSorter.js +132 -133
- package/matchSorter.mjs +108 -126
- package/mbToBytes.js +20 -7
- package/mbToBytes.mjs +1 -2
- package/mergeObjects.d.ts +1 -1
- package/mergeObjects.js +24 -26
- package/mergeObjects.mjs +12 -15
- package/mergeUrlQueryParams.js +25 -20
- package/mergeUrlQueryParams.mjs +4 -8
- package/moveSortableArrayItemByKey.js +26 -12
- package/moveSortableArrayItemByKey.mjs +8 -8
- package/noop.js +20 -7
- package/noop.mjs +1 -2
- package/normaliseUrl.js +22 -18
- package/normaliseUrl.mjs +1 -3
- package/normaliseUrlPathname.js +22 -17
- package/normaliseUrlPathname.mjs +1 -3
- package/objectOmit.js +21 -9
- package/objectOmit.mjs +3 -5
- package/objectPick.js +22 -9
- package/objectPick.mjs +4 -5
- package/package.json +11 -8
- package/parseCookie.js +29 -26
- package/parseCookie.mjs +11 -15
- package/parseURL.js +23 -10
- package/parseURL.mjs +5 -6
- package/quaranteneProps.js +24 -12
- package/quaranteneProps.mjs +6 -8
- package/randomInt.js +19 -6
- package/randomInt.mjs +1 -2
- package/randomKey.js +21 -8
- package/randomKey.mjs +3 -4
- package/readCookie.js +25 -12
- package/readCookie.mjs +7 -8
- package/removeAccents.js +24 -15
- package/removeAccents.mjs +5 -8
- package/removeCookie.js +26 -17
- package/removeCookie.mjs +6 -5
- package/removeDuplicates.js +1 -1
- package/removeDuplicates.mjs +0 -1
- package/removeDuplicatesByKey.js +24 -12
- package/removeDuplicatesByKey.mjs +5 -7
- package/removeDuplicatesComparing.js +22 -11
- package/removeDuplicatesComparing.mjs +3 -4
- package/removeIndexesFromArray.js +21 -8
- package/removeIndexesFromArray.mjs +3 -4
- package/removeTrailingSlash.js +20 -8
- package/removeTrailingSlash.mjs +1 -3
- package/removeUrlQueryParams.js +27 -20
- package/removeUrlQueryParams.mjs +5 -7
- package/render.js +61 -137
- package/render.mjs +43 -98
- package/roundTo.js +34 -22
- package/roundTo.mjs +15 -17
- package/serializeCookie.js +29 -35
- package/serializeCookie.mjs +9 -15
- package/setCookie.js +37 -31
- package/setCookie.mjs +13 -16
- package/shuffle.js +28 -14
- package/shuffle.mjs +10 -10
- package/slugify.js +33 -25
- package/slugify.mjs +13 -11
- package/split.js +18 -4
- package/swapMap.js +22 -10
- package/swapMap.mjs +3 -5
- package/throttle.d.ts +1 -0
- package/throttle.js +23 -15
- package/throttle.mjs +5 -11
- package/titleCase.js +20 -11
- package/titleCase.mjs +1 -6
- package/toNumber.js +20 -9
- package/toNumber.mjs +1 -2
- package/toRgba.js +22 -10
- package/toRgba.mjs +3 -5
- package/transformToUrlPathname.js +21 -18
- package/transformToUrlPathname.mjs +2 -5
- package/truncate.js +20 -13
- package/truncate.mjs +1 -8
- package/tryUntil.js +26 -15
- package/tryUntil.mjs +7 -10
- package/types.js +4 -1
- package/types.mjs +2 -1
- package/uid.js +21 -13
- package/uid.mjs +3 -5
- package/updateLinkParams.js +21 -14
- package/updateLinkParams.mjs +2 -3
- package/updateUrlQueryParams.js +26 -21
- package/updateUrlQueryParams.mjs +3 -7
- package/uppercase.js +20 -9
- package/uppercase.mjs +1 -4
- package/uuid.js +21 -10
- package/uuid.mjs +2 -5
- package/uuidNumeric.js +20 -7
- package/uuidNumeric.mjs +1 -2
- package/wait.js +20 -9
- package/wait.mjs +1 -4
- package/without.js +2 -3
- package/without.mjs +1 -3
package/matchSorter.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* @file
|
|
4
3
|
*
|
|
@@ -14,41 +13,35 @@ import { __assign } from "tslib";
|
|
|
14
13
|
* @license MIT license.
|
|
15
14
|
* @copyright (c) 2020 Kent C. Dodds
|
|
16
15
|
* @author Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var defaultBaseSortFn = function (a, b) {
|
|
28
|
-
return String(a.rankedValue).localeCompare(String(b.rankedValue));
|
|
29
|
-
};
|
|
16
|
+
*/ import removeAccents from "./removeAccents";
|
|
17
|
+
const RANKING_CASE_SENSITIVE_EQUAL = 7;
|
|
18
|
+
const RANKING_EQUAL = 6;
|
|
19
|
+
const RANKING_STARTS_WITH = 5;
|
|
20
|
+
const RANKING_WORD_STARTS_WITH = 4;
|
|
21
|
+
const RANKING_CONTAINS = 3;
|
|
22
|
+
const RANKING_ACRONYM = 2;
|
|
23
|
+
const RANKING_MATCHES = 1;
|
|
24
|
+
const RANKING_NO_MATCH = 0;
|
|
25
|
+
const defaultBaseSortFn = (a, b)=>String(a.rankedValue).localeCompare(String(b.rankedValue));
|
|
30
26
|
/**
|
|
31
27
|
* Takes an array of items and a value and returns a new array with the items that match the given value
|
|
32
28
|
* @param {Array} items - the items to sort
|
|
33
29
|
* @param {String} value - the value to use for ranking
|
|
34
30
|
* @param {Object} options - Some options to configure the sorter
|
|
35
31
|
* @return {Array} - the new sorted array
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return matchedItems.sort(function (a, b) { return sortRankedValues(a, b, baseSort); });
|
|
41
|
-
} : _c;
|
|
42
|
-
var matchedItems = items.reduce(reduceItemsToRanked, []);
|
|
43
|
-
return sorter(matchedItems).map(function (_a) {
|
|
44
|
-
var item = _a.item;
|
|
45
|
-
return item;
|
|
46
|
-
});
|
|
32
|
+
*/ function matchSorter(items, value, options = {}) {
|
|
33
|
+
const { keys, threshold = RANKING_MATCHES, baseSort = defaultBaseSortFn, sorter = (matchedItems)=>matchedItems.sort((a, b)=>sortRankedValues(a, b, baseSort)) } = options;
|
|
34
|
+
const matchedItems = items.reduce(reduceItemsToRanked, []);
|
|
35
|
+
return sorter(matchedItems).map(({ item })=>item);
|
|
47
36
|
function reduceItemsToRanked(matches, item, index) {
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
const rankingInfo = getHighestRanking(item, keys, value, options);
|
|
38
|
+
const { rank, keyThreshold = threshold } = rankingInfo;
|
|
50
39
|
if (rank >= keyThreshold) {
|
|
51
|
-
matches.push(
|
|
40
|
+
matches.push({
|
|
41
|
+
...rankingInfo,
|
|
42
|
+
item,
|
|
43
|
+
index
|
|
44
|
+
});
|
|
52
45
|
}
|
|
53
46
|
return matches;
|
|
54
47
|
}
|
|
@@ -60,30 +53,26 @@ function matchSorter(items, value, options) {
|
|
|
60
53
|
* @param {String} value - the value to rank against
|
|
61
54
|
* @param {Object} options - options to control the ranking
|
|
62
55
|
* @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking
|
|
63
|
-
*/
|
|
64
|
-
function getHighestRanking(item, keys, value, options) {
|
|
56
|
+
*/ function getHighestRanking(item, keys, value, options) {
|
|
65
57
|
if (!keys) {
|
|
66
58
|
// if keys is not specified, then we assume the item given is ready to be matched
|
|
67
|
-
|
|
59
|
+
const stringItem = item;
|
|
68
60
|
return {
|
|
69
61
|
// ends up being duplicate of 'item' in matches but consistent
|
|
70
62
|
rankedValue: stringItem,
|
|
71
63
|
rank: getMatchRanking(stringItem, value, options),
|
|
72
64
|
keyIndex: -1,
|
|
73
|
-
keyThreshold: options.threshold
|
|
65
|
+
keyThreshold: options.threshold
|
|
74
66
|
};
|
|
75
67
|
}
|
|
76
|
-
|
|
77
|
-
return valuesToRank.reduce(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var newRankedValue = rankedValue;
|
|
82
|
-
var minRanking = attributes.minRanking, maxRanking = attributes.maxRanking, threshold = attributes.threshold;
|
|
68
|
+
const valuesToRank = getAllValuesToRank(item, keys);
|
|
69
|
+
return valuesToRank.reduce(({ rank, rankedValue, keyIndex, keyThreshold }, { itemValue, attributes }, i)=>{
|
|
70
|
+
let newRank = getMatchRanking(itemValue, value, options);
|
|
71
|
+
let newRankedValue = rankedValue;
|
|
72
|
+
const { minRanking, maxRanking, threshold } = attributes;
|
|
83
73
|
if (newRank < minRanking && newRank >= RANKING_MATCHES) {
|
|
84
74
|
newRank = minRanking;
|
|
85
|
-
}
|
|
86
|
-
else if (newRank > maxRanking) {
|
|
75
|
+
} else if (newRank > maxRanking) {
|
|
87
76
|
newRank = maxRanking;
|
|
88
77
|
}
|
|
89
78
|
if (newRank > rank) {
|
|
@@ -92,12 +81,17 @@ function getHighestRanking(item, keys, value, options) {
|
|
|
92
81
|
keyThreshold = threshold;
|
|
93
82
|
newRankedValue = itemValue;
|
|
94
83
|
}
|
|
95
|
-
return {
|
|
84
|
+
return {
|
|
85
|
+
rankedValue: newRankedValue,
|
|
86
|
+
rank,
|
|
87
|
+
keyIndex,
|
|
88
|
+
keyThreshold
|
|
89
|
+
};
|
|
96
90
|
}, {
|
|
97
91
|
rankedValue: item,
|
|
98
92
|
rank: RANKING_NO_MATCH,
|
|
99
93
|
keyIndex: -1,
|
|
100
|
-
keyThreshold: options.threshold
|
|
94
|
+
keyThreshold: options.threshold
|
|
101
95
|
});
|
|
102
96
|
}
|
|
103
97
|
/**
|
|
@@ -106,8 +100,7 @@ function getHighestRanking(item, keys, value, options) {
|
|
|
106
100
|
* @param {String} stringToRank - the string to rank
|
|
107
101
|
* @param {Object} options - options for the match (like keepDiacritics for comparison)
|
|
108
102
|
* @returns {Number} the ranking for how well stringToRank matches testString
|
|
109
|
-
*/
|
|
110
|
-
function getMatchRanking(testString, stringToRank, options) {
|
|
103
|
+
*/ function getMatchRanking(testString, stringToRank, options) {
|
|
111
104
|
testString = prepareValueForComparison(testString, options);
|
|
112
105
|
stringToRank = prepareValueForComparison(stringToRank, options);
|
|
113
106
|
// too long
|
|
@@ -130,14 +123,13 @@ function getMatchRanking(testString, stringToRank, options) {
|
|
|
130
123
|
return RANKING_STARTS_WITH;
|
|
131
124
|
}
|
|
132
125
|
// word starts with
|
|
133
|
-
if (testString.includes(
|
|
126
|
+
if (testString.includes(` ${stringToRank}`)) {
|
|
134
127
|
return RANKING_WORD_STARTS_WITH;
|
|
135
128
|
}
|
|
136
129
|
// contains
|
|
137
130
|
if (testString.includes(stringToRank)) {
|
|
138
131
|
return RANKING_CONTAINS;
|
|
139
|
-
}
|
|
140
|
-
else if (stringToRank.length === 1) {
|
|
132
|
+
} else if (stringToRank.length === 1) {
|
|
141
133
|
// If the only character in the given stringToRank
|
|
142
134
|
// isn't even contained in the testString, then
|
|
143
135
|
// it's definitely not a match.
|
|
@@ -156,13 +148,12 @@ function getMatchRanking(testString, stringToRank, options) {
|
|
|
156
148
|
*
|
|
157
149
|
* @param {String} string the string for which to produce the acronym
|
|
158
150
|
* @returns {String} the acronym
|
|
159
|
-
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
splitByHyphenWords.forEach(function (splitByHyphenWord) {
|
|
151
|
+
*/ function getAcronym(string) {
|
|
152
|
+
let acronym = "";
|
|
153
|
+
const wordsInString = string.split(" ");
|
|
154
|
+
wordsInString.forEach((wordInString)=>{
|
|
155
|
+
const splitByHyphenWords = wordInString.split("-");
|
|
156
|
+
splitByHyphenWords.forEach((splitByHyphenWord)=>{
|
|
166
157
|
acronym += splitByHyphenWord.substring(0, 1);
|
|
167
158
|
});
|
|
168
159
|
});
|
|
@@ -177,13 +168,12 @@ function getAcronym(string) {
|
|
|
177
168
|
* @param {String} stringToRank - the string to rank
|
|
178
169
|
* @returns {Number} the number between RANKING_MATCHES and
|
|
179
170
|
* RANKING_MATCHES + 1 for how well stringToRank matches testString
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var charNumber = 0;
|
|
171
|
+
*/ function getClosenessRanking(testString, stringToRank) {
|
|
172
|
+
let matchingInOrderCharCount = 0;
|
|
173
|
+
let charNumber = 0;
|
|
184
174
|
function findMatchingCharacter(matchChar, string, index) {
|
|
185
|
-
for
|
|
186
|
-
|
|
175
|
+
for(let j = index, J = string.length; j < J; j++){
|
|
176
|
+
const stringChar = string[j];
|
|
187
177
|
if (stringChar === matchChar) {
|
|
188
178
|
matchingInOrderCharCount += 1;
|
|
189
179
|
return j + 1;
|
|
@@ -192,25 +182,25 @@ function getClosenessRanking(testString, stringToRank) {
|
|
|
192
182
|
return -1;
|
|
193
183
|
}
|
|
194
184
|
function getRanking(spread) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
185
|
+
const spreadPercentage = 1 / spread;
|
|
186
|
+
const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
|
|
187
|
+
const ranking = RANKING_MATCHES + inOrderPercentage * spreadPercentage;
|
|
198
188
|
return ranking;
|
|
199
189
|
}
|
|
200
|
-
|
|
190
|
+
const firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
|
|
201
191
|
if (firstIndex < 0) {
|
|
202
192
|
return RANKING_NO_MATCH;
|
|
203
193
|
}
|
|
204
194
|
charNumber = firstIndex;
|
|
205
|
-
for
|
|
206
|
-
|
|
195
|
+
for(let i = 1, I = stringToRank.length; i < I; i++){
|
|
196
|
+
const matchChar = stringToRank[i];
|
|
207
197
|
charNumber = findMatchingCharacter(matchChar, testString, charNumber);
|
|
208
|
-
|
|
198
|
+
const found = charNumber > -1;
|
|
209
199
|
if (!found) {
|
|
210
200
|
return RANKING_NO_MATCH;
|
|
211
201
|
}
|
|
212
202
|
}
|
|
213
|
-
|
|
203
|
+
const spread = charNumber - firstIndex;
|
|
214
204
|
return getRanking(spread);
|
|
215
205
|
}
|
|
216
206
|
/**
|
|
@@ -218,23 +208,20 @@ function getClosenessRanking(testString, stringToRank) {
|
|
|
218
208
|
* @param {Object} a - the first item to sort
|
|
219
209
|
* @param {Object} b - the second item to sort
|
|
220
210
|
* @return {Number} -1 if a should come first, 1 if b should come first, 0 if equal
|
|
221
|
-
*/
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
var same = aRank === bRank;
|
|
211
|
+
*/ function sortRankedValues(a, b, baseSort) {
|
|
212
|
+
const aFirst = -1;
|
|
213
|
+
const bFirst = 1;
|
|
214
|
+
const { rank: aRank, keyIndex: aKeyIndex } = a;
|
|
215
|
+
const { rank: bRank, keyIndex: bKeyIndex } = b;
|
|
216
|
+
const same = aRank === bRank;
|
|
228
217
|
if (same) {
|
|
229
218
|
if (aKeyIndex === bKeyIndex) {
|
|
230
219
|
// use the base sort function as a tie-breaker
|
|
231
220
|
return baseSort(a, b);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
221
|
+
} else {
|
|
234
222
|
return aKeyIndex < bKeyIndex ? aFirst : bFirst;
|
|
235
223
|
}
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
224
|
+
} else {
|
|
238
225
|
return aRank > bRank ? aFirst : bFirst;
|
|
239
226
|
}
|
|
240
227
|
}
|
|
@@ -243,12 +230,10 @@ function sortRankedValues(a, b, baseSort) {
|
|
|
243
230
|
* @param {String} value - the value to clean
|
|
244
231
|
* @param {Object} options - {keepDiacritics: whether to remove diacritics}
|
|
245
232
|
* @return {String} the prepared value
|
|
246
|
-
*/
|
|
247
|
-
function prepareValueForComparison(value, _a) {
|
|
248
|
-
var keepDiacritics = _a.keepDiacritics;
|
|
233
|
+
*/ function prepareValueForComparison(value, { keepDiacritics }) {
|
|
249
234
|
// value might not actually be a string at this point (we don't get to choose)
|
|
250
235
|
// so part of preparing the value for comparison is ensure that it is a string
|
|
251
|
-
value =
|
|
236
|
+
value = `${value}`; // toString
|
|
252
237
|
if (!keepDiacritics) {
|
|
253
238
|
value = removeAccents(value);
|
|
254
239
|
}
|
|
@@ -259,26 +244,21 @@ function prepareValueForComparison(value, _a) {
|
|
|
259
244
|
* @param {Object} item - the item
|
|
260
245
|
* @param {Object|Function} key - the potentially nested keypath or property callback
|
|
261
246
|
* @return {Array} - an array containing the value(s) at the nested keypath
|
|
262
|
-
*/
|
|
263
|
-
function getItemValues(item, key) {
|
|
247
|
+
*/ function getItemValues(item, key) {
|
|
264
248
|
if (typeof key === "object") {
|
|
265
249
|
key = key.key;
|
|
266
250
|
}
|
|
267
|
-
|
|
251
|
+
let value;
|
|
268
252
|
if (typeof key === "function") {
|
|
269
253
|
value = key(item);
|
|
270
|
-
}
|
|
271
|
-
else if (item == null) {
|
|
254
|
+
} else if (item == null) {
|
|
272
255
|
value = null;
|
|
273
|
-
}
|
|
274
|
-
else if (Object.hasOwnProperty.call(item, key)) {
|
|
256
|
+
} else if (Object.hasOwnProperty.call(item, key)) {
|
|
275
257
|
value = item[key];
|
|
276
|
-
}
|
|
277
|
-
else if (key.includes(".")) {
|
|
258
|
+
} else if (key.includes(".")) {
|
|
278
259
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
279
260
|
return getNestedValues(key, item);
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
261
|
+
} else {
|
|
282
262
|
value = null;
|
|
283
263
|
}
|
|
284
264
|
// because `value` can also be undefined
|
|
@@ -288,7 +268,9 @@ function getItemValues(item, key) {
|
|
|
288
268
|
if (Array.isArray(value)) {
|
|
289
269
|
return value;
|
|
290
270
|
}
|
|
291
|
-
return [
|
|
271
|
+
return [
|
|
272
|
+
String(value)
|
|
273
|
+
];
|
|
292
274
|
}
|
|
293
275
|
/**
|
|
294
276
|
* Given path: "foo.bar.baz"
|
|
@@ -296,24 +278,23 @@ function getItemValues(item, key) {
|
|
|
296
278
|
* -> 'buzz'
|
|
297
279
|
* @param path a dot-separated set of keys
|
|
298
280
|
* @param item the item to get the value from
|
|
299
|
-
*/
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
281
|
+
*/ function getNestedValues(path, item) {
|
|
282
|
+
const keys = path.split(".");
|
|
283
|
+
let values = [
|
|
284
|
+
item
|
|
285
|
+
];
|
|
286
|
+
for(let i = 0, I = keys.length; i < I; i++){
|
|
287
|
+
const nestedKey = keys[i];
|
|
288
|
+
let nestedValues = [];
|
|
289
|
+
for(let j = 0, J = values.length; j < J; j++){
|
|
290
|
+
const nestedItem = values[j];
|
|
291
|
+
if (nestedItem == null) continue;
|
|
310
292
|
if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
|
|
311
|
-
|
|
293
|
+
const nestedValue = nestedItem[nestedKey];
|
|
312
294
|
if (nestedValue != null) {
|
|
313
295
|
nestedValues.push(nestedValue);
|
|
314
296
|
}
|
|
315
|
-
}
|
|
316
|
-
else if (nestedKey === "*") {
|
|
297
|
+
} else if (nestedKey === "*") {
|
|
317
298
|
// ensure that values is an array
|
|
318
299
|
nestedValues = nestedValues.concat(nestedItem);
|
|
319
300
|
}
|
|
@@ -323,8 +304,8 @@ function getNestedValues(path, item) {
|
|
|
323
304
|
if (Array.isArray(values[0])) {
|
|
324
305
|
// keep allowing the implicit wildcard for an array of strings at the end of
|
|
325
306
|
// the path; don't use `.flat()` because that's not available in node.js v10
|
|
326
|
-
|
|
327
|
-
return result.concat
|
|
307
|
+
const result = [];
|
|
308
|
+
return result.concat(...values);
|
|
328
309
|
}
|
|
329
310
|
// Based on our logic it should be an array of strings by now...
|
|
330
311
|
// assuming the user's path terminated in strings
|
|
@@ -335,36 +316,37 @@ function getNestedValues(path, item) {
|
|
|
335
316
|
* @param item - the item from which the values will be retrieved
|
|
336
317
|
* @param keys - the keys to use to retrieve the values
|
|
337
318
|
* @return objects with {itemValue, attributes}
|
|
338
|
-
*/
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
for (var i = 0, I = itemValues.length; i < I; i++) {
|
|
319
|
+
*/ function getAllValuesToRank(item, keys) {
|
|
320
|
+
const allValues = [];
|
|
321
|
+
for(let j = 0, J = keys.length; j < J; j++){
|
|
322
|
+
const key = keys[j];
|
|
323
|
+
const attributes = getKeyAttributes(key);
|
|
324
|
+
const itemValues = getItemValues(item, key);
|
|
325
|
+
for(let i = 0, I = itemValues.length; i < I; i++){
|
|
346
326
|
allValues.push({
|
|
347
327
|
itemValue: itemValues[i],
|
|
348
|
-
attributes
|
|
328
|
+
attributes
|
|
349
329
|
});
|
|
350
330
|
}
|
|
351
331
|
}
|
|
352
332
|
return allValues;
|
|
353
333
|
}
|
|
354
|
-
|
|
334
|
+
const defaultKeyAttributes = {
|
|
355
335
|
maxRanking: Infinity,
|
|
356
|
-
minRanking: -Infinity
|
|
336
|
+
minRanking: -Infinity
|
|
357
337
|
};
|
|
358
338
|
/**
|
|
359
339
|
* Gets all the attributes for the given key
|
|
360
340
|
* @param key - the key from which the attributes will be retrieved
|
|
361
341
|
* @return object containing the key's attributes
|
|
362
|
-
*/
|
|
363
|
-
function getKeyAttributes(key) {
|
|
342
|
+
*/ function getKeyAttributes(key) {
|
|
364
343
|
if (typeof key === "string") {
|
|
365
344
|
return defaultKeyAttributes;
|
|
366
345
|
}
|
|
367
|
-
return
|
|
346
|
+
return {
|
|
347
|
+
...defaultKeyAttributes,
|
|
348
|
+
...key
|
|
349
|
+
};
|
|
368
350
|
}
|
|
369
351
|
export { matchSorter, defaultBaseSortFn };
|
|
370
352
|
export default matchSorter;
|
package/mbToBytes.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mbToBytes = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Megabytes to bytes
|
|
6
3
|
*
|
|
7
4
|
* @category format
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
function _export(target, all) {
|
|
10
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: all[name]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
_export(exports, {
|
|
16
|
+
mbToBytes: function() {
|
|
17
|
+
return mbToBytes;
|
|
18
|
+
},
|
|
19
|
+
default: function() {
|
|
20
|
+
return _default;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const mbToBytes = (bytes)=>bytes * 1000 * 1000;
|
|
24
|
+
const _default = mbToBytes;
|
package/mbToBytes.mjs
CHANGED
package/mergeObjects.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @category objects
|
|
5
5
|
* @see https://stackoverflow.com/a/46973278/1938970
|
|
6
6
|
*/
|
|
7
|
-
export declare const mergeObjects: <T extends object = object>(target: T, ...sources: T[]) => T;
|
|
7
|
+
export declare const mergeObjects: <T extends object = object>(target: T, ...sources: Partial<T>[]) => T;
|
package/mergeObjects.js
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @category objects
|
|
10
|
-
* @see https://stackoverflow.com/a/46973278/1938970
|
|
11
|
-
*/
|
|
12
|
-
var mergeObjects = function (target) {
|
|
13
|
-
var sources = [];
|
|
14
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
15
|
-
sources[_i - 1] = arguments[_i];
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "mergeObjects", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return mergeObjects;
|
|
16
9
|
}
|
|
10
|
+
});
|
|
11
|
+
const _isObject = require("./isObject");
|
|
12
|
+
const _isUndefined = require("./isUndefined");
|
|
13
|
+
const mergeObjects = (target, ...sources)=>{
|
|
17
14
|
if (!sources.length) {
|
|
18
15
|
return target;
|
|
19
16
|
}
|
|
20
|
-
|
|
17
|
+
const source = sources.shift();
|
|
21
18
|
if (source === undefined) {
|
|
22
19
|
return target;
|
|
23
20
|
}
|
|
24
|
-
if ((0,
|
|
25
|
-
Object.keys(source).forEach(
|
|
26
|
-
|
|
27
|
-
if ((0,
|
|
21
|
+
if ((0, _isObject.isObject)(target) && (0, _isObject.isObject)(source)) {
|
|
22
|
+
Object.keys(source).forEach((_key)=>{
|
|
23
|
+
const key = _key;
|
|
24
|
+
if ((0, _isObject.isObject)(source[key])) {
|
|
28
25
|
if (!target[key]) {
|
|
29
|
-
// @ts-expect-error FIXME: ...
|
|
30
26
|
target[key] = {};
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
mergeObjects(target[key], source[key]);
|
|
29
|
+
} else {
|
|
30
|
+
if (!(0, _isUndefined.isUndefined)(source[key])) {
|
|
31
|
+
// FIXME: assertion here should not be needed but isUndefined does not
|
|
32
|
+
// seem to narrow the type correctly for some reason
|
|
33
|
+
target[key] = source[key];
|
|
34
|
+
}
|
|
36
35
|
}
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
|
-
return
|
|
38
|
+
return mergeObjects(target, ...sources);
|
|
40
39
|
};
|
|
41
|
-
exports.mergeObjects = mergeObjects;
|
package/mergeObjects.mjs
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
|
-
import { __spreadArray } from "tslib";
|
|
2
1
|
import { isObject } from "./isObject";
|
|
2
|
+
import { isUndefined } from "./isUndefined";
|
|
3
3
|
/**
|
|
4
4
|
* Merge two or more objects together. It mutates the target object.
|
|
5
5
|
*
|
|
6
6
|
* @category objects
|
|
7
7
|
* @see https://stackoverflow.com/a/46973278/1938970
|
|
8
|
-
*/
|
|
9
|
-
export var mergeObjects = function (target) {
|
|
10
|
-
var sources = [];
|
|
11
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
12
|
-
sources[_i - 1] = arguments[_i];
|
|
13
|
-
}
|
|
8
|
+
*/ export const mergeObjects = (target, ...sources)=>{
|
|
14
9
|
if (!sources.length) {
|
|
15
10
|
return target;
|
|
16
11
|
}
|
|
17
|
-
|
|
12
|
+
const source = sources.shift();
|
|
18
13
|
if (source === undefined) {
|
|
19
14
|
return target;
|
|
20
15
|
}
|
|
21
16
|
if (isObject(target) && isObject(source)) {
|
|
22
|
-
Object.keys(source).forEach(
|
|
23
|
-
|
|
17
|
+
Object.keys(source).forEach((_key)=>{
|
|
18
|
+
const key = _key;
|
|
24
19
|
if (isObject(source[key])) {
|
|
25
20
|
if (!target[key]) {
|
|
26
|
-
// @ts-expect-error FIXME: ...
|
|
27
21
|
target[key] = {};
|
|
28
22
|
}
|
|
29
23
|
mergeObjects(target[key], source[key]);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
} else {
|
|
25
|
+
if (!isUndefined(source[key])) {
|
|
26
|
+
// FIXME: assertion here should not be needed but isUndefined does not
|
|
27
|
+
// seem to narrow the type correctly for some reason
|
|
28
|
+
target[key] = source[key];
|
|
29
|
+
}
|
|
33
30
|
}
|
|
34
31
|
});
|
|
35
32
|
}
|
|
36
|
-
return mergeObjects
|
|
33
|
+
return mergeObjects(target, ...sources);
|
|
37
34
|
};
|
package/mergeUrlQueryParams.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
mergeUrlQueryParams: function() {
|
|
13
|
+
return mergeUrlQueryParams;
|
|
14
|
+
},
|
|
15
|
+
default: function() {
|
|
16
|
+
return _default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
+
const _isNull = /*#__PURE__*/ _interop_require_default._(require("./isNull"));
|
|
21
|
+
function mergeUrlQueryParams(oldParams = {}, newParams = {}) {
|
|
22
|
+
for(const key in newParams){
|
|
23
|
+
const value = newParams[key];
|
|
24
|
+
if (oldParams[key] && (0, _isNull.default)(value)) {
|
|
18
25
|
delete oldParams[key];
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
26
|
+
} else {
|
|
21
27
|
oldParams[key] = value;
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
return oldParams;
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
exports.default = mergeUrlQueryParams;
|
|
32
|
+
const _default = mergeUrlQueryParams;
|
package/mergeUrlQueryParams.mjs
CHANGED
|
@@ -4,16 +4,12 @@ import isNull from "./isNull";
|
|
|
4
4
|
*
|
|
5
5
|
* @category location
|
|
6
6
|
* @pure
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (newParams === void 0) { newParams = {}; }
|
|
11
|
-
for (var key in newParams) {
|
|
12
|
-
var value = newParams[key];
|
|
7
|
+
*/ export function mergeUrlQueryParams(oldParams = {}, newParams = {}) {
|
|
8
|
+
for(const key in newParams){
|
|
9
|
+
const value = newParams[key];
|
|
13
10
|
if (oldParams[key] && isNull(value)) {
|
|
14
11
|
delete oldParams[key];
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
12
|
+
} else {
|
|
17
13
|
oldParams[key] = value;
|
|
18
14
|
}
|
|
19
15
|
}
|