@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.js CHANGED
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultBaseSortFn = exports.matchSorter = void 0;
4
- var tslib_1 = require("tslib");
5
1
  /**
6
2
  * @file
7
3
  *
@@ -17,47 +13,61 @@ var tslib_1 = require("tslib");
17
13
  * @license MIT license.
18
14
  * @copyright (c) 2020 Kent C. Dodds
19
15
  * @author Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)
20
- */
21
- var removeAccents_1 = tslib_1.__importDefault(require("./removeAccents"));
22
- var RANKING_CASE_SENSITIVE_EQUAL = 7;
23
- var RANKING_EQUAL = 6;
24
- var RANKING_STARTS_WITH = 5;
25
- var RANKING_WORD_STARTS_WITH = 4;
26
- var RANKING_CONTAINS = 3;
27
- var RANKING_ACRONYM = 2;
28
- var RANKING_MATCHES = 1;
29
- var RANKING_NO_MATCH = 0;
30
- var defaultBaseSortFn = function (a, b) {
31
- return String(a.rankedValue).localeCompare(String(b.rankedValue));
32
- };
33
- exports.defaultBaseSortFn = defaultBaseSortFn;
16
+ */ "use strict";
17
+ Object.defineProperty(exports, "__esModule", {
18
+ value: true
19
+ });
20
+ function _export(target, all) {
21
+ for(var name in all)Object.defineProperty(target, name, {
22
+ enumerable: true,
23
+ get: all[name]
24
+ });
25
+ }
26
+ _export(exports, {
27
+ matchSorter: function() {
28
+ return matchSorter;
29
+ },
30
+ defaultBaseSortFn: function() {
31
+ return defaultBaseSortFn;
32
+ },
33
+ default: function() {
34
+ return _default;
35
+ }
36
+ });
37
+ const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
38
+ const _removeAccents = /*#__PURE__*/ _interop_require_default._(require("./removeAccents"));
39
+ const RANKING_CASE_SENSITIVE_EQUAL = 7;
40
+ const RANKING_EQUAL = 6;
41
+ const RANKING_STARTS_WITH = 5;
42
+ const RANKING_WORD_STARTS_WITH = 4;
43
+ const RANKING_CONTAINS = 3;
44
+ const RANKING_ACRONYM = 2;
45
+ const RANKING_MATCHES = 1;
46
+ const RANKING_NO_MATCH = 0;
47
+ const defaultBaseSortFn = (a, b)=>String(a.rankedValue).localeCompare(String(b.rankedValue));
34
48
  /**
35
49
  * Takes an array of items and a value and returns a new array with the items that match the given value
36
50
  * @param {Array} items - the items to sort
37
51
  * @param {String} value - the value to use for ranking
38
52
  * @param {Object} options - Some options to configure the sorter
39
53
  * @return {Array} - the new sorted array
40
- */
41
- function matchSorter(items, value, options) {
42
- if (options === void 0) { options = {}; }
43
- 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) {
44
- return matchedItems.sort(function (a, b) { return sortRankedValues(a, b, baseSort); });
45
- } : _c;
46
- var matchedItems = items.reduce(reduceItemsToRanked, []);
47
- return sorter(matchedItems).map(function (_a) {
48
- var item = _a.item;
49
- return item;
50
- });
54
+ */ function matchSorter(items, value, options = {}) {
55
+ const { keys, threshold = RANKING_MATCHES, baseSort = defaultBaseSortFn, sorter = (matchedItems)=>matchedItems.sort((a, b)=>sortRankedValues(a, b, baseSort)) } = options;
56
+ const matchedItems = items.reduce(reduceItemsToRanked, []);
57
+ return sorter(matchedItems).map(({ item })=>item);
51
58
  function reduceItemsToRanked(matches, item, index) {
52
- var rankingInfo = getHighestRanking(item, keys, value, options);
53
- var rank = rankingInfo.rank, _a = rankingInfo.keyThreshold, keyThreshold = _a === void 0 ? threshold : _a;
59
+ const rankingInfo = getHighestRanking(item, keys, value, options);
60
+ const { rank, keyThreshold = threshold } = rankingInfo;
54
61
  if (rank >= keyThreshold) {
55
- matches.push(tslib_1.__assign(tslib_1.__assign({}, rankingInfo), { item: item, index: index }));
62
+ matches.push({
63
+ ...rankingInfo,
64
+ item,
65
+ index
66
+ });
56
67
  }
57
68
  return matches;
58
69
  }
59
70
  }
60
- exports.matchSorter = matchSorter;
61
71
  /**
62
72
  * Gets the highest ranking for value for the given item based on its values for the given keys
63
73
  * @param {*} item - the item to rank
@@ -65,30 +75,26 @@ exports.matchSorter = matchSorter;
65
75
  * @param {String} value - the value to rank against
66
76
  * @param {Object} options - options to control the ranking
67
77
  * @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking
68
- */
69
- function getHighestRanking(item, keys, value, options) {
78
+ */ function getHighestRanking(item, keys, value, options) {
70
79
  if (!keys) {
71
80
  // if keys is not specified, then we assume the item given is ready to be matched
72
- var stringItem = item;
81
+ const stringItem = item;
73
82
  return {
74
83
  // ends up being duplicate of 'item' in matches but consistent
75
84
  rankedValue: stringItem,
76
85
  rank: getMatchRanking(stringItem, value, options),
77
86
  keyIndex: -1,
78
- keyThreshold: options.threshold,
87
+ keyThreshold: options.threshold
79
88
  };
80
89
  }
81
- var valuesToRank = getAllValuesToRank(item, keys);
82
- return valuesToRank.reduce(function (_a, _b, i) {
83
- var rank = _a.rank, rankedValue = _a.rankedValue, keyIndex = _a.keyIndex, keyThreshold = _a.keyThreshold;
84
- var itemValue = _b.itemValue, attributes = _b.attributes;
85
- var newRank = getMatchRanking(itemValue, value, options);
86
- var newRankedValue = rankedValue;
87
- var minRanking = attributes.minRanking, maxRanking = attributes.maxRanking, threshold = attributes.threshold;
90
+ const valuesToRank = getAllValuesToRank(item, keys);
91
+ return valuesToRank.reduce(({ rank, rankedValue, keyIndex, keyThreshold }, { itemValue, attributes }, i)=>{
92
+ let newRank = getMatchRanking(itemValue, value, options);
93
+ let newRankedValue = rankedValue;
94
+ const { minRanking, maxRanking, threshold } = attributes;
88
95
  if (newRank < minRanking && newRank >= RANKING_MATCHES) {
89
96
  newRank = minRanking;
90
- }
91
- else if (newRank > maxRanking) {
97
+ } else if (newRank > maxRanking) {
92
98
  newRank = maxRanking;
93
99
  }
94
100
  if (newRank > rank) {
@@ -97,12 +103,17 @@ function getHighestRanking(item, keys, value, options) {
97
103
  keyThreshold = threshold;
98
104
  newRankedValue = itemValue;
99
105
  }
100
- return { rankedValue: newRankedValue, rank: rank, keyIndex: keyIndex, keyThreshold: keyThreshold };
106
+ return {
107
+ rankedValue: newRankedValue,
108
+ rank,
109
+ keyIndex,
110
+ keyThreshold
111
+ };
101
112
  }, {
102
113
  rankedValue: item,
103
114
  rank: RANKING_NO_MATCH,
104
115
  keyIndex: -1,
105
- keyThreshold: options.threshold,
116
+ keyThreshold: options.threshold
106
117
  });
107
118
  }
108
119
  /**
@@ -111,8 +122,7 @@ function getHighestRanking(item, keys, value, options) {
111
122
  * @param {String} stringToRank - the string to rank
112
123
  * @param {Object} options - options for the match (like keepDiacritics for comparison)
113
124
  * @returns {Number} the ranking for how well stringToRank matches testString
114
- */
115
- function getMatchRanking(testString, stringToRank, options) {
125
+ */ function getMatchRanking(testString, stringToRank, options) {
116
126
  testString = prepareValueForComparison(testString, options);
117
127
  stringToRank = prepareValueForComparison(stringToRank, options);
118
128
  // too long
@@ -135,14 +145,13 @@ function getMatchRanking(testString, stringToRank, options) {
135
145
  return RANKING_STARTS_WITH;
136
146
  }
137
147
  // word starts with
138
- if (testString.includes(" ".concat(stringToRank))) {
148
+ if (testString.includes(` ${stringToRank}`)) {
139
149
  return RANKING_WORD_STARTS_WITH;
140
150
  }
141
151
  // contains
142
152
  if (testString.includes(stringToRank)) {
143
153
  return RANKING_CONTAINS;
144
- }
145
- else if (stringToRank.length === 1) {
154
+ } else if (stringToRank.length === 1) {
146
155
  // If the only character in the given stringToRank
147
156
  // isn't even contained in the testString, then
148
157
  // it's definitely not a match.
@@ -161,13 +170,12 @@ function getMatchRanking(testString, stringToRank, options) {
161
170
  *
162
171
  * @param {String} string the string for which to produce the acronym
163
172
  * @returns {String} the acronym
164
- */
165
- function getAcronym(string) {
166
- var acronym = "";
167
- var wordsInString = string.split(" ");
168
- wordsInString.forEach(function (wordInString) {
169
- var splitByHyphenWords = wordInString.split("-");
170
- splitByHyphenWords.forEach(function (splitByHyphenWord) {
173
+ */ function getAcronym(string) {
174
+ let acronym = "";
175
+ const wordsInString = string.split(" ");
176
+ wordsInString.forEach((wordInString)=>{
177
+ const splitByHyphenWords = wordInString.split("-");
178
+ splitByHyphenWords.forEach((splitByHyphenWord)=>{
171
179
  acronym += splitByHyphenWord.substring(0, 1);
172
180
  });
173
181
  });
@@ -182,13 +190,12 @@ function getAcronym(string) {
182
190
  * @param {String} stringToRank - the string to rank
183
191
  * @returns {Number} the number between RANKING_MATCHES and
184
192
  * RANKING_MATCHES + 1 for how well stringToRank matches testString
185
- */
186
- function getClosenessRanking(testString, stringToRank) {
187
- var matchingInOrderCharCount = 0;
188
- var charNumber = 0;
193
+ */ function getClosenessRanking(testString, stringToRank) {
194
+ let matchingInOrderCharCount = 0;
195
+ let charNumber = 0;
189
196
  function findMatchingCharacter(matchChar, string, index) {
190
- for (var j = index, J = string.length; j < J; j++) {
191
- var stringChar = string[j];
197
+ for(let j = index, J = string.length; j < J; j++){
198
+ const stringChar = string[j];
192
199
  if (stringChar === matchChar) {
193
200
  matchingInOrderCharCount += 1;
194
201
  return j + 1;
@@ -197,25 +204,25 @@ function getClosenessRanking(testString, stringToRank) {
197
204
  return -1;
198
205
  }
199
206
  function getRanking(spread) {
200
- var spreadPercentage = 1 / spread;
201
- var inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
202
- var ranking = RANKING_MATCHES + inOrderPercentage * spreadPercentage;
207
+ const spreadPercentage = 1 / spread;
208
+ const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
209
+ const ranking = RANKING_MATCHES + inOrderPercentage * spreadPercentage;
203
210
  return ranking;
204
211
  }
205
- var firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
212
+ const firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
206
213
  if (firstIndex < 0) {
207
214
  return RANKING_NO_MATCH;
208
215
  }
209
216
  charNumber = firstIndex;
210
- for (var i = 1, I = stringToRank.length; i < I; i++) {
211
- var matchChar = stringToRank[i];
217
+ for(let i = 1, I = stringToRank.length; i < I; i++){
218
+ const matchChar = stringToRank[i];
212
219
  charNumber = findMatchingCharacter(matchChar, testString, charNumber);
213
- var found = charNumber > -1;
220
+ const found = charNumber > -1;
214
221
  if (!found) {
215
222
  return RANKING_NO_MATCH;
216
223
  }
217
224
  }
218
- var spread = charNumber - firstIndex;
225
+ const spread = charNumber - firstIndex;
219
226
  return getRanking(spread);
220
227
  }
221
228
  /**
@@ -223,23 +230,20 @@ function getClosenessRanking(testString, stringToRank) {
223
230
  * @param {Object} a - the first item to sort
224
231
  * @param {Object} b - the second item to sort
225
232
  * @return {Number} -1 if a should come first, 1 if b should come first, 0 if equal
226
- */
227
- function sortRankedValues(a, b, baseSort) {
228
- var aFirst = -1;
229
- var bFirst = 1;
230
- var aRank = a.rank, aKeyIndex = a.keyIndex;
231
- var bRank = b.rank, bKeyIndex = b.keyIndex;
232
- var same = aRank === bRank;
233
+ */ function sortRankedValues(a, b, baseSort) {
234
+ const aFirst = -1;
235
+ const bFirst = 1;
236
+ const { rank: aRank, keyIndex: aKeyIndex } = a;
237
+ const { rank: bRank, keyIndex: bKeyIndex } = b;
238
+ const same = aRank === bRank;
233
239
  if (same) {
234
240
  if (aKeyIndex === bKeyIndex) {
235
241
  // use the base sort function as a tie-breaker
236
242
  return baseSort(a, b);
237
- }
238
- else {
243
+ } else {
239
244
  return aKeyIndex < bKeyIndex ? aFirst : bFirst;
240
245
  }
241
- }
242
- else {
246
+ } else {
243
247
  return aRank > bRank ? aFirst : bFirst;
244
248
  }
245
249
  }
@@ -248,14 +252,12 @@ function sortRankedValues(a, b, baseSort) {
248
252
  * @param {String} value - the value to clean
249
253
  * @param {Object} options - {keepDiacritics: whether to remove diacritics}
250
254
  * @return {String} the prepared value
251
- */
252
- function prepareValueForComparison(value, _a) {
253
- var keepDiacritics = _a.keepDiacritics;
255
+ */ function prepareValueForComparison(value, { keepDiacritics }) {
254
256
  // value might not actually be a string at this point (we don't get to choose)
255
257
  // so part of preparing the value for comparison is ensure that it is a string
256
- value = "".concat(value); // toString
258
+ value = `${value}`; // toString
257
259
  if (!keepDiacritics) {
258
- value = (0, removeAccents_1.default)(value);
260
+ value = (0, _removeAccents.default)(value);
259
261
  }
260
262
  return value;
261
263
  }
@@ -264,26 +266,21 @@ function prepareValueForComparison(value, _a) {
264
266
  * @param {Object} item - the item
265
267
  * @param {Object|Function} key - the potentially nested keypath or property callback
266
268
  * @return {Array} - an array containing the value(s) at the nested keypath
267
- */
268
- function getItemValues(item, key) {
269
+ */ function getItemValues(item, key) {
269
270
  if (typeof key === "object") {
270
271
  key = key.key;
271
272
  }
272
- var value;
273
+ let value;
273
274
  if (typeof key === "function") {
274
275
  value = key(item);
275
- }
276
- else if (item == null) {
276
+ } else if (item == null) {
277
277
  value = null;
278
- }
279
- else if (Object.hasOwnProperty.call(item, key)) {
278
+ } else if (Object.hasOwnProperty.call(item, key)) {
280
279
  value = item[key];
281
- }
282
- else if (key.includes(".")) {
280
+ } else if (key.includes(".")) {
283
281
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
284
282
  return getNestedValues(key, item);
285
- }
286
- else {
283
+ } else {
287
284
  value = null;
288
285
  }
289
286
  // because `value` can also be undefined
@@ -293,7 +290,9 @@ function getItemValues(item, key) {
293
290
  if (Array.isArray(value)) {
294
291
  return value;
295
292
  }
296
- return [String(value)];
293
+ return [
294
+ String(value)
295
+ ];
297
296
  }
298
297
  /**
299
298
  * Given path: "foo.bar.baz"
@@ -301,24 +300,23 @@ function getItemValues(item, key) {
301
300
  * -> 'buzz'
302
301
  * @param path a dot-separated set of keys
303
302
  * @param item the item to get the value from
304
- */
305
- function getNestedValues(path, item) {
306
- var keys = path.split(".");
307
- var values = [item];
308
- for (var i = 0, I = keys.length; i < I; i++) {
309
- var nestedKey = keys[i];
310
- var nestedValues = [];
311
- for (var j = 0, J = values.length; j < J; j++) {
312
- var nestedItem = values[j];
313
- if (nestedItem == null)
314
- continue;
303
+ */ function getNestedValues(path, item) {
304
+ const keys = path.split(".");
305
+ let values = [
306
+ item
307
+ ];
308
+ for(let i = 0, I = keys.length; i < I; i++){
309
+ const nestedKey = keys[i];
310
+ let nestedValues = [];
311
+ for(let j = 0, J = values.length; j < J; j++){
312
+ const nestedItem = values[j];
313
+ if (nestedItem == null) continue;
315
314
  if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
316
- var nestedValue = nestedItem[nestedKey];
315
+ const nestedValue = nestedItem[nestedKey];
317
316
  if (nestedValue != null) {
318
317
  nestedValues.push(nestedValue);
319
318
  }
320
- }
321
- else if (nestedKey === "*") {
319
+ } else if (nestedKey === "*") {
322
320
  // ensure that values is an array
323
321
  nestedValues = nestedValues.concat(nestedItem);
324
322
  }
@@ -328,8 +326,8 @@ function getNestedValues(path, item) {
328
326
  if (Array.isArray(values[0])) {
329
327
  // keep allowing the implicit wildcard for an array of strings at the end of
330
328
  // the path; don't use `.flat()` because that's not available in node.js v10
331
- var result = [];
332
- return result.concat.apply(result, values);
329
+ const result = [];
330
+ return result.concat(...values);
333
331
  }
334
332
  // Based on our logic it should be an array of strings by now...
335
333
  // assuming the user's path terminated in strings
@@ -340,35 +338,36 @@ function getNestedValues(path, item) {
340
338
  * @param item - the item from which the values will be retrieved
341
339
  * @param keys - the keys to use to retrieve the values
342
340
  * @return objects with {itemValue, attributes}
343
- */
344
- function getAllValuesToRank(item, keys) {
345
- var allValues = [];
346
- for (var j = 0, J = keys.length; j < J; j++) {
347
- var key = keys[j];
348
- var attributes = getKeyAttributes(key);
349
- var itemValues = getItemValues(item, key);
350
- for (var i = 0, I = itemValues.length; i < I; i++) {
341
+ */ function getAllValuesToRank(item, keys) {
342
+ const allValues = [];
343
+ for(let j = 0, J = keys.length; j < J; j++){
344
+ const key = keys[j];
345
+ const attributes = getKeyAttributes(key);
346
+ const itemValues = getItemValues(item, key);
347
+ for(let i = 0, I = itemValues.length; i < I; i++){
351
348
  allValues.push({
352
349
  itemValue: itemValues[i],
353
- attributes: attributes,
350
+ attributes
354
351
  });
355
352
  }
356
353
  }
357
354
  return allValues;
358
355
  }
359
- var defaultKeyAttributes = {
356
+ const defaultKeyAttributes = {
360
357
  maxRanking: Infinity,
361
- minRanking: -Infinity,
358
+ minRanking: -Infinity
362
359
  };
363
360
  /**
364
361
  * Gets all the attributes for the given key
365
362
  * @param key - the key from which the attributes will be retrieved
366
363
  * @return object containing the key's attributes
367
- */
368
- function getKeyAttributes(key) {
364
+ */ function getKeyAttributes(key) {
369
365
  if (typeof key === "string") {
370
366
  return defaultKeyAttributes;
371
367
  }
372
- return tslib_1.__assign(tslib_1.__assign({}, defaultKeyAttributes), key);
368
+ return {
369
+ ...defaultKeyAttributes,
370
+ ...key
371
+ };
373
372
  }
374
- exports.default = matchSorter;
373
+ const _default = matchSorter;