@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
@@ -1,242 +1,97 @@
1
1
  import { isString } from './isString.esm.js';
2
2
  import { removeAccents } from './removeAccents.esm.js';
3
3
  import './getType.esm.js';
4
- import './accentSets.esm.js';
4
+ import './accentsSets.esm.js';
5
5
 
6
- const RANKING_CASE_SENSITIVE_EQUAL = 7;
7
- const RANKING_EQUAL = 6;
8
- const RANKING_STARTS_WITH = 5;
9
- const RANKING_WORD_STARTS_WITH = 4;
10
- const RANKING_CONTAINS = 3;
11
- const RANKING_ACRONYM = 2;
12
- const RANKING_MATCHES = 1;
13
- const RANKING_NO_MATCH = 0;
14
- let defaultBaseSortFn = (a, b) => String(a.rankedValue).localeCompare(String(b.rankedValue));
15
- let matchSorter = (items, value, options = {}) => {
16
- const { keys, threshold = RANKING_MATCHES, baseSort = defaultBaseSortFn, sorter = (matchedItems) => matchedItems.sort((a, b) => sortRankedValues(a, b, baseSort)), } = options;
17
- const matchedItems = items.reduce(reduceItemsToRanked, []);
18
- return sorter(matchedItems).map(({ item }) => item);
19
- function reduceItemsToRanked(matches, item, index) {
20
- const rankingInfo = getHighestRanking(item, keys, value, options);
21
- const { rank, keyThreshold = threshold } = rankingInfo;
22
- if (rank >= keyThreshold) {
23
- matches.push({ ...rankingInfo, item, index });
24
- }
25
- return matches;
26
- }
27
- };
28
- let getHighestRanking = (item, keys, value, options) => {
29
- if (!keys) {
30
- const stringItem = item;
31
- return {
32
- rankedValue: stringItem,
33
- rank: getMatchRanking(stringItem, value, options),
34
- keyIndex: -1,
35
- keyThreshold: options.threshold,
36
- };
37
- }
38
- const valuesToRank = getAllValuesToRank(item, keys);
39
- return valuesToRank.reduce(({ rank, rankedValue, keyIndex, keyThreshold }, { itemValue, attributes }, i) => {
40
- let newRank = getMatchRanking(itemValue, value, options);
41
- let newRankedValue = rankedValue;
42
- const { minRanking, maxRanking, threshold } = attributes;
43
- if (newRank < minRanking && newRank >= RANKING_MATCHES) {
44
- newRank = minRanking;
45
- }
46
- else if (newRank > maxRanking) {
47
- newRank = maxRanking;
48
- }
49
- if (newRank > rank) {
50
- rank = newRank;
51
- keyIndex = i;
52
- keyThreshold = threshold;
53
- newRankedValue = itemValue;
54
- }
55
- return { rankedValue: newRankedValue, rank, keyIndex, keyThreshold };
56
- }, {
57
- rankedValue: item,
58
- rank: RANKING_NO_MATCH,
59
- keyIndex: -1,
60
- keyThreshold: options.threshold,
61
- });
62
- };
63
- let getMatchRanking = (testString, stringToRank, options) => {
64
- testString = prepareValueForComparison(testString, options);
65
- stringToRank = prepareValueForComparison(stringToRank, options);
66
- if (stringToRank.length > testString.length) {
67
- return RANKING_NO_MATCH;
68
- }
69
- if (testString === stringToRank) {
70
- return RANKING_CASE_SENSITIVE_EQUAL;
71
- }
72
- testString = testString.toLowerCase();
73
- stringToRank = stringToRank.toLowerCase();
74
- if (testString === stringToRank) {
75
- return RANKING_EQUAL;
76
- }
77
- if (testString.startsWith(stringToRank)) {
78
- return RANKING_STARTS_WITH;
79
- }
80
- if (testString.includes(` ${stringToRank}`)) {
81
- return RANKING_WORD_STARTS_WITH;
82
- }
83
- if (testString.includes(stringToRank)) {
84
- return RANKING_CONTAINS;
85
- }
86
- else if (stringToRank.length === 1) {
87
- return RANKING_NO_MATCH;
88
- }
89
- if (getAcronym(testString).includes(stringToRank)) {
90
- return RANKING_ACRONYM;
91
- }
92
- return getClosenessRanking(testString, stringToRank);
93
- };
94
- let getAcronym = (string) => {
95
- let acronym = "";
96
- const wordsInString = string.split(" ");
97
- wordsInString.forEach((wordInString) => {
98
- const splitByHyphenWords = wordInString.split("-");
99
- splitByHyphenWords.forEach((splitByHyphenWord) => {
100
- acronym += splitByHyphenWord.substring(0, 1);
101
- });
102
- });
103
- return acronym;
104
- };
105
- let getClosenessRanking = (testString, stringToRank) => {
106
- let matchingInOrderCharCount = 0;
107
- let charNumber = 0;
108
- function findMatchingCharacter(matchChar, string, index) {
109
- for (let j = index, J = string.length; j < J; j++) {
110
- const stringChar = string[j];
111
- if (stringChar === matchChar) {
112
- matchingInOrderCharCount += 1;
113
- return j + 1;
114
- }
115
- }
116
- return -1;
117
- }
118
- function getRanking(spread) {
119
- const spreadPercentage = 1 / spread;
120
- const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
121
- const ranking = RANKING_MATCHES + inOrderPercentage * spreadPercentage;
122
- return ranking;
123
- }
124
- const firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
125
- if (firstIndex < 0) {
126
- return RANKING_NO_MATCH;
127
- }
128
- charNumber = firstIndex;
129
- for (let i = 1, I = stringToRank.length; i < I; i++) {
130
- const matchChar = stringToRank[i];
131
- charNumber = findMatchingCharacter(matchChar, testString, charNumber);
132
- const found = charNumber > -1;
133
- if (!found) {
134
- return RANKING_NO_MATCH;
135
- }
136
- }
137
- const spread = charNumber - firstIndex;
138
- return getRanking(spread);
139
- };
140
- let sortRankedValues = (a, b, baseSort) => {
141
- const aFirst = -1;
142
- const bFirst = 1;
143
- const { rank: aRank, keyIndex: aKeyIndex } = a;
144
- const { rank: bRank, keyIndex: bKeyIndex } = b;
145
- const same = aRank === bRank;
146
- if (same) {
147
- if (aKeyIndex === bKeyIndex) {
148
- return baseSort(a, b);
149
- }
150
- else {
151
- return aKeyIndex < bKeyIndex ? aFirst : bFirst;
152
- }
153
- }
154
- else {
155
- return aRank > bRank ? aFirst : bFirst;
156
- }
157
- };
158
- let prepareValueForComparison = (value, { keepDiacritics }) => {
159
- value = `${value}`;
160
- if (!keepDiacritics) {
161
- value = removeAccents(value);
162
- }
163
- return value;
164
- };
165
- let getItemValues = (item, key) => {
166
- if (typeof key === "object") {
167
- key = key.key;
168
- }
169
- let value;
170
- if (typeof key === "function") {
171
- value = key(item);
172
- }
173
- else if (item == null) {
174
- value = null;
175
- }
176
- else if (Object.hasOwnProperty.call(item, key)) {
177
- value = item[key];
178
- }
179
- else if (key.includes(".")) {
180
- return getNestedValues(key, item);
181
- }
182
- else {
183
- value = null;
184
- }
185
- if (value == null) {
186
- return [];
187
- }
188
- if (Array.isArray(value)) {
189
- return value;
190
- }
191
- return [String(value)];
192
- };
193
- let getNestedValues = (path, item) => {
194
- const keys = path.split(".");
195
- let values = [item];
196
- for (let i = 0, I = keys.length; i < I; i++) {
197
- const nestedKey = keys[i];
198
- let nestedValues = [];
199
- for (let j = 0, J = values.length; j < J; j++) {
200
- const nestedItem = values[j];
201
- if (nestedItem == null)
202
- continue;
203
- if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
204
- const nestedValue = nestedItem[nestedKey];
205
- if (nestedValue != null) {
206
- nestedValues.push(nestedValue);
207
- }
208
- }
209
- else if (nestedKey === "*") {
210
- nestedValues = nestedValues.concat(nestedItem);
211
- }
212
- }
213
- values = nestedValues;
214
- }
215
- if (Array.isArray(values[0])) {
216
- const result = [];
217
- return result.concat(...values);
218
- }
219
- return values;
220
- };
221
- let getAllValuesToRank = (item, keys) => {
222
- const allValues = [];
223
- for (let j = 0, J = keys.length; j < J; j++) {
224
- const key = keys[j];
225
- const attributes = getKeyAttributes(key);
226
- const itemValues = getItemValues(item, key);
227
- for (let i = 0, I = itemValues.length; i < I; i++) {
228
- allValues.push({
229
- itemValue: itemValues[i],
230
- attributes,
231
- });
232
- }
233
- }
234
- return allValues;
235
- };
236
- const defaultKeyAttributes = {
237
- maxRanking: Infinity,
238
- minRanking: -Infinity,
239
- };
240
- let getKeyAttributes = (key) => isString(key) ? defaultKeyAttributes : { ...defaultKeyAttributes, ...key };
6
+ let r=(e,t)=>String(e.rankedValue).localeCompare(String(t.rankedValue)),/**
7
+ * Takes an array of items and a value and returns a new array with the items that match the given value
8
+ * @param {Array} items - the items to sort
9
+ * @param {String} value - the value to use for ranking
10
+ * @param {Object} options - Some options to configure the sorter
11
+ * @return {Array} - the new sorted array
12
+ */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)},/**
13
+ * Gets the highest ranking for value for the given item based on its values for the given keys
14
+ * @param {*} item - the item to rank
15
+ * @param {Array} keys - the keys to get values from the item for the ranking
16
+ * @param {String} value - the value to rank against
17
+ * @param {Object} options - options to control the ranking
18
+ * @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking
19
+ */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
20
+ rankedValue:// if keys is not specified, then we assume the item given is ready to be matched
21
+ e,rank:u(e,r,l),keyIndex:-1,keyThreshold:l.threshold},/**
22
+ * Gives a rankings score based on how well the two strings match.
23
+ * @param {String} testString - the string to test against
24
+ * @param {String} stringToRank - the string to rank
25
+ * @param {Object} options - options for the match (like keepDiacritics for comparison)
26
+ * @returns {Number} the ranking for how well stringToRank matches testString
27
+ */u=(e,t,r)=>// too long
28
+ (e=s(e,r),(t=s(t,r)).length>e.length)?0:// case sensitive equals
29
+ e===t?7:// case insensitive equals
30
+ // Lower casing before further comparison
31
+ (e=e.toLowerCase())===(t=t.toLowerCase())?6:// starts with
32
+ e.startsWith(t)?5:// word starts with
33
+ e.includes(` ${t}`)?4:// contains
34
+ e.includes(t)?3:1===t.length?0:// If the only character in the given stringToRank
35
+ // isn't even contained in the testString, then
36
+ // it's definitely not a match.
37
+ // acronym
38
+ a(e).includes(t)?2:// will return a number between RANKING_MATCHES and
39
+ // RANKING_MATCHES + 1 depending on how close of a match it is.
40
+ o(e,t),/**
41
+ * Generates an acronym for a string.
42
+ *
43
+ * @param {String} string the string for which to produce the acronym
44
+ * @returns {String} the acronym
45
+ */a=e=>{let t="";return e.split(" ").forEach(e=>{e.split("-").forEach(e=>{t+=e.substring(0,1);});}),t},/**
46
+ * Returns a score based on how spread apart the
47
+ * characters from the stringToRank are within the testString.
48
+ * A number close to RANKING_MATCHES represents a loose match. A number close
49
+ * to RANKING_MATCHES + 1 represents a tighter match.
50
+ * @param {String} testString - the string to test against
51
+ * @param {String} stringToRank - the string to rank
52
+ * @returns {Number} the number between RANKING_MATCHES and
53
+ * RANKING_MATCHES + 1 for how well stringToRank matches testString
54
+ */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)},/**
55
+ * Sorts items that have a rank, index, and keyIndex
56
+ * @param {Object} a - the first item to sort
57
+ * @param {Object} b - the second item to sort
58
+ * @return {Number} -1 if a should come first, 1 if b should come first, 0 if equal
59
+ */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
60
+ r(e,t):n<a?-1:1},/**
61
+ * Prepares value for comparison by stringifying it, removing diacritics (if specified)
62
+ * @param {String} value - the value to clean
63
+ * @param {Object} options - {keepDiacritics: whether to remove diacritics}
64
+ * @return {String} the prepared value
65
+ */s=(e,{keepDiacritics:r})=>(// value might not actually be a string at this point (we don't get to choose)
66
+ // so part of preparing the value for comparison is ensure that it is a string
67
+ e=`${e}`,// toString
68
+ r||(e=removeAccents(e)),e),/**
69
+ * Gets value for key in item at arbitrarily nested keypath
70
+ * @param {Object} item - the item
71
+ * @param {Object|Function} key - the potentially nested keypath or property callback
72
+ * @return {Array} - an array containing the value(s) at the nested keypath
73
+ */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
74
+ return f(t,e);r=null;}return(// because `value` can also be undefined
75
+ null==r?[]:Array.isArray(r)?r:[String(r)])},/**
76
+ * Given path: "foo.bar.baz"
77
+ * And item: {foo: {bar: {baz: 'buzz'}}}
78
+ * -> 'buzz'
79
+ * @param path a dot-separated set of keys
80
+ * @param item the item to get the value from
81
+ */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
82
+ (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
83
+ // the path; don't use `.flat()` because that's not available in node.js v10
84
+ [].concat(...l):// Based on our logic it should be an array of strings by now...
85
+ // assuming the user's path terminated in strings
86
+ l},/**
87
+ * Gets all the values for the given keys in the given item and returns an array of those values
88
+ * @param item - the item from which the values will be retrieved
89
+ * @param keys - the keys to use to retrieve the values
90
+ * @return objects with {itemValue, attributes}
91
+ */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},/**
92
+ * Gets all the attributes for the given key
93
+ * @param key - the key from which the attributes will be retrieved
94
+ * @return object containing the key's attributes
95
+ */k=t=>isString(t)?d:{...d,...t};
241
96
 
242
- export { matchSorter as default, defaultBaseSortFn, matchSorter };
97
+ export { l as default, r as defaultBaseSortFn, l as matchSorter };
package/mbToBytes.cjs.js CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- let mbToBytes = (bytes) => bytes * 1000 * 1000;
5
+ /**
6
+ * Megabytes to bytes
7
+ *
8
+ * @category format
9
+ */let mbToBytes=e=>1e6*e;
6
10
 
7
11
  exports["default"] = mbToBytes;
8
12
  exports.mbToBytes = mbToBytes;
package/mbToBytes.esm.js CHANGED
@@ -1,3 +1,7 @@
1
- let mbToBytes = (bytes) => bytes * 1000 * 1000;
1
+ /**
2
+ * Megabytes to bytes
3
+ *
4
+ * @category format
5
+ */let mbToBytes=e=>1e6*e;
2
6
 
3
7
  export { mbToBytes as default, mbToBytes };
@@ -7,32 +7,14 @@ var isUndefined = require('./isUndefined.cjs.js');
7
7
  require('./isPlainObject.cjs.js');
8
8
  require('./getType.cjs.js');
9
9
 
10
- let mergeObjects = (target, ...sources) => {
11
- if (!sources.length) {
12
- return target;
13
- }
14
- const source = sources.shift();
15
- if (source === undefined) {
16
- return target;
17
- }
18
- if (isObject.isObject(target) && isObject.isObject(source)) {
19
- Object.keys(source).forEach((_key) => {
20
- const key = _key;
21
- if (isObject.isObject(source[key])) {
22
- if (!target[key]) {
23
- target[key] = {};
24
- }
25
- mergeObjects(target[key], source[key]);
26
- }
27
- else {
28
- if (!isUndefined.isUndefined(source[key])) {
29
- target[key] = source[key];
30
- }
31
- }
32
- });
33
- }
34
- return mergeObjects(target, ...sources);
35
- };
10
+ /**
11
+ * Merge two or more objects together. It mutates the target object.
12
+ *
13
+ * @category object
14
+ * @see https://stackoverflow.com/a/46973278/1938970
15
+ */let mergeObjects=(r,...i)=>{if(!i.length)return r;let m=i.shift();return void 0===m?r:(isObject.isObject(r)&&isObject.isObject(m)&&Object.keys(m).forEach(i=>{isObject.isObject(m[i])?(r[i]||(r[i]={}),mergeObjects(r[i],m[i])):isUndefined.isUndefined(m[i])||// FIXME: assertion here should not be needed but isUndefined does not
16
+ // narrow the type here
17
+ (r[i]=m[i]);}),mergeObjects(r,...i))};
36
18
 
37
19
  exports["default"] = mergeObjects;
38
20
  exports.mergeObjects = mergeObjects;
@@ -3,31 +3,13 @@ import { isUndefined } from './isUndefined.esm.js';
3
3
  import './isPlainObject.esm.js';
4
4
  import './getType.esm.js';
5
5
 
6
- let mergeObjects = (target, ...sources) => {
7
- if (!sources.length) {
8
- return target;
9
- }
10
- const source = sources.shift();
11
- if (source === undefined) {
12
- return target;
13
- }
14
- if (isObject(target) && isObject(source)) {
15
- Object.keys(source).forEach((_key) => {
16
- const key = _key;
17
- if (isObject(source[key])) {
18
- if (!target[key]) {
19
- target[key] = {};
20
- }
21
- mergeObjects(target[key], source[key]);
22
- }
23
- else {
24
- if (!isUndefined(source[key])) {
25
- target[key] = source[key];
26
- }
27
- }
28
- });
29
- }
30
- return mergeObjects(target, ...sources);
31
- };
6
+ /**
7
+ * Merge two or more objects together. It mutates the target object.
8
+ *
9
+ * @category object
10
+ * @see https://stackoverflow.com/a/46973278/1938970
11
+ */let mergeObjects=(r,...i)=>{if(!i.length)return r;let m=i.shift();return void 0===m?r:(isObject(r)&&isObject(m)&&Object.keys(m).forEach(i=>{isObject(m[i])?(r[i]||(r[i]={}),mergeObjects(r[i],m[i])):isUndefined(m[i])||// FIXME: assertion here should not be needed but isUndefined does not
12
+ // narrow the type here
13
+ (r[i]=m[i]);}),mergeObjects(r,...i))};
32
14
 
33
15
  export { mergeObjects as default, mergeObjects };
@@ -5,18 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var isNull = require('./isNull.cjs.js');
6
6
  require('./getType.cjs.js');
7
7
 
8
- let mergeUrlQueryParams = (oldParams = {}, newParams = {}) => {
9
- for (const key in newParams) {
10
- const value = newParams[key];
11
- if (oldParams[key] && isNull.isNull(value)) {
12
- delete oldParams[key];
13
- }
14
- else {
15
- oldParams[key] = value;
16
- }
17
- }
18
- return oldParams;
19
- };
8
+ /**
9
+ * Merge query parameters objects, it *mutates* the first given object argument
10
+ *
11
+ * @category location
12
+ */let mergeUrlQueryParams=(r={},l={})=>{for(let t in l){let m=l[t];r[t]&&isNull.isNull(m)?delete r[t]:r[t]=m;}return r};
20
13
 
21
14
  exports["default"] = mergeUrlQueryParams;
22
15
  exports.mergeUrlQueryParams = mergeUrlQueryParams;
@@ -1,17 +1,10 @@
1
1
  import { isNull } from './isNull.esm.js';
2
2
  import './getType.esm.js';
3
3
 
4
- let mergeUrlQueryParams = (oldParams = {}, newParams = {}) => {
5
- for (const key in newParams) {
6
- const value = newParams[key];
7
- if (oldParams[key] && isNull(value)) {
8
- delete oldParams[key];
9
- }
10
- else {
11
- oldParams[key] = value;
12
- }
13
- }
14
- return oldParams;
15
- };
4
+ /**
5
+ * Merge query parameters objects, it *mutates* the first given object argument
6
+ *
7
+ * @category location
8
+ */let mergeUrlQueryParams=(r={},l={})=>{for(let t in l){let m=l[t];r[t]&&isNull(m)?delete r[t]:r[t]=m;}return r};
16
9
 
17
10
  export { mergeUrlQueryParams as default, mergeUrlQueryParams };
@@ -2,14 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- let moveSortableArrayItemByKey = (items, key, fromItem, toItem) => {
6
- const itemsKeys = items.map((item) => item[key]);
7
- const idxFrom = itemsKeys.indexOf(fromItem[key]);
8
- const idxTo = itemsKeys.indexOf(toItem[key]);
9
- const [item] = items.splice(idxFrom, 1);
10
- items.splice(idxTo, 0, item);
11
- return [...items];
12
- };
5
+ /**
6
+ * Move item from one place to another in a sortable array of objects, re-ordering
7
+ * the array accrodingly (no swapping of position).
8
+ * This is useful for drag and drop functionalities
9
+ *
10
+ * @category array
11
+ */let moveSortableArrayItemByKey=(e,r,t,l)=>{let a=e.map(e=>e[r]),o=a.indexOf(t[r]),y=a.indexOf(l[r]),[m]=e.splice(o,1);return e.splice(y,0,m),[...e]};
13
12
 
14
13
  exports["default"] = moveSortableArrayItemByKey;
15
14
  exports.moveSortableArrayItemByKey = moveSortableArrayItemByKey;
@@ -1,10 +1,9 @@
1
- let moveSortableArrayItemByKey = (items, key, fromItem, toItem) => {
2
- const itemsKeys = items.map((item) => item[key]);
3
- const idxFrom = itemsKeys.indexOf(fromItem[key]);
4
- const idxTo = itemsKeys.indexOf(toItem[key]);
5
- const [item] = items.splice(idxFrom, 1);
6
- items.splice(idxTo, 0, item);
7
- return [...items];
8
- };
1
+ /**
2
+ * Move item from one place to another in a sortable array of objects, re-ordering
3
+ * the array accrodingly (no swapping of position).
4
+ * This is useful for drag and drop functionalities
5
+ *
6
+ * @category array
7
+ */let moveSortableArrayItemByKey=(e,r,t,l)=>{let a=e.map(e=>e[r]),o=a.indexOf(t[r]),y=a.indexOf(l[r]),[m]=e.splice(o,1);return e.splice(y,0,m),[...e]};
9
8
 
10
9
  export { moveSortableArrayItemByKey as default, moveSortableArrayItemByKey };
package/noop.cjs.js CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- let noop = () => void 0;
5
+ /**
6
+ * No operation function
7
+ *
8
+ * @category native
9
+ */let noop=()=>void 0;
6
10
 
7
11
  exports["default"] = noop;
8
12
  exports.noop = noop;
package/noop.esm.js CHANGED
@@ -1,3 +1,7 @@
1
- let noop = () => void 0;
1
+ /**
2
+ * No operation function
3
+ *
4
+ * @category native
5
+ */let noop=()=>void 0;
2
6
 
3
7
  export { noop as default, noop };
@@ -4,7 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var removeTrailingSlash = require('./removeTrailingSlash.cjs.js');
6
6
 
7
- let normaliseUrl = (absoluteUrl = "") => removeTrailingSlash.removeTrailingSlash(absoluteUrl.replace(/(:\/\/)|(\/)+/g, "$1$2"));
7
+ /**
8
+ * Normalise URL, it works both for absolute and relative URLs
9
+ *
10
+ * - replaces too many consecutive slashes (except `http{s}://`)
11
+ * - removes the trailing slash
12
+ *
13
+ * @category location
14
+ * @see https://stackoverflow.com/a/40649435/1938970
15
+ */let normaliseUrl=(e="")=>removeTrailingSlash.removeTrailingSlash(e.replace(/(:\/\/)|(\/)+/g,"$1$2"));
8
16
 
9
17
  exports["default"] = normaliseUrl;
10
18
  exports.normaliseUrl = normaliseUrl;
@@ -1,5 +1,13 @@
1
1
  import { removeTrailingSlash } from './removeTrailingSlash.esm.js';
2
2
 
3
- let normaliseUrl = (absoluteUrl = "") => removeTrailingSlash(absoluteUrl.replace(/(:\/\/)|(\/)+/g, "$1$2"));
3
+ /**
4
+ * Normalise URL, it works both for absolute and relative URLs
5
+ *
6
+ * - replaces too many consecutive slashes (except `http{s}://`)
7
+ * - removes the trailing slash
8
+ *
9
+ * @category location
10
+ * @see https://stackoverflow.com/a/40649435/1938970
11
+ */let normaliseUrl=(e="")=>removeTrailingSlash(e.replace(/(:\/\/)|(\/)+/g,"$1$2"));
4
12
 
5
13
  export { normaliseUrl as default, normaliseUrl };
@@ -4,7 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var removeTrailingSlash = require('./removeTrailingSlash.cjs.js');
6
6
 
7
- let normaliseUrlPathname = (pathname = "") => removeTrailingSlash.removeTrailingSlash(pathname.replace(/\/+/g, "/"));
7
+ /**
8
+ * Normalise URL pathname (relative URL)
9
+ *
10
+ * - replaces too many consecutive slashes
11
+ * - removes the trailing slash
12
+ *
13
+ * @category location
14
+ */let normaliseUrlPathname=(r="")=>removeTrailingSlash.removeTrailingSlash(r.replace(/\/+/g,"/"));
8
15
 
9
16
  exports["default"] = normaliseUrlPathname;
10
17
  exports.normaliseUrlPathname = normaliseUrlPathname;
@@ -1,5 +1,12 @@
1
1
  import { removeTrailingSlash } from './removeTrailingSlash.esm.js';
2
2
 
3
- let normaliseUrlPathname = (pathname = "") => removeTrailingSlash(pathname.replace(/\/+/g, "/"));
3
+ /**
4
+ * Normalise URL pathname (relative URL)
5
+ *
6
+ * - replaces too many consecutive slashes
7
+ * - removes the trailing slash
8
+ *
9
+ * @category location
10
+ */let normaliseUrlPathname=(r="")=>removeTrailingSlash(r.replace(/\/+/g,"/"));
4
11
 
5
12
  export { normaliseUrlPathname as default, normaliseUrlPathname };