@koine/utils 2.0.0-beta.80 → 2.0.0-beta.83

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