@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.
Files changed (283) hide show
  1. package/Defer.js +23 -18
  2. package/Defer.mjs +6 -5
  3. package/Emitter.js +31 -20
  4. package/Emitter.mjs +13 -16
  5. package/README.md +5 -1
  6. package/accentSets.js +129 -37
  7. package/accentSets.mjs +113 -29
  8. package/addOrReplaceAtIdx.js +27 -10
  9. package/addOrReplaceAtIdx.mjs +9 -6
  10. package/areEqual.js +35 -41
  11. package/areEqual.mjs +16 -22
  12. package/arrayOfAll.js +20 -11
  13. package/arrayOfAll.mjs +1 -6
  14. package/arraySum.js +20 -9
  15. package/arraySum.mjs +1 -4
  16. package/arrayToLookup.js +21 -9
  17. package/arrayToLookup.mjs +2 -4
  18. package/buildUrlQueryString.js +32 -29
  19. package/buildUrlQueryString.mjs +11 -14
  20. package/capitalize.js +21 -9
  21. package/capitalize.mjs +3 -5
  22. package/changeUrlPath.js +23 -17
  23. package/changeUrlPath.mjs +2 -3
  24. package/chunkByChunks.js +35 -24
  25. package/chunkByChunks.mjs +17 -20
  26. package/chunkBySize.js +21 -8
  27. package/chunkBySize.mjs +3 -4
  28. package/clamp.js +19 -6
  29. package/clamp.mjs +1 -2
  30. package/clsx.js +29 -23
  31. package/clsx.mjs +11 -14
  32. package/convertRange.js +20 -7
  33. package/convertRange.mjs +2 -3
  34. package/cookie.js +13 -5
  35. package/cookie.mjs +3 -2
  36. package/createPalette.js +27 -19
  37. package/createPalette.mjs +9 -6
  38. package/debounce.js +27 -21
  39. package/debounce.mjs +9 -17
  40. package/debouncePromise.js +20 -11
  41. package/debouncePromise.mjs +1 -2
  42. package/debounceRaf.js +23 -14
  43. package/debounceRaf.mjs +5 -10
  44. package/decode.js +20 -7
  45. package/decode.mjs +2 -3
  46. package/encode.js +20 -7
  47. package/encode.mjs +2 -3
  48. package/ensureInt.js +20 -9
  49. package/ensureInt.mjs +1 -4
  50. package/env.js +1 -1
  51. package/env.mjs +0 -1
  52. package/errorToString.js +21 -14
  53. package/errorToString.mjs +1 -4
  54. package/findDuplicatedIndexes.js +22 -9
  55. package/findDuplicatedIndexes.mjs +4 -5
  56. package/forin.js +20 -7
  57. package/forin.mjs +2 -3
  58. package/gbToBytes.js +20 -7
  59. package/gbToBytes.mjs +1 -2
  60. package/getEmptyArray.js +25 -16
  61. package/getEmptyArray.mjs +4 -3
  62. package/getKeys.js +20 -6
  63. package/getKeys.mjs +1 -2
  64. package/getMediaQueryWidthResolvers.js +62 -53
  65. package/getMediaQueryWidthResolvers.mjs +44 -49
  66. package/getMediaQueryWidthTailwindScreens.js +36 -18
  67. package/getMediaQueryWidthTailwindScreens.mjs +18 -14
  68. package/getNonce.js +20 -10
  69. package/getNonce.mjs +1 -2
  70. package/getParamAmong.js +22 -19
  71. package/getParamAmong.mjs +2 -4
  72. package/getParamAsInt.js +22 -19
  73. package/getParamAsInt.mjs +2 -4
  74. package/getParamAsString.js +21 -16
  75. package/getParamAsString.mjs +1 -2
  76. package/getType.js +19 -12
  77. package/getType.mjs +2 -4
  78. package/getUrlHashParams.js +20 -13
  79. package/getUrlHashParams.mjs +2 -4
  80. package/getUrlHashPathname.js +20 -8
  81. package/getUrlHashPathname.mjs +1 -3
  82. package/getUrlPathnameParts.js +23 -23
  83. package/getUrlPathnameParts.mjs +2 -7
  84. package/getUrlQueryParams.js +26 -33
  85. package/getUrlQueryParams.mjs +7 -18
  86. package/imgEmptyPixel.js +20 -6
  87. package/imgEmptyPixel.mjs +1 -2
  88. package/index.js +531 -266
  89. package/index.mjs +2 -2
  90. package/invariant.js +24 -12
  91. package/invariant.mjs +6 -8
  92. package/isAnyObject.js +21 -12
  93. package/isAnyObject.mjs +1 -2
  94. package/isArray.js +21 -12
  95. package/isArray.mjs +1 -2
  96. package/isBlob.js +21 -12
  97. package/isBlob.mjs +1 -2
  98. package/isBoolean.js +21 -12
  99. package/isBoolean.mjs +1 -2
  100. package/isBrowser.js +20 -6
  101. package/isBrowser.mjs +1 -2
  102. package/isBrowserNow.js +21 -11
  103. package/isBrowserNow.mjs +1 -2
  104. package/isDate.js +21 -12
  105. package/isDate.mjs +1 -2
  106. package/isEmptyArray.js +21 -12
  107. package/isEmptyArray.mjs +1 -2
  108. package/isEmptyObject.js +21 -12
  109. package/isEmptyObject.mjs +1 -2
  110. package/isEmptyString.js +19 -6
  111. package/isEmptyString.mjs +1 -2
  112. package/isError.js +21 -12
  113. package/isError.mjs +1 -2
  114. package/isExternalUrl.js +24 -18
  115. package/isExternalUrl.mjs +4 -6
  116. package/isFile.js +21 -12
  117. package/isFile.mjs +1 -2
  118. package/isFloat.js +21 -12
  119. package/isFloat.mjs +1 -2
  120. package/isFormData.js +21 -12
  121. package/isFormData.mjs +1 -2
  122. package/isFullArray.js +21 -12
  123. package/isFullArray.mjs +1 -2
  124. package/isFullObject.js +21 -12
  125. package/isFullObject.mjs +1 -2
  126. package/isFullString.js +21 -12
  127. package/isFullString.mjs +1 -2
  128. package/isFunction.js +18 -9
  129. package/isFunction.mjs +1 -2
  130. package/isInt.js +21 -12
  131. package/isInt.mjs +1 -2
  132. package/isMap.js +21 -12
  133. package/isMap.mjs +1 -2
  134. package/isNaNValue.js +21 -12
  135. package/isNaNValue.mjs +1 -2
  136. package/isNegativeNumber.js +21 -12
  137. package/isNegativeNumber.mjs +1 -2
  138. package/isNull.js +21 -12
  139. package/isNull.mjs +1 -2
  140. package/isNullOrUndefined.js +23 -13
  141. package/isNullOrUndefined.mjs +1 -2
  142. package/isNumber.js +21 -14
  143. package/isNumber.mjs +1 -2
  144. package/isObject.js +21 -12
  145. package/isObject.mjs +1 -2
  146. package/isObjectLike.js +21 -14
  147. package/isObjectLike.mjs +1 -2
  148. package/isOneOf.js +19 -11
  149. package/isOneOf.mjs +1 -7
  150. package/isPlainObject.js +22 -15
  151. package/isPlainObject.mjs +3 -6
  152. package/isPositiveNumber.js +21 -12
  153. package/isPositiveNumber.mjs +1 -2
  154. package/isPrimitive.js +26 -22
  155. package/isPrimitive.mjs +5 -11
  156. package/isPromise.js +21 -12
  157. package/isPromise.mjs +1 -2
  158. package/isRegExp.js +21 -12
  159. package/isRegExp.mjs +1 -2
  160. package/isServer.js +22 -11
  161. package/isServer.mjs +1 -2
  162. package/isServerNow.js +21 -11
  163. package/isServerNow.mjs +1 -2
  164. package/isSet.js +21 -12
  165. package/isSet.mjs +1 -2
  166. package/isString.js +21 -12
  167. package/isString.mjs +1 -2
  168. package/isSymbol.js +21 -12
  169. package/isSymbol.mjs +1 -2
  170. package/isType.js +22 -17
  171. package/isType.mjs +3 -5
  172. package/isUndefined.js +21 -12
  173. package/isUndefined.mjs +1 -2
  174. package/isWeakMap.js +21 -12
  175. package/isWeakMap.mjs +1 -2
  176. package/isWeakSet.js +21 -12
  177. package/isWeakSet.mjs +1 -2
  178. package/kbToBytes.js +20 -7
  179. package/kbToBytes.mjs +1 -2
  180. package/location.js +6 -2
  181. package/location.mjs +3 -1
  182. package/lowercase.js +20 -9
  183. package/lowercase.mjs +1 -4
  184. package/mapListBy.js +21 -10
  185. package/mapListBy.mjs +2 -5
  186. package/matchSorter.js +132 -133
  187. package/matchSorter.mjs +108 -126
  188. package/mbToBytes.js +20 -7
  189. package/mbToBytes.mjs +1 -2
  190. package/mergeObjects.d.ts +1 -1
  191. package/mergeObjects.js +24 -26
  192. package/mergeObjects.mjs +12 -15
  193. package/mergeUrlQueryParams.js +25 -20
  194. package/mergeUrlQueryParams.mjs +4 -8
  195. package/moveSortableArrayItemByKey.js +26 -12
  196. package/moveSortableArrayItemByKey.mjs +8 -8
  197. package/noop.js +20 -7
  198. package/noop.mjs +1 -2
  199. package/normaliseUrl.js +22 -18
  200. package/normaliseUrl.mjs +1 -3
  201. package/normaliseUrlPathname.js +22 -17
  202. package/normaliseUrlPathname.mjs +1 -3
  203. package/objectOmit.js +21 -9
  204. package/objectOmit.mjs +3 -5
  205. package/objectPick.js +22 -9
  206. package/objectPick.mjs +4 -5
  207. package/package.json +11 -8
  208. package/parseCookie.js +29 -26
  209. package/parseCookie.mjs +11 -15
  210. package/parseURL.js +23 -10
  211. package/parseURL.mjs +5 -6
  212. package/quaranteneProps.js +24 -12
  213. package/quaranteneProps.mjs +6 -8
  214. package/randomInt.js +19 -6
  215. package/randomInt.mjs +1 -2
  216. package/randomKey.js +21 -8
  217. package/randomKey.mjs +3 -4
  218. package/readCookie.js +25 -12
  219. package/readCookie.mjs +7 -8
  220. package/removeAccents.js +24 -15
  221. package/removeAccents.mjs +5 -8
  222. package/removeCookie.js +26 -17
  223. package/removeCookie.mjs +6 -5
  224. package/removeDuplicates.js +1 -1
  225. package/removeDuplicates.mjs +0 -1
  226. package/removeDuplicatesByKey.js +24 -12
  227. package/removeDuplicatesByKey.mjs +5 -7
  228. package/removeDuplicatesComparing.js +22 -11
  229. package/removeDuplicatesComparing.mjs +3 -4
  230. package/removeIndexesFromArray.js +21 -8
  231. package/removeIndexesFromArray.mjs +3 -4
  232. package/removeTrailingSlash.js +20 -8
  233. package/removeTrailingSlash.mjs +1 -3
  234. package/removeUrlQueryParams.js +27 -20
  235. package/removeUrlQueryParams.mjs +5 -7
  236. package/render.js +61 -137
  237. package/render.mjs +43 -98
  238. package/roundTo.js +34 -22
  239. package/roundTo.mjs +15 -17
  240. package/serializeCookie.js +29 -35
  241. package/serializeCookie.mjs +9 -15
  242. package/setCookie.js +37 -31
  243. package/setCookie.mjs +13 -16
  244. package/shuffle.js +28 -14
  245. package/shuffle.mjs +10 -10
  246. package/slugify.js +33 -25
  247. package/slugify.mjs +13 -11
  248. package/split.js +18 -4
  249. package/swapMap.js +22 -10
  250. package/swapMap.mjs +3 -5
  251. package/throttle.d.ts +1 -0
  252. package/throttle.js +23 -15
  253. package/throttle.mjs +5 -11
  254. package/titleCase.js +20 -11
  255. package/titleCase.mjs +1 -6
  256. package/toNumber.js +20 -9
  257. package/toNumber.mjs +1 -2
  258. package/toRgba.js +22 -10
  259. package/toRgba.mjs +3 -5
  260. package/transformToUrlPathname.js +21 -18
  261. package/transformToUrlPathname.mjs +2 -5
  262. package/truncate.js +20 -13
  263. package/truncate.mjs +1 -8
  264. package/tryUntil.js +26 -15
  265. package/tryUntil.mjs +7 -10
  266. package/types.js +4 -1
  267. package/types.mjs +2 -1
  268. package/uid.js +21 -13
  269. package/uid.mjs +3 -5
  270. package/updateLinkParams.js +21 -14
  271. package/updateLinkParams.mjs +2 -3
  272. package/updateUrlQueryParams.js +26 -21
  273. package/updateUrlQueryParams.mjs +3 -7
  274. package/uppercase.js +20 -9
  275. package/uppercase.mjs +1 -4
  276. package/uuid.js +21 -10
  277. package/uuid.mjs +2 -5
  278. package/uuidNumeric.js +20 -7
  279. package/uuidNumeric.mjs +1 -2
  280. package/wait.js +20 -9
  281. package/wait.mjs +1 -4
  282. package/without.js +2 -3
  283. 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
- import removeAccents from "./removeAccents";
19
- var RANKING_CASE_SENSITIVE_EQUAL = 7;
20
- var RANKING_EQUAL = 6;
21
- var RANKING_STARTS_WITH = 5;
22
- var RANKING_WORD_STARTS_WITH = 4;
23
- var RANKING_CONTAINS = 3;
24
- var RANKING_ACRONYM = 2;
25
- var RANKING_MATCHES = 1;
26
- var RANKING_NO_MATCH = 0;
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
- function matchSorter(items, value, options) {
38
- if (options === void 0) { options = {}; }
39
- var keys = options.keys, _a = options.threshold, threshold = _a === void 0 ? RANKING_MATCHES : _a, _b = options.baseSort, baseSort = _b === void 0 ? defaultBaseSortFn : _b, _c = options.sorter, sorter = _c === void 0 ? function (matchedItems) {
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
- var rankingInfo = getHighestRanking(item, keys, value, options);
49
- var rank = rankingInfo.rank, _a = rankingInfo.keyThreshold, keyThreshold = _a === void 0 ? threshold : _a;
37
+ const rankingInfo = getHighestRanking(item, keys, value, options);
38
+ const { rank, keyThreshold = threshold } = rankingInfo;
50
39
  if (rank >= keyThreshold) {
51
- matches.push(__assign(__assign({}, rankingInfo), { item: item, index: index }));
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
- var stringItem = item;
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
- var valuesToRank = getAllValuesToRank(item, keys);
77
- return valuesToRank.reduce(function (_a, _b, i) {
78
- var rank = _a.rank, rankedValue = _a.rankedValue, keyIndex = _a.keyIndex, keyThreshold = _a.keyThreshold;
79
- var itemValue = _b.itemValue, attributes = _b.attributes;
80
- var newRank = getMatchRanking(itemValue, value, options);
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 { rankedValue: newRankedValue, rank: rank, keyIndex: keyIndex, keyThreshold: keyThreshold };
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(" ".concat(stringToRank))) {
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
- function getAcronym(string) {
161
- var acronym = "";
162
- var wordsInString = string.split(" ");
163
- wordsInString.forEach(function (wordInString) {
164
- var splitByHyphenWords = wordInString.split("-");
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
- function getClosenessRanking(testString, stringToRank) {
182
- var matchingInOrderCharCount = 0;
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 (var j = index, J = string.length; j < J; j++) {
186
- var stringChar = string[j];
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
- var spreadPercentage = 1 / spread;
196
- var inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
197
- var ranking = RANKING_MATCHES + inOrderPercentage * spreadPercentage;
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
- var firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
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 (var i = 1, I = stringToRank.length; i < I; i++) {
206
- var matchChar = stringToRank[i];
195
+ for(let i = 1, I = stringToRank.length; i < I; i++){
196
+ const matchChar = stringToRank[i];
207
197
  charNumber = findMatchingCharacter(matchChar, testString, charNumber);
208
- var found = charNumber > -1;
198
+ const found = charNumber > -1;
209
199
  if (!found) {
210
200
  return RANKING_NO_MATCH;
211
201
  }
212
202
  }
213
- var spread = charNumber - firstIndex;
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
- function sortRankedValues(a, b, baseSort) {
223
- var aFirst = -1;
224
- var bFirst = 1;
225
- var aRank = a.rank, aKeyIndex = a.keyIndex;
226
- var bRank = b.rank, bKeyIndex = b.keyIndex;
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 = "".concat(value); // toString
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
- var value;
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 [String(value)];
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
- function getNestedValues(path, item) {
301
- var keys = path.split(".");
302
- var values = [item];
303
- for (var i = 0, I = keys.length; i < I; i++) {
304
- var nestedKey = keys[i];
305
- var nestedValues = [];
306
- for (var j = 0, J = values.length; j < J; j++) {
307
- var nestedItem = values[j];
308
- if (nestedItem == null)
309
- continue;
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
- var nestedValue = nestedItem[nestedKey];
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
- var result = [];
327
- return result.concat.apply(result, values);
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
- function getAllValuesToRank(item, keys) {
340
- var allValues = [];
341
- for (var j = 0, J = keys.length; j < J; j++) {
342
- var key = keys[j];
343
- var attributes = getKeyAttributes(key);
344
- var itemValues = getItemValues(item, key);
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: attributes,
328
+ attributes
349
329
  });
350
330
  }
351
331
  }
352
332
  return allValues;
353
333
  }
354
- var defaultKeyAttributes = {
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 __assign(__assign({}, defaultKeyAttributes), key);
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
- var mbToBytes = function (bytes) { return bytes * 1000 * 1000; };
10
- exports.mbToBytes = mbToBytes;
11
- exports.default = exports.mbToBytes;
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
@@ -2,6 +2,5 @@
2
2
  * Megabytes to bytes
3
3
  *
4
4
  * @category format
5
- */
6
- export var mbToBytes = function (bytes) { return bytes * 1000 * 1000; };
5
+ */ export const mbToBytes = (bytes)=>bytes * 1000 * 1000;
7
6
  export default mbToBytes;
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", { value: true });
3
- exports.mergeObjects = void 0;
4
- var tslib_1 = require("tslib");
5
- var isObject_1 = require("./isObject");
6
- /**
7
- * Merge two or more objects together. It mutates the target object.
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
- var source = sources.shift();
17
+ const source = sources.shift();
21
18
  if (source === undefined) {
22
19
  return target;
23
20
  }
24
- if ((0, isObject_1.isObject)(target) && (0, isObject_1.isObject)(source)) {
25
- Object.keys(source).forEach(function (_key) {
26
- var key = _key;
27
- if ((0, isObject_1.isObject)(source[key])) {
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
- (0, exports.mergeObjects)(target[key], source[key]);
33
- }
34
- else {
35
- target[key] = source[key];
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 exports.mergeObjects.apply(void 0, tslib_1.__spreadArray([target], sources, false));
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
- var source = sources.shift();
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(function (_key) {
23
- var key = _key;
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
- else {
32
- target[key] = source[key];
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.apply(void 0, __spreadArray([target], sources, false));
33
+ return mergeObjects(target, ...sources);
37
34
  };
@@ -1,27 +1,32 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeUrlQueryParams = void 0;
4
- var tslib_1 = require("tslib");
5
- var isNull_1 = tslib_1.__importDefault(require("./isNull"));
6
- /**
7
- * Merge query parameters objects, it *mutates* the first given object argument
8
- *
9
- * @category location
10
- * @pure
11
- */
12
- function mergeUrlQueryParams(oldParams, newParams) {
13
- if (oldParams === void 0) { oldParams = {}; }
14
- if (newParams === void 0) { newParams = {}; }
15
- for (var key in newParams) {
16
- var value = newParams[key];
17
- if (oldParams[key] && (0, isNull_1.default)(value)) {
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
- exports.mergeUrlQueryParams = mergeUrlQueryParams;
27
- exports.default = mergeUrlQueryParams;
32
+ const _default = mergeUrlQueryParams;
@@ -4,16 +4,12 @@ import isNull from "./isNull";
4
4
  *
5
5
  * @category location
6
6
  * @pure
7
- */
8
- export function mergeUrlQueryParams(oldParams, newParams) {
9
- if (oldParams === void 0) { oldParams = {}; }
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
  }