@koine/utils 2.0.0-beta.72 → 2.0.0-beta.74

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 (333) hide show
  1. package/Defer.d.ts +1 -0
  2. package/Defer.js +11 -0
  3. package/Emitter.d.ts +1 -0
  4. package/Emitter.js +20 -0
  5. package/accentSets.d.ts +1 -0
  6. package/accentSets.js +30 -0
  7. package/addOrReplaceAtIdx.d.ts +1 -0
  8. package/addOrReplaceAtIdx.js +15 -0
  9. package/areEqual.d.ts +1 -1
  10. package/areEqual.js +46 -0
  11. package/arrayFilterFalsy.d.ts +1 -0
  12. package/arrayFilterFalsy.js +2 -0
  13. package/arrayFindLastIndex.d.ts +1 -0
  14. package/arrayFindLastIndex.js +9 -0
  15. package/arrayOfAll.d.ts +1 -0
  16. package/arrayOfAll.js +2 -0
  17. package/arraySum.d.ts +1 -0
  18. package/arraySum.js +2 -0
  19. package/arrayToLookup.d.ts +1 -0
  20. package/arrayToLookup.js +5 -0
  21. package/arrayUniqueByProperties.d.ts +1 -0
  22. package/arrayUniqueByProperties.js +2 -0
  23. package/buildUrlQueryString.d.ts +1 -0
  24. package/buildUrlQueryString.js +21 -0
  25. package/capitalize.d.ts +1 -0
  26. package/capitalize.js +3 -0
  27. package/changeCaseCamel.d.ts +1 -0
  28. package/changeCaseCamel.js +19 -0
  29. package/changeCaseCapital.d.ts +1 -0
  30. package/changeCaseCapital.js +12 -0
  31. package/changeCaseConstant.d.ts +1 -0
  32. package/changeCaseConstant.js +8 -0
  33. package/changeCaseDot.d.ts +1 -0
  34. package/changeCaseDot.js +3 -0
  35. package/changeCaseHelpers.d.ts +0 -5
  36. package/changeCaseHelpers.js +71 -0
  37. package/changeCaseKebab.d.ts +1 -0
  38. package/changeCaseKebab.js +3 -0
  39. package/changeCaseNone.d.ts +1 -0
  40. package/changeCaseNone.js +8 -0
  41. package/changeCasePascal.d.ts +1 -0
  42. package/changeCasePascal.js +11 -0
  43. package/changeCasePascalSnake.d.ts +1 -0
  44. package/changeCasePascalSnake.js +3 -0
  45. package/changeCasePath.d.ts +1 -0
  46. package/changeCasePath.js +3 -0
  47. package/changeCaseSentence.d.ts +1 -0
  48. package/changeCaseSentence.js +17 -0
  49. package/changeCaseSnake.d.ts +1 -0
  50. package/changeCaseSnake.js +3 -0
  51. package/changeCaseTrain.d.ts +1 -0
  52. package/changeCaseTrain.js +3 -0
  53. package/chunkByChunks.d.ts +1 -0
  54. package/chunkByChunks.js +32 -0
  55. package/chunkBySize.d.ts +1 -0
  56. package/chunkBySize.js +8 -0
  57. package/clamp.d.ts +1 -0
  58. package/clamp.js +2 -0
  59. package/clsx.d.ts +1 -1
  60. package/clsx.js +40 -0
  61. package/convertRange.d.ts +1 -0
  62. package/convertRange.js +2 -0
  63. package/cookie.d.ts +0 -3
  64. package/cookie.js +1 -0
  65. package/createPalette.d.ts +1 -1
  66. package/createPalette.js +12 -0
  67. package/debounce.d.ts +1 -0
  68. package/debounce.js +18 -0
  69. package/debouncePromise.d.ts +1 -0
  70. package/debouncePromise.js +52 -0
  71. package/debounceRaf.d.ts +1 -0
  72. package/debounceRaf.js +13 -0
  73. package/decode.d.ts +1 -0
  74. package/decode.js +2 -0
  75. package/encode.d.ts +1 -0
  76. package/encode.js +2 -0
  77. package/ensureInt.d.ts +1 -0
  78. package/ensureInt.js +2 -0
  79. package/env.js +1 -0
  80. package/errorToString.d.ts +1 -0
  81. package/errorToString.js +3 -0
  82. package/escapeRegExp.d.ts +1 -0
  83. package/escapeRegExp.js +2 -0
  84. package/findDuplicatedIndexes.d.ts +1 -0
  85. package/findDuplicatedIndexes.js +11 -0
  86. package/forin.d.ts +1 -0
  87. package/forin.js +6 -0
  88. package/gbToBytes.d.ts +1 -0
  89. package/gbToBytes.js +2 -0
  90. package/getEmptyArray.d.ts +1 -0
  91. package/getEmptyArray.js +5 -0
  92. package/getKeys.d.ts +1 -0
  93. package/getKeys.js +2 -0
  94. package/getMediaQueryWidthResolvers.d.ts +1 -0
  95. package/getMediaQueryWidthResolvers.js +42 -0
  96. package/getMediaQueryWidthTailwindScreens.d.ts +1 -0
  97. package/getMediaQueryWidthTailwindScreens.js +27 -0
  98. package/getNonce.d.ts +1 -0
  99. package/getNonce.js +3 -0
  100. package/getParamAmong.d.ts +1 -0
  101. package/getParamAmong.js +6 -0
  102. package/getParamAsInt.d.ts +1 -0
  103. package/getParamAsInt.js +9 -0
  104. package/getParamAsString.d.ts +1 -0
  105. package/getParamAsString.js +3 -0
  106. package/getType.d.ts +1 -0
  107. package/getType.js +2 -0
  108. package/getUrlHashParams.d.ts +1 -0
  109. package/getUrlHashParams.js +9 -0
  110. package/getUrlHashPathname.d.ts +1 -0
  111. package/getUrlHashPathname.js +2 -0
  112. package/getUrlPathnameParts.d.ts +1 -0
  113. package/getUrlPathnameParts.js +6 -0
  114. package/getUrlQueryParams.d.ts +1 -0
  115. package/getUrlQueryParams.js +22 -0
  116. package/imgEmptyPixel.d.ts +1 -0
  117. package/imgEmptyPixel.js +2 -0
  118. package/index.cjs.js +69 -69
  119. package/index.d.ts +1 -1
  120. package/index.esm.js +69 -69
  121. package/index.js +156 -0
  122. package/invariant.d.ts +1 -0
  123. package/invariant.js +17 -0
  124. package/isAbsoluteUrl.d.ts +1 -0
  125. package/isAbsoluteUrl.js +3 -0
  126. package/isAnyObject.d.ts +1 -0
  127. package/isAnyObject.js +3 -0
  128. package/isArray.d.ts +1 -0
  129. package/isArray.js +3 -0
  130. package/isBlob.d.ts +1 -0
  131. package/isBlob.js +3 -0
  132. package/isBoolean.d.ts +1 -0
  133. package/isBoolean.js +3 -0
  134. package/isBrowser.d.ts +1 -0
  135. package/isBrowser.js +2 -0
  136. package/isBrowserNow.d.ts +1 -0
  137. package/isBrowserNow.js +3 -0
  138. package/isDate.d.ts +1 -0
  139. package/isDate.js +3 -0
  140. package/isEmptyArray.d.ts +1 -0
  141. package/isEmptyArray.js +3 -0
  142. package/isEmptyObject.d.ts +1 -0
  143. package/isEmptyObject.js +3 -0
  144. package/isEmptyString.d.ts +1 -0
  145. package/isEmptyString.js +2 -0
  146. package/isError.d.ts +1 -0
  147. package/isError.js +3 -0
  148. package/isExternalUrl.d.ts +1 -0
  149. package/isExternalUrl.js +11 -0
  150. package/isFile.d.ts +1 -0
  151. package/isFile.js +3 -0
  152. package/isFloat.d.ts +1 -0
  153. package/isFloat.js +3 -0
  154. package/isFormData.d.ts +1 -0
  155. package/isFormData.js +3 -0
  156. package/isFullArray.d.ts +1 -0
  157. package/isFullArray.js +3 -0
  158. package/isFullObject.d.ts +1 -0
  159. package/isFullObject.js +3 -0
  160. package/isFullString.d.ts +1 -0
  161. package/isFullString.js +3 -0
  162. package/isFunction.d.ts +1 -0
  163. package/isFunction.js +2 -0
  164. package/isInt.d.ts +1 -0
  165. package/isInt.js +3 -0
  166. package/isMap.d.ts +1 -0
  167. package/isMap.js +3 -0
  168. package/isNaNValue.d.ts +1 -0
  169. package/isNaNValue.js +3 -0
  170. package/isNegativeNumber.d.ts +1 -0
  171. package/isNegativeNumber.js +3 -0
  172. package/isNull.d.ts +1 -0
  173. package/isNull.js +3 -0
  174. package/isNullOrUndefined.d.ts +1 -0
  175. package/isNullOrUndefined.js +5 -0
  176. package/isNumber.d.ts +1 -0
  177. package/isNumber.js +3 -0
  178. package/isNumericLiteral.d.ts +1 -0
  179. package/isNumericLiteral.js +2 -0
  180. package/isObject.d.ts +1 -0
  181. package/isObject.js +3 -0
  182. package/isObjectLike.d.ts +1 -0
  183. package/isObjectLike.js +3 -0
  184. package/isObjectStringKeyed.d.ts +1 -0
  185. package/isObjectStringKeyed.js +3 -0
  186. package/isOneOf.d.ts +1 -0
  187. package/isOneOf.js +8 -0
  188. package/isPlainObject.d.ts +1 -0
  189. package/isPlainObject.js +6 -0
  190. package/isPositiveNumber.d.ts +1 -0
  191. package/isPositiveNumber.js +3 -0
  192. package/isPrimitive.d.ts +1 -0
  193. package/isPrimitive.js +13 -0
  194. package/isPromise.d.ts +1 -0
  195. package/isPromise.js +3 -0
  196. package/isRegExp.d.ts +1 -0
  197. package/isRegExp.js +3 -0
  198. package/isServer.d.ts +1 -0
  199. package/isServer.js +3 -0
  200. package/isServerNow.d.ts +1 -0
  201. package/isServerNow.js +3 -0
  202. package/isSet.d.ts +1 -0
  203. package/isSet.js +3 -0
  204. package/isString.d.ts +1 -0
  205. package/isString.js +3 -0
  206. package/isSymbol.d.ts +1 -0
  207. package/isSymbol.js +3 -0
  208. package/isType.d.ts +1 -0
  209. package/isType.js +13 -0
  210. package/isUndefined.d.ts +1 -0
  211. package/isUndefined.js +3 -0
  212. package/isWeakMap.d.ts +1 -0
  213. package/isWeakMap.js +3 -0
  214. package/isWeakSet.d.ts +1 -0
  215. package/isWeakSet.js +3 -0
  216. package/kbToBytes.d.ts +1 -0
  217. package/kbToBytes.js +2 -0
  218. package/location.js +1 -0
  219. package/lowercase.d.ts +1 -0
  220. package/lowercase.js +2 -0
  221. package/mapListBy.d.ts +1 -0
  222. package/mapListBy.js +5 -0
  223. package/matchSorter.d.ts +1 -0
  224. package/matchSorter.js +239 -0
  225. package/mbToBytes.d.ts +1 -0
  226. package/mbToBytes.js +2 -0
  227. package/mergeObjects.d.ts +1 -0
  228. package/mergeObjects.js +29 -0
  229. package/mergeUrlQueryParams.d.ts +1 -0
  230. package/mergeUrlQueryParams.js +14 -0
  231. package/moveSortableArrayItemByKey.d.ts +1 -0
  232. package/moveSortableArrayItemByKey.js +9 -0
  233. package/noop.d.ts +1 -0
  234. package/noop.js +2 -0
  235. package/normaliseUrl.d.ts +1 -0
  236. package/normaliseUrl.js +3 -0
  237. package/normaliseUrlPathname.d.ts +1 -0
  238. package/normaliseUrlPathname.js +3 -0
  239. package/objectFlat.d.ts +1 -0
  240. package/objectFlat.js +17 -0
  241. package/objectFlip.d.ts +1 -0
  242. package/objectFlip.js +5 -0
  243. package/objectMergeWithDefaults.d.ts +1 -0
  244. package/objectMergeWithDefaults.js +21 -0
  245. package/objectOmit.d.ts +1 -0
  246. package/objectOmit.js +8 -0
  247. package/objectPick.d.ts +1 -0
  248. package/objectPick.js +9 -0
  249. package/objectSort.d.ts +1 -0
  250. package/objectSort.js +2 -0
  251. package/objectSortByKeysMatching.d.ts +1 -0
  252. package/objectSortByKeysMatching.js +3 -0
  253. package/objectToArray.d.ts +1 -0
  254. package/objectToArray.js +2 -0
  255. package/package.json +1 -1
  256. package/parseCookie.d.ts +1 -0
  257. package/parseCookie.js +33 -0
  258. package/parseURL.d.ts +1 -0
  259. package/parseURL.js +14 -0
  260. package/quaranteneProps.d.ts +1 -1
  261. package/quaranteneProps.js +16 -0
  262. package/randomInt.d.ts +1 -0
  263. package/randomInt.js +2 -0
  264. package/randomKey.d.ts +1 -0
  265. package/randomKey.js +5 -0
  266. package/readCookie.d.ts +1 -0
  267. package/readCookie.js +34 -0
  268. package/removeAccents.d.ts +1 -0
  269. package/removeAccents.js +10 -0
  270. package/removeCookie.d.ts +1 -0
  271. package/removeCookie.js +10 -0
  272. package/removeDuplicates.d.ts +2 -0
  273. package/removeDuplicates.js +2 -0
  274. package/removeDuplicatesByKey.d.ts +1 -0
  275. package/removeDuplicatesByKey.js +13 -0
  276. package/removeDuplicatesComparing.d.ts +1 -0
  277. package/removeDuplicatesComparing.js +7 -0
  278. package/removeIndexesFromArray.d.ts +1 -0
  279. package/removeIndexesFromArray.js +10 -0
  280. package/removeTrailingSlash.d.ts +2 -1
  281. package/removeTrailingSlash.js +2 -0
  282. package/removeUrlQueryParams.d.ts +1 -0
  283. package/removeUrlQueryParams.js +14 -0
  284. package/render.d.ts +1 -1
  285. package/render.js +113 -0
  286. package/round.d.ts +1 -0
  287. package/round.js +4 -0
  288. package/roundTo.d.ts +1 -0
  289. package/roundTo.js +11 -0
  290. package/serializeCookie.d.ts +1 -0
  291. package/serializeCookie.js +69 -0
  292. package/setCookie.d.ts +1 -0
  293. package/setCookie.js +45 -0
  294. package/shuffle.d.ts +1 -0
  295. package/shuffle.js +17 -0
  296. package/slugify.d.ts +1 -0
  297. package/slugify.js +11 -0
  298. package/split.d.ts +1 -0
  299. package/split.js +2 -0
  300. package/splitReverse.d.ts +1 -0
  301. package/splitReverse.js +2 -0
  302. package/swapMap.d.ts +1 -0
  303. package/swapMap.js +8 -0
  304. package/throttle.d.ts +1 -0
  305. package/throttle.js +15 -0
  306. package/titleCase.d.ts +1 -0
  307. package/titleCase.js +4 -0
  308. package/toNumber.d.ts +1 -0
  309. package/toNumber.js +3 -0
  310. package/toRgba.d.ts +1 -0
  311. package/toRgba.js +8 -0
  312. package/transformToUrlPathname.d.ts +1 -0
  313. package/transformToUrlPathname.js +5 -0
  314. package/truncate.d.ts +1 -0
  315. package/truncate.js +6 -0
  316. package/tryUntil.d.ts +1 -0
  317. package/tryUntil.js +15 -0
  318. package/types.js +1 -0
  319. package/uid.d.ts +1 -0
  320. package/uid.js +6 -0
  321. package/updateLinkParams.d.ts +1 -0
  322. package/updateLinkParams.js +7 -0
  323. package/updateUrlQueryParams.d.ts +1 -0
  324. package/updateUrlQueryParams.js +11 -0
  325. package/uppercase.d.ts +1 -0
  326. package/uppercase.js +2 -0
  327. package/uuid.d.ts +1 -0
  328. package/uuid.js +5 -0
  329. package/uuidNumeric.d.ts +1 -0
  330. package/uuidNumeric.js +2 -0
  331. package/wait.d.ts +1 -0
  332. package/wait.js +2 -0
  333. package/without.js +1 -0
package/matchSorter.js ADDED
@@ -0,0 +1,239 @@
1
+ import { isString } from "./isString";
2
+ import { removeAccents } from "./removeAccents";
3
+ const RANKING_CASE_SENSITIVE_EQUAL = 7;
4
+ const RANKING_EQUAL = 6;
5
+ const RANKING_STARTS_WITH = 5;
6
+ const RANKING_WORD_STARTS_WITH = 4;
7
+ const RANKING_CONTAINS = 3;
8
+ const RANKING_ACRONYM = 2;
9
+ const RANKING_MATCHES = 1;
10
+ const RANKING_NO_MATCH = 0;
11
+ let defaultBaseSortFn = (a, b) => String(a.rankedValue).localeCompare(String(b.rankedValue));
12
+ let matchSorter = (items, value, options = {}) => {
13
+ const { keys, threshold = RANKING_MATCHES, baseSort = defaultBaseSortFn, sorter = (matchedItems) => matchedItems.sort((a, b) => sortRankedValues(a, b, baseSort)), } = options;
14
+ const matchedItems = items.reduce(reduceItemsToRanked, []);
15
+ return sorter(matchedItems).map(({ item }) => item);
16
+ function reduceItemsToRanked(matches, item, index) {
17
+ const rankingInfo = getHighestRanking(item, keys, value, options);
18
+ const { rank, keyThreshold = threshold } = rankingInfo;
19
+ if (rank >= keyThreshold) {
20
+ matches.push({ ...rankingInfo, item, index });
21
+ }
22
+ return matches;
23
+ }
24
+ };
25
+ let getHighestRanking = (item, keys, value, options) => {
26
+ if (!keys) {
27
+ const stringItem = item;
28
+ return {
29
+ rankedValue: stringItem,
30
+ rank: getMatchRanking(stringItem, value, options),
31
+ keyIndex: -1,
32
+ keyThreshold: options.threshold,
33
+ };
34
+ }
35
+ const valuesToRank = getAllValuesToRank(item, keys);
36
+ return valuesToRank.reduce(({ rank, rankedValue, keyIndex, keyThreshold }, { itemValue, attributes }, i) => {
37
+ let newRank = getMatchRanking(itemValue, value, options);
38
+ let newRankedValue = rankedValue;
39
+ const { minRanking, maxRanking, threshold } = attributes;
40
+ if (newRank < minRanking && newRank >= RANKING_MATCHES) {
41
+ newRank = minRanking;
42
+ }
43
+ else if (newRank > maxRanking) {
44
+ newRank = maxRanking;
45
+ }
46
+ if (newRank > rank) {
47
+ rank = newRank;
48
+ keyIndex = i;
49
+ keyThreshold = threshold;
50
+ newRankedValue = itemValue;
51
+ }
52
+ return { rankedValue: newRankedValue, rank, keyIndex, keyThreshold };
53
+ }, {
54
+ rankedValue: item,
55
+ rank: RANKING_NO_MATCH,
56
+ keyIndex: -1,
57
+ keyThreshold: options.threshold,
58
+ });
59
+ };
60
+ let getMatchRanking = (testString, stringToRank, options) => {
61
+ testString = prepareValueForComparison(testString, options);
62
+ stringToRank = prepareValueForComparison(stringToRank, options);
63
+ if (stringToRank.length > testString.length) {
64
+ return RANKING_NO_MATCH;
65
+ }
66
+ if (testString === stringToRank) {
67
+ return RANKING_CASE_SENSITIVE_EQUAL;
68
+ }
69
+ testString = testString.toLowerCase();
70
+ stringToRank = stringToRank.toLowerCase();
71
+ if (testString === stringToRank) {
72
+ return RANKING_EQUAL;
73
+ }
74
+ if (testString.startsWith(stringToRank)) {
75
+ return RANKING_STARTS_WITH;
76
+ }
77
+ if (testString.includes(` ${stringToRank}`)) {
78
+ return RANKING_WORD_STARTS_WITH;
79
+ }
80
+ if (testString.includes(stringToRank)) {
81
+ return RANKING_CONTAINS;
82
+ }
83
+ else if (stringToRank.length === 1) {
84
+ return RANKING_NO_MATCH;
85
+ }
86
+ if (getAcronym(testString).includes(stringToRank)) {
87
+ return RANKING_ACRONYM;
88
+ }
89
+ return getClosenessRanking(testString, stringToRank);
90
+ };
91
+ let getAcronym = (string) => {
92
+ let acronym = "";
93
+ const wordsInString = string.split(" ");
94
+ wordsInString.forEach((wordInString) => {
95
+ const splitByHyphenWords = wordInString.split("-");
96
+ splitByHyphenWords.forEach((splitByHyphenWord) => {
97
+ acronym += splitByHyphenWord.substring(0, 1);
98
+ });
99
+ });
100
+ return acronym;
101
+ };
102
+ let getClosenessRanking = (testString, stringToRank) => {
103
+ let matchingInOrderCharCount = 0;
104
+ let charNumber = 0;
105
+ function findMatchingCharacter(matchChar, string, index) {
106
+ for (let j = index, J = string.length; j < J; j++) {
107
+ const stringChar = string[j];
108
+ if (stringChar === matchChar) {
109
+ matchingInOrderCharCount += 1;
110
+ return j + 1;
111
+ }
112
+ }
113
+ return -1;
114
+ }
115
+ function getRanking(spread) {
116
+ const spreadPercentage = 1 / spread;
117
+ const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
118
+ const ranking = RANKING_MATCHES + inOrderPercentage * spreadPercentage;
119
+ return ranking;
120
+ }
121
+ const firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
122
+ if (firstIndex < 0) {
123
+ return RANKING_NO_MATCH;
124
+ }
125
+ charNumber = firstIndex;
126
+ for (let i = 1, I = stringToRank.length; i < I; i++) {
127
+ const matchChar = stringToRank[i];
128
+ charNumber = findMatchingCharacter(matchChar, testString, charNumber);
129
+ const found = charNumber > -1;
130
+ if (!found) {
131
+ return RANKING_NO_MATCH;
132
+ }
133
+ }
134
+ const spread = charNumber - firstIndex;
135
+ return getRanking(spread);
136
+ };
137
+ let sortRankedValues = (a, b, baseSort) => {
138
+ const aFirst = -1;
139
+ const bFirst = 1;
140
+ const { rank: aRank, keyIndex: aKeyIndex } = a;
141
+ const { rank: bRank, keyIndex: bKeyIndex } = b;
142
+ const same = aRank === bRank;
143
+ if (same) {
144
+ if (aKeyIndex === bKeyIndex) {
145
+ return baseSort(a, b);
146
+ }
147
+ else {
148
+ return aKeyIndex < bKeyIndex ? aFirst : bFirst;
149
+ }
150
+ }
151
+ else {
152
+ return aRank > bRank ? aFirst : bFirst;
153
+ }
154
+ };
155
+ let prepareValueForComparison = (value, { keepDiacritics }) => {
156
+ value = `${value}`;
157
+ if (!keepDiacritics) {
158
+ value = removeAccents(value);
159
+ }
160
+ return value;
161
+ };
162
+ let getItemValues = (item, key) => {
163
+ if (typeof key === "object") {
164
+ key = key.key;
165
+ }
166
+ let value;
167
+ if (typeof key === "function") {
168
+ value = key(item);
169
+ }
170
+ else if (item == null) {
171
+ value = null;
172
+ }
173
+ else if (Object.hasOwnProperty.call(item, key)) {
174
+ value = item[key];
175
+ }
176
+ else if (key.includes(".")) {
177
+ return getNestedValues(key, item);
178
+ }
179
+ else {
180
+ value = null;
181
+ }
182
+ if (value == null) {
183
+ return [];
184
+ }
185
+ if (Array.isArray(value)) {
186
+ return value;
187
+ }
188
+ return [String(value)];
189
+ };
190
+ let getNestedValues = (path, item) => {
191
+ const keys = path.split(".");
192
+ let values = [item];
193
+ for (let i = 0, I = keys.length; i < I; i++) {
194
+ const nestedKey = keys[i];
195
+ let nestedValues = [];
196
+ for (let j = 0, J = values.length; j < J; j++) {
197
+ const nestedItem = values[j];
198
+ if (nestedItem == null)
199
+ continue;
200
+ if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
201
+ const nestedValue = nestedItem[nestedKey];
202
+ if (nestedValue != null) {
203
+ nestedValues.push(nestedValue);
204
+ }
205
+ }
206
+ else if (nestedKey === "*") {
207
+ nestedValues = nestedValues.concat(nestedItem);
208
+ }
209
+ }
210
+ values = nestedValues;
211
+ }
212
+ if (Array.isArray(values[0])) {
213
+ const result = [];
214
+ return result.concat(...values);
215
+ }
216
+ return values;
217
+ };
218
+ let getAllValuesToRank = (item, keys) => {
219
+ const allValues = [];
220
+ for (let j = 0, J = keys.length; j < J; j++) {
221
+ const key = keys[j];
222
+ const attributes = getKeyAttributes(key);
223
+ const itemValues = getItemValues(item, key);
224
+ for (let i = 0, I = itemValues.length; i < I; i++) {
225
+ allValues.push({
226
+ itemValue: itemValues[i],
227
+ attributes,
228
+ });
229
+ }
230
+ }
231
+ return allValues;
232
+ };
233
+ const defaultKeyAttributes = {
234
+ maxRanking: Infinity,
235
+ minRanking: -Infinity,
236
+ };
237
+ let getKeyAttributes = (key) => isString(key) ? defaultKeyAttributes : { ...defaultKeyAttributes, ...key };
238
+ export { matchSorter, defaultBaseSortFn };
239
+ export default matchSorter;
package/mbToBytes.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let mbToBytes: (bytes: number) => number;
2
+ export default mbToBytes;
package/mbToBytes.js ADDED
@@ -0,0 +1,2 @@
1
+ export let mbToBytes = (bytes) => bytes * 1000 * 1000;
2
+ export default mbToBytes;
package/mergeObjects.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let mergeObjects: <T extends object = object>(target: T, ...sources: Partial<T>[]) => T;
2
+ export default mergeObjects;
@@ -0,0 +1,29 @@
1
+ import { isObject } from "./isObject";
2
+ import { isUndefined } from "./isUndefined";
3
+ export let mergeObjects = (target, ...sources) => {
4
+ if (!sources.length) {
5
+ return target;
6
+ }
7
+ const source = sources.shift();
8
+ if (source === undefined) {
9
+ return target;
10
+ }
11
+ if (isObject(target) && isObject(source)) {
12
+ Object.keys(source).forEach((_key) => {
13
+ const key = _key;
14
+ if (isObject(source[key])) {
15
+ if (!target[key]) {
16
+ target[key] = {};
17
+ }
18
+ mergeObjects(target[key], source[key]);
19
+ }
20
+ else {
21
+ if (!isUndefined(source[key])) {
22
+ target[key] = source[key];
23
+ }
24
+ }
25
+ });
26
+ }
27
+ return mergeObjects(target, ...sources);
28
+ };
29
+ export default mergeObjects;
@@ -1,2 +1,3 @@
1
1
  import type { AnyQueryParams } from "./location";
2
2
  export declare let mergeUrlQueryParams: <T extends AnyQueryParams>(oldParams?: NonNullable<AnyQueryParams>, newParams?: NonNullable<AnyQueryParams>) => T;
3
+ export default mergeUrlQueryParams;
@@ -0,0 +1,14 @@
1
+ import { isNull } from "./isNull";
2
+ export let mergeUrlQueryParams = (oldParams = {}, newParams = {}) => {
3
+ for (const key in newParams) {
4
+ const value = newParams[key];
5
+ if (oldParams[key] && isNull(value)) {
6
+ delete oldParams[key];
7
+ }
8
+ else {
9
+ oldParams[key] = value;
10
+ }
11
+ }
12
+ return oldParams;
13
+ };
14
+ export default mergeUrlQueryParams;
@@ -1 +1,2 @@
1
1
  export declare let moveSortableArrayItemByKey: <T, K extends keyof T>(items: T[], key: K, fromItem: Pick<T, K>, toItem: Pick<T, K>) => T[];
2
+ export default moveSortableArrayItemByKey;
@@ -0,0 +1,9 @@
1
+ export 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
+ };
9
+ export default moveSortableArrayItemByKey;
package/noop.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let noop: () => void | undefined;
2
+ export default noop;
package/noop.js ADDED
@@ -0,0 +1,2 @@
1
+ export let noop = () => void 0;
2
+ export default noop;
package/normaliseUrl.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let normaliseUrl: (absoluteUrl?: string) => string;
2
+ export default normaliseUrl;
@@ -0,0 +1,3 @@
1
+ import { removeTrailingSlash } from "./removeTrailingSlash";
2
+ export let normaliseUrl = (absoluteUrl = "") => removeTrailingSlash(absoluteUrl.replace(/(:\/\/)|(\/)+/g, "$1$2"));
3
+ export default normaliseUrl;
@@ -1 +1,2 @@
1
1
  export declare let normaliseUrlPathname: (pathname?: string) => string;
2
+ export default normaliseUrlPathname;
@@ -0,0 +1,3 @@
1
+ import { removeTrailingSlash } from "./removeTrailingSlash";
2
+ export let normaliseUrlPathname = (pathname = "") => removeTrailingSlash(pathname.replace(/\/+/g, "/"));
3
+ export default normaliseUrlPathname;
package/objectFlat.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export declare let objectFlat: <TReturn extends {
2
2
  [key: string]: unknown;
3
3
  }, TInput extends object = object>(obj: TInput, delimiter?: string, parent?: string) => TReturn;
4
+ export default objectFlat;
package/objectFlat.js ADDED
@@ -0,0 +1,17 @@
1
+ export let objectFlat = (obj, delimiter = ".", parent = "") => {
2
+ return Object.keys(obj).reduce((acc, _key) => {
3
+ const key = _key;
4
+ const propName = (parent ? `${parent}${delimiter}${key}` : key);
5
+ if (typeof obj[key] === "object") {
6
+ acc = {
7
+ ...acc,
8
+ ...objectFlat(obj[key], delimiter, propName),
9
+ };
10
+ }
11
+ else {
12
+ acc[propName] = obj[key];
13
+ }
14
+ return acc;
15
+ }, {});
16
+ };
17
+ export default objectFlat;
package/objectFlip.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let objectFlip: <T extends PropertyKey, U extends PropertyKey>(input: Record<T, U>, keyTransformer?: ((key: string) => T) | undefined) => Record<U, T>;
2
+ export default objectFlip;
package/objectFlip.js ADDED
@@ -0,0 +1,5 @@
1
+ export let objectFlip = (input, keyTransformer) => Object.fromEntries(Object.entries(input).map(([key, value]) => [
2
+ value,
3
+ keyTransformer ? keyTransformer(key) : key,
4
+ ]));
5
+ export default objectFlip;
@@ -3,3 +3,4 @@ export type ObjectMergeWithDefaults<Defaults, Overrides> = Overrides extends und
3
3
  [K in keyof Overrides]-?: Overrides[K] extends undefined ? K extends keyof Defaults ? Defaults[K] : never : K extends keyof Defaults ? ObjectMergeWithDefaults<Defaults[K], Overrides[K]> : Overrides[K];
4
4
  } : Overrides;
5
5
  export declare let objectMergeWithDefaults: <D extends PlainObject, O extends PlainObject>(defaults: D, overrides?: O | undefined) => ObjectMergeWithDefaults<D, O>;
6
+ export default objectMergeWithDefaults;
@@ -0,0 +1,21 @@
1
+ import { isObject } from "./isObject";
2
+ export let objectMergeWithDefaults = (defaults, overrides) => overrides
3
+ ? Object.keys(overrides).reduce((result, _key) => {
4
+ const keyDefaults = _key;
5
+ const keyOverrides = _key;
6
+ if (isObject(overrides[keyOverrides])) {
7
+ if (!defaults[keyDefaults]) {
8
+ defaults[keyDefaults] = {};
9
+ }
10
+ result[keyDefaults] = objectMergeWithDefaults(defaults[keyDefaults], overrides[keyOverrides]);
11
+ }
12
+ else {
13
+ result[keyDefaults] =
14
+ overrides[keyOverrides] === undefined
15
+ ? defaults[keyDefaults]
16
+ : overrides[keyOverrides];
17
+ }
18
+ return result;
19
+ }, { ...defaults })
20
+ : defaults;
21
+ export default objectMergeWithDefaults;
package/objectOmit.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let objectOmit: <T extends object, Keys extends (keyof T)[]>(object: T, keys: Keys) => Omit<T, Keys[number]>;
2
+ export default objectOmit;
package/objectOmit.js ADDED
@@ -0,0 +1,8 @@
1
+ export let objectOmit = (object, keys) => Object.keys(object).reduce((output, key) => {
2
+ if (!keys.includes(key)) {
3
+ output[key] =
4
+ object[key];
5
+ }
6
+ return output;
7
+ }, {});
8
+ export default objectOmit;
package/objectPick.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let objectPick: <T extends object, Keys extends (keyof T)[]>(object: T, keys: Keys) => Pick<T, Keys[number]>;
2
+ export default objectPick;
package/objectPick.js ADDED
@@ -0,0 +1,9 @@
1
+ export let objectPick = (object, keys) => {
2
+ const output = {};
3
+ let len = keys.length;
4
+ while (len--) {
5
+ output[keys[len]] = object[keys[len]];
6
+ }
7
+ return output;
8
+ };
9
+ export default objectPick;
package/objectSort.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export declare let objectSort: <T extends object>(data: T, compareFn?: ((a: [Extract<keyof T, string>, T[Extract<keyof T, string>]], b: [Extract<keyof T, string>, T[Extract<keyof T, string>]]) => number) | undefined) => {
2
2
  [k: string]: any;
3
3
  };
4
+ export default objectSort;
package/objectSort.js ADDED
@@ -0,0 +1,2 @@
1
+ export let objectSort = (data, compareFn) => Object.fromEntries(Object.entries(data).sort(compareFn));
2
+ export default objectSort;
@@ -1,3 +1,4 @@
1
1
  export declare let objectSortByKeysMatching: <T extends object>(data: T, keyMatch: keyof T) => {
2
2
  [k: string]: any;
3
3
  };
4
+ export default objectSortByKeysMatching;
@@ -0,0 +1,3 @@
1
+ import { objectSort } from "./objectSort";
2
+ export let objectSortByKeysMatching = (data, keyMatch) => objectSort(data, ([a], [b]) => (a === keyMatch ? -1 : a.localeCompare(b)));
3
+ export default objectSortByKeysMatching;
@@ -1 +1,2 @@
1
1
  export declare let objectToArray: <T extends object, R>(obj: T, iterator: (key: keyof T, index: number) => R) => R[];
2
+ export default objectToArray;
@@ -0,0 +1,2 @@
1
+ export let objectToArray = (obj, iterator) => Object.keys(obj).map(iterator);
2
+ export default objectToArray;
package/package.json CHANGED
@@ -14,5 +14,5 @@
14
14
  },
15
15
  "module": "./index.esm.js",
16
16
  "main": "./index.cjs.js",
17
- "version": "2.0.0-beta.72"
17
+ "version": "2.0.0-beta.74"
18
18
  }
package/parseCookie.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import type { CookieAttributesServer } from "./cookie";
2
2
  export declare let parseCookie: <T extends Record<string, unknown> = Record<string, string>>(str: string, attributes?: CookieAttributesServer) => T;
3
+ export default parseCookie;
package/parseCookie.js ADDED
@@ -0,0 +1,33 @@
1
+ let tryDecode = (str, decode) => {
2
+ try {
3
+ return decode(str);
4
+ }
5
+ catch (e) {
6
+ return str;
7
+ }
8
+ };
9
+ export let parseCookie = (str, attributes = {}) => {
10
+ if (typeof str !== "string") {
11
+ throw new TypeError("argument str must be a string");
12
+ }
13
+ const obj = {};
14
+ const pairs = str.split(";");
15
+ const { decode = decodeURIComponent } = attributes;
16
+ for (let i = 0; i < pairs.length; i++) {
17
+ const pair = pairs[i];
18
+ const index = pair.indexOf("=");
19
+ if (index < 0) {
20
+ continue;
21
+ }
22
+ const key = pair.substring(0, index).trim();
23
+ if (undefined == obj[key]) {
24
+ let val = pair.substring(index + 1, pair.length).trim();
25
+ if (val[0] === '"') {
26
+ val = val.slice(1, -1);
27
+ }
28
+ obj[key] = tryDecode(val, decode);
29
+ }
30
+ }
31
+ return obj;
32
+ };
33
+ export default parseCookie;
package/parseURL.d.ts CHANGED
@@ -8,3 +8,4 @@ export declare let parseURL: (url: string) => {
8
8
  search: string;
9
9
  hash: string;
10
10
  } | null;
11
+ export default parseURL;
package/parseURL.js ADDED
@@ -0,0 +1,14 @@
1
+ export let parseURL = (url) => {
2
+ const match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
3
+ return (match && {
4
+ href: url,
5
+ protocol: match[1],
6
+ host: match[2],
7
+ hostname: match[3],
8
+ port: match[4],
9
+ pathname: match[5],
10
+ search: match[6],
11
+ hash: match[7],
12
+ });
13
+ };
14
+ export default parseURL;
@@ -4,4 +4,4 @@ export declare let quaranteneProps: <TProps extends Record<never, never>, TSupec
4
4
  type QuaranteneProps<TProps extends Record<never, never>> = readonly (keyof {
5
5
  [K in keyof TProps]?: TProps[K];
6
6
  })[];
7
- export {};
7
+ export default quaranteneProps;
@@ -0,0 +1,16 @@
1
+ export let quaranteneProps = (props, propsKeysToQuarantene) => {
2
+ const healthyProps = {
3
+ _: {},
4
+ };
5
+ for (const key in props) {
6
+ const prop = props[key];
7
+ if (propsKeysToQuarantene.includes(key)) {
8
+ healthyProps._[key] = prop;
9
+ }
10
+ else {
11
+ healthyProps[key] = prop;
12
+ }
13
+ }
14
+ return healthyProps;
15
+ };
16
+ export default quaranteneProps;
package/randomInt.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let randomInt: (min: number, max: number) => number;
2
+ export default randomInt;
package/randomInt.js ADDED
@@ -0,0 +1,2 @@
1
+ export let randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
2
+ export default randomInt;
package/randomKey.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare let randomKey: <T extends Record<string | number, unknown>>(obj: T) => keyof T;
2
+ export default randomKey;
package/randomKey.js ADDED
@@ -0,0 +1,5 @@
1
+ export let randomKey = (obj) => {
2
+ const keys = Object.keys(obj);
3
+ return keys[(keys.length * Math.random()) << 0];
4
+ };
5
+ export default randomKey;
package/readCookie.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare function readCookie<T extends Record<string, unknown> = Record<string, string>>(name?: null): T;
2
2
  export declare function readCookie<T extends Record<string, unknown> = Record<string, string>, N extends keyof T = keyof T>(name: N): T[N];
3
+ export default readCookie;
package/readCookie.js ADDED
@@ -0,0 +1,34 @@
1
+ let converterRead = (value) => {
2
+ if (value[0] === '"') {
3
+ value = value.slice(1, -1);
4
+ }
5
+ return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
6
+ };
7
+ export function readCookie(name) {
8
+ if (typeof document === "undefined") {
9
+ if (process.env["NODE_ENV"] === "development") {
10
+ console.warn("[@koine/utils:readCookie] document is undefined");
11
+ }
12
+ return name ? "" : {};
13
+ }
14
+ const cookies = document.cookie ? document.cookie.split("; ") : [];
15
+ const all = {};
16
+ for (let i = 0; i < cookies.length; i++) {
17
+ const parts = cookies[i].split("=");
18
+ const value = parts.slice(1).join("=");
19
+ try {
20
+ const found = decodeURIComponent(parts[0]);
21
+ all[found] = converterRead(value);
22
+ if (name === found) {
23
+ break;
24
+ }
25
+ }
26
+ catch (e) {
27
+ if (process.env["NODE_ENV"] === "development") {
28
+ console.warn("[@koine/utils:readCookie] failed to decode", value);
29
+ }
30
+ }
31
+ }
32
+ return name ? all[name] : all;
33
+ }
34
+ export default readCookie;
@@ -1,2 +1,3 @@
1
1
  import type { AccentsSet } from "./accentSets";
2
2
  export declare let removeAccents: (text?: string, sets?: AccentsSet[]) => string;
3
+ export default removeAccents;
@@ -0,0 +1,10 @@
1
+ import { accentsSets } from "./accentSets";
2
+ export let removeAccents = (text = "", sets = accentsSets) => {
3
+ let len = sets.length;
4
+ while (len--) {
5
+ const [to, from] = sets[len];
6
+ text = text.replace(new RegExp(`[${from}]`, "gi"), to);
7
+ }
8
+ return text;
9
+ };
10
+ export default removeAccents;
package/removeCookie.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { type CookieAttributesClient } from "./cookie";
2
2
  export declare let removeCookie: (name: string, attributes?: CookieAttributesClient) => void;
3
+ export default removeCookie;
@@ -0,0 +1,10 @@
1
+ import { defaultAttributesClient } from "./cookie";
2
+ import { setCookie } from "./setCookie";
3
+ export let removeCookie = (name, attributes = {}) => {
4
+ setCookie(name, "", {
5
+ ...defaultAttributesClient,
6
+ ...attributes,
7
+ expires: -1,
8
+ });
9
+ };
10
+ export default removeCookie;