@koine/utils 2.0.0-beta.1 → 2.0.0-beta.11

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 (331) hide show
  1. package/Defer.mjs +6 -5
  2. package/Emitter.d.ts +3 -1
  3. package/Emitter.mjs +16 -17
  4. package/README.md +6 -1
  5. package/accentSets.d.ts +3 -2
  6. package/accentSets.mjs +116 -31
  7. package/addOrReplaceAtIdx.d.ts +4 -0
  8. package/addOrReplaceAtIdx.mjs +13 -6
  9. package/areEqual.d.ts +1 -1
  10. package/areEqual.mjs +17 -23
  11. package/arrayOfAll.d.ts +1 -2
  12. package/arrayOfAll.mjs +2 -8
  13. package/arraySum.d.ts +2 -1
  14. package/arraySum.mjs +3 -5
  15. package/arrayToLookup.mjs +2 -4
  16. package/buildUrlQueryString.mjs +11 -14
  17. package/capitalize.d.ts +2 -1
  18. package/capitalize.mjs +5 -6
  19. package/changeUrlPath.mjs +2 -3
  20. package/chunkByChunks.d.ts +1 -1
  21. package/chunkByChunks.mjs +18 -21
  22. package/chunkBySize.mjs +3 -4
  23. package/clamp.mjs +1 -2
  24. package/clsx.d.ts +6 -2
  25. package/clsx.mjs +14 -15
  26. package/convertRange.d.ts +3 -1
  27. package/convertRange.mjs +5 -4
  28. package/cookie.d.ts +13 -1
  29. package/cookie.mjs +8 -3
  30. package/createPalette.d.ts +3 -1
  31. package/createPalette.mjs +17 -7
  32. package/debounce.mjs +9 -17
  33. package/debouncePromise.d.ts +22 -4
  34. package/debouncePromise.mjs +73 -3
  35. package/debounceRaf.d.ts +1 -1
  36. package/debounceRaf.mjs +6 -11
  37. package/decode.mjs +2 -3
  38. package/encode.mjs +2 -3
  39. package/ensureInt.mjs +1 -4
  40. package/env.mjs +0 -1
  41. package/errorToString.d.ts +2 -1
  42. package/errorToString.mjs +3 -5
  43. package/findDuplicatedIndexes.mjs +4 -5
  44. package/forin.d.ts +2 -1
  45. package/forin.mjs +4 -4
  46. package/gbToBytes.mjs +1 -2
  47. package/getEmptyArray.d.ts +0 -1
  48. package/getEmptyArray.mjs +4 -4
  49. package/getKeys.d.ts +2 -1
  50. package/getKeys.mjs +3 -3
  51. package/getMediaQueryWidthResolvers.d.ts +6 -0
  52. package/getMediaQueryWidthResolvers.mjs +49 -50
  53. package/getMediaQueryWidthTailwindScreens.d.ts +4 -0
  54. package/getMediaQueryWidthTailwindScreens.mjs +22 -15
  55. package/getNonce.mjs +1 -2
  56. package/getParamAmong.d.ts +3 -2
  57. package/getParamAmong.mjs +5 -6
  58. package/getParamAsInt.d.ts +2 -2
  59. package/getParamAsInt.mjs +4 -6
  60. package/getParamAsString.d.ts +1 -1
  61. package/getParamAsString.mjs +2 -3
  62. package/getType.d.ts +0 -3
  63. package/getType.mjs +2 -7
  64. package/getUrlHashParams.mjs +2 -4
  65. package/getUrlHashPathname.mjs +1 -3
  66. package/getUrlPathnameParts.mjs +2 -7
  67. package/getUrlQueryParams.d.ts +3 -4
  68. package/getUrlQueryParams.mjs +10 -22
  69. package/imgEmptyPixel.mjs +1 -2
  70. package/index.d.ts +5 -2
  71. package/index.mjs +2 -2
  72. package/invariant.mjs +6 -8
  73. package/isAnyObject.mjs +1 -2
  74. package/isArray.mjs +1 -2
  75. package/isBlob.mjs +1 -2
  76. package/isBoolean.mjs +1 -2
  77. package/isBrowser.mjs +1 -2
  78. package/isBrowserNow.mjs +1 -2
  79. package/isDate.mjs +1 -2
  80. package/isEmptyArray.mjs +1 -2
  81. package/isEmptyObject.mjs +1 -2
  82. package/isEmptyString.mjs +1 -2
  83. package/isError.mjs +1 -2
  84. package/isExternalUrl.mjs +4 -6
  85. package/isFile.mjs +1 -2
  86. package/isFloat.mjs +1 -2
  87. package/isFormData.mjs +1 -2
  88. package/isFullArray.mjs +1 -2
  89. package/isFullObject.mjs +1 -2
  90. package/isFullString.mjs +1 -2
  91. package/isFunction.mjs +1 -2
  92. package/isInt.mjs +1 -2
  93. package/isMap.mjs +1 -2
  94. package/isNaNValue.mjs +1 -2
  95. package/isNegativeNumber.mjs +1 -2
  96. package/isNull.mjs +1 -2
  97. package/isNullOrUndefined.mjs +1 -2
  98. package/isNumber.mjs +1 -2
  99. package/isObject.mjs +1 -2
  100. package/isObjectLike.mjs +1 -2
  101. package/isOneOf.mjs +1 -7
  102. package/isPlainObject.mjs +3 -6
  103. package/isPositiveNumber.mjs +1 -2
  104. package/isPrimitive.mjs +5 -11
  105. package/isPromise.mjs +1 -2
  106. package/isRegExp.mjs +1 -2
  107. package/isServer.mjs +1 -2
  108. package/isServerNow.mjs +1 -2
  109. package/isSet.mjs +1 -2
  110. package/isString.mjs +1 -2
  111. package/isSymbol.mjs +1 -2
  112. package/isType.mjs +3 -5
  113. package/isUndefined.mjs +1 -2
  114. package/isWeakMap.mjs +1 -2
  115. package/isWeakSet.mjs +1 -2
  116. package/kbToBytes.mjs +1 -2
  117. package/location.mjs +3 -1
  118. package/lowercase.mjs +1 -4
  119. package/mapListBy.mjs +2 -5
  120. package/matchSorter.mjs +110 -128
  121. package/mbToBytes.mjs +1 -2
  122. package/mergeObjects.d.ts +2 -2
  123. package/mergeObjects.mjs +13 -16
  124. package/mergeUrlQueryParams.d.ts +0 -1
  125. package/mergeUrlQueryParams.mjs +4 -9
  126. package/moveSortableArrayItemByKey.d.ts +1 -1
  127. package/moveSortableArrayItemByKey.mjs +9 -9
  128. package/noop.mjs +1 -2
  129. package/normaliseUrl.mjs +1 -3
  130. package/normaliseUrlPathname.mjs +1 -3
  131. package/objectOmit.d.ts +1 -1
  132. package/objectOmit.mjs +4 -6
  133. package/objectPick.d.ts +1 -1
  134. package/objectPick.mjs +5 -6
  135. package/package.json +7 -11
  136. package/parseCookie.mjs +11 -15
  137. package/parseURL.mjs +5 -6
  138. package/quaranteneProps.d.ts +1 -1
  139. package/quaranteneProps.mjs +7 -9
  140. package/randomInt.mjs +1 -2
  141. package/randomKey.mjs +3 -4
  142. package/readCookie.d.ts +5 -0
  143. package/readCookie.mjs +7 -8
  144. package/removeAccents.mjs +5 -8
  145. package/removeCookie.d.ts +0 -4
  146. package/removeCookie.mjs +6 -9
  147. package/removeDuplicates.mjs +0 -1
  148. package/removeDuplicatesByKey.mjs +5 -7
  149. package/removeDuplicatesComparing.mjs +3 -4
  150. package/removeIndexesFromArray.mjs +3 -4
  151. package/removeTrailingSlash.mjs +1 -3
  152. package/removeUrlQueryParams.d.ts +0 -1
  153. package/removeUrlQueryParams.mjs +5 -8
  154. package/render.d.ts +2 -1
  155. package/render.mjs +45 -99
  156. package/roundTo.mjs +15 -17
  157. package/serializeCookie.d.ts +1 -5
  158. package/serializeCookie.mjs +10 -20
  159. package/setCookie.d.ts +0 -4
  160. package/setCookie.mjs +13 -20
  161. package/shuffle.d.ts +7 -6
  162. package/shuffle.mjs +17 -16
  163. package/slugify.d.ts +2 -1
  164. package/slugify.mjs +15 -12
  165. package/split.d.ts +4 -0
  166. package/split.mjs +4 -1
  167. package/swapMap.d.ts +1 -1
  168. package/swapMap.mjs +4 -6
  169. package/throttle.d.ts +2 -1
  170. package/throttle.mjs +6 -12
  171. package/titleCase.d.ts +4 -3
  172. package/titleCase.mjs +5 -9
  173. package/toNumber.mjs +1 -2
  174. package/toRgba.mjs +3 -5
  175. package/transformToUrlPathname.mjs +2 -5
  176. package/truncate.d.ts +1 -1
  177. package/truncate.mjs +2 -9
  178. package/tryUntil.d.ts +4 -1
  179. package/tryUntil.mjs +11 -11
  180. package/types.mjs +2 -1
  181. package/typings.d.ts +1 -6
  182. package/uid.mjs +3 -5
  183. package/updateLinkParams.mjs +2 -3
  184. package/updateUrlQueryParams.d.ts +0 -1
  185. package/updateUrlQueryParams.mjs +3 -8
  186. package/uppercase.d.ts +1 -0
  187. package/uppercase.mjs +2 -4
  188. package/uuid.mjs +2 -5
  189. package/uuidNumeric.mjs +1 -2
  190. package/wait.mjs +1 -4
  191. package/without.mjs +1 -3
  192. package/Defer.js +0 -30
  193. package/Emitter.js +0 -42
  194. package/accentSets.js +0 -41
  195. package/addOrReplaceAtIdx.js +0 -23
  196. package/areEqual.js +0 -81
  197. package/arrayOfAll.js +0 -36
  198. package/arraySum.js +0 -13
  199. package/arrayToLookup.js +0 -17
  200. package/buildUrlQueryString.js +0 -36
  201. package/capitalize.js +0 -16
  202. package/changeUrlPath.js +0 -23
  203. package/chunkByChunks.js +0 -41
  204. package/chunkBySize.js +0 -16
  205. package/clamp.js +0 -14
  206. package/clsx.js +0 -53
  207. package/convertRange.js +0 -20
  208. package/cookie.js +0 -13
  209. package/createPalette.js +0 -26
  210. package/debounce.js +0 -33
  211. package/debouncePromise.js +0 -12
  212. package/debounceRaf.js +0 -31
  213. package/decode.js +0 -14
  214. package/encode.js +0 -14
  215. package/ensureInt.js +0 -13
  216. package/env.js +0 -3
  217. package/errorToString.js +0 -15
  218. package/findDuplicatedIndexes.js +0 -18
  219. package/forin.js +0 -15
  220. package/gbToBytes.js +0 -11
  221. package/getEmptyArray.js +0 -20
  222. package/getKeys.js +0 -12
  223. package/getMediaQueryWidthResolvers.js +0 -72
  224. package/getMediaQueryWidthTailwindScreens.js +0 -33
  225. package/getNonce.js +0 -13
  226. package/getParamAmong.js +0 -22
  227. package/getParamAsInt.js +0 -25
  228. package/getParamAsString.js +0 -19
  229. package/getType.js +0 -23
  230. package/getUrlHashParams.js +0 -20
  231. package/getUrlHashPathname.js +0 -17
  232. package/getUrlPathnameParts.js +0 -25
  233. package/getUrlQueryParams.js +0 -43
  234. package/imgEmptyPixel.js +0 -10
  235. package/index.js +0 -267
  236. package/invariant.js +0 -38
  237. package/isAnyObject.js +0 -15
  238. package/isArray.js +0 -15
  239. package/isBlob.js +0 -15
  240. package/isBoolean.js +0 -15
  241. package/isBrowser.js +0 -9
  242. package/isBrowserNow.js +0 -12
  243. package/isDate.js +0 -15
  244. package/isEmptyArray.js +0 -15
  245. package/isEmptyObject.js +0 -15
  246. package/isEmptyString.js +0 -13
  247. package/isError.js +0 -15
  248. package/isExternalUrl.js +0 -26
  249. package/isFile.js +0 -15
  250. package/isFloat.js +0 -15
  251. package/isFormData.js +0 -15
  252. package/isFullArray.js +0 -15
  253. package/isFullObject.js +0 -15
  254. package/isFullString.js +0 -15
  255. package/isFunction.js +0 -13
  256. package/isInt.js +0 -15
  257. package/isMap.js +0 -15
  258. package/isNaNValue.js +0 -15
  259. package/isNegativeNumber.js +0 -15
  260. package/isNull.js +0 -15
  261. package/isNullOrUndefined.js +0 -14
  262. package/isNumber.js +0 -17
  263. package/isObject.js +0 -15
  264. package/isObjectLike.js +0 -17
  265. package/isOneOf.js +0 -14
  266. package/isPlainObject.js +0 -18
  267. package/isPositiveNumber.js +0 -15
  268. package/isPrimitive.js +0 -25
  269. package/isPromise.js +0 -15
  270. package/isRegExp.js +0 -15
  271. package/isServer.js +0 -12
  272. package/isServerNow.js +0 -12
  273. package/isSet.js +0 -15
  274. package/isString.js +0 -15
  275. package/isSymbol.js +0 -15
  276. package/isType.js +0 -27
  277. package/isUndefined.js +0 -15
  278. package/isWeakMap.js +0 -15
  279. package/isWeakSet.js +0 -15
  280. package/kbToBytes.js +0 -11
  281. package/location.js +0 -2
  282. package/lowercase.js +0 -13
  283. package/mapListBy.js +0 -18
  284. package/matchSorter.js +0 -374
  285. package/mbToBytes.js +0 -11
  286. package/mergeObjects.js +0 -41
  287. package/mergeUrlQueryParams.js +0 -27
  288. package/moveSortableArrayItemByKey.js +0 -21
  289. package/noop.js +0 -11
  290. package/normaliseUrl.js +0 -20
  291. package/normaliseUrlPathname.js +0 -19
  292. package/objectOmit.js +0 -23
  293. package/objectPick.js +0 -19
  294. package/parseCookie.js +0 -52
  295. package/parseURL.js +0 -24
  296. package/quaranteneProps.js +0 -37
  297. package/randomInt.js +0 -13
  298. package/randomKey.js +0 -15
  299. package/readCookie.js +0 -38
  300. package/removeAccents.js +0 -19
  301. package/removeCookie.js +0 -19
  302. package/removeDuplicates.js +0 -13
  303. package/removeDuplicatesByKey.js +0 -24
  304. package/removeDuplicatesComparing.js +0 -14
  305. package/removeIndexesFromArray.js +0 -18
  306. package/removeTrailingSlash.js +0 -14
  307. package/removeUrlQueryParams.js +0 -26
  308. package/render.js +0 -169
  309. package/roundTo.js +0 -38
  310. package/serializeCookie.js +0 -108
  311. package/setCookie.js +0 -62
  312. package/shuffle.js +0 -36
  313. package/slugify.js +0 -27
  314. package/split.js +0 -8
  315. package/swapMap.js +0 -18
  316. package/throttle.js +0 -30
  317. package/titleCase.js +0 -15
  318. package/toNumber.js +0 -12
  319. package/toRgba.js +0 -20
  320. package/transformToUrlPathname.js +0 -21
  321. package/truncate.js +0 -17
  322. package/tryUntil.js +0 -31
  323. package/types.js +0 -2
  324. package/uid.js +0 -16
  325. package/updateLinkParams.js +0 -19
  326. package/updateUrlQueryParams.js +0 -23
  327. package/uppercase.js +0 -13
  328. package/uuid.js +0 -17
  329. package/uuidNumeric.js +0 -10
  330. package/wait.js +0 -13
  331. package/without.js +0 -56
package/matchSorter.js DELETED
@@ -1,374 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultBaseSortFn = exports.matchSorter = void 0;
4
- var tslib_1 = require("tslib");
5
- /**
6
- * @file
7
- *
8
- * Slightly adapted from Kent C. Dodd's [match-sorter](https://github.com/kentcdodds/match-sorter)
9
- * differences are:
10
- * - less exports
11
- * - smaller output
12
- * - no external deps
13
- *
14
- * TODO: turn objects into arrays for smaller output?
15
- *
16
- * @name match-sorter
17
- * @license MIT license.
18
- * @copyright (c) 2020 Kent C. Dodds
19
- * @author Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)
20
- */
21
- var removeAccents_1 = tslib_1.__importDefault(require("./removeAccents"));
22
- var RANKING_CASE_SENSITIVE_EQUAL = 7;
23
- var RANKING_EQUAL = 6;
24
- var RANKING_STARTS_WITH = 5;
25
- var RANKING_WORD_STARTS_WITH = 4;
26
- var RANKING_CONTAINS = 3;
27
- var RANKING_ACRONYM = 2;
28
- var RANKING_MATCHES = 1;
29
- var RANKING_NO_MATCH = 0;
30
- var defaultBaseSortFn = function (a, b) {
31
- return String(a.rankedValue).localeCompare(String(b.rankedValue));
32
- };
33
- exports.defaultBaseSortFn = defaultBaseSortFn;
34
- /**
35
- * Takes an array of items and a value and returns a new array with the items that match the given value
36
- * @param {Array} items - the items to sort
37
- * @param {String} value - the value to use for ranking
38
- * @param {Object} options - Some options to configure the sorter
39
- * @return {Array} - the new sorted array
40
- */
41
- function matchSorter(items, value, options) {
42
- if (options === void 0) { options = {}; }
43
- var keys = options.keys, _a = options.threshold, threshold = _a === void 0 ? RANKING_MATCHES : _a, _b = options.baseSort, baseSort = _b === void 0 ? defaultBaseSortFn : _b, _c = options.sorter, sorter = _c === void 0 ? function (matchedItems) {
44
- return matchedItems.sort(function (a, b) { return sortRankedValues(a, b, baseSort); });
45
- } : _c;
46
- var matchedItems = items.reduce(reduceItemsToRanked, []);
47
- return sorter(matchedItems).map(function (_a) {
48
- var item = _a.item;
49
- return item;
50
- });
51
- function reduceItemsToRanked(matches, item, index) {
52
- var rankingInfo = getHighestRanking(item, keys, value, options);
53
- var rank = rankingInfo.rank, _a = rankingInfo.keyThreshold, keyThreshold = _a === void 0 ? threshold : _a;
54
- if (rank >= keyThreshold) {
55
- matches.push(tslib_1.__assign(tslib_1.__assign({}, rankingInfo), { item: item, index: index }));
56
- }
57
- return matches;
58
- }
59
- }
60
- exports.matchSorter = matchSorter;
61
- /**
62
- * Gets the highest ranking for value for the given item based on its values for the given keys
63
- * @param {*} item - the item to rank
64
- * @param {Array} keys - the keys to get values from the item for the ranking
65
- * @param {String} value - the value to rank against
66
- * @param {Object} options - options to control the ranking
67
- * @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking
68
- */
69
- function getHighestRanking(item, keys, value, options) {
70
- if (!keys) {
71
- // if keys is not specified, then we assume the item given is ready to be matched
72
- var stringItem = item;
73
- return {
74
- // ends up being duplicate of 'item' in matches but consistent
75
- rankedValue: stringItem,
76
- rank: getMatchRanking(stringItem, value, options),
77
- keyIndex: -1,
78
- keyThreshold: options.threshold,
79
- };
80
- }
81
- var valuesToRank = getAllValuesToRank(item, keys);
82
- return valuesToRank.reduce(function (_a, _b, i) {
83
- var rank = _a.rank, rankedValue = _a.rankedValue, keyIndex = _a.keyIndex, keyThreshold = _a.keyThreshold;
84
- var itemValue = _b.itemValue, attributes = _b.attributes;
85
- var newRank = getMatchRanking(itemValue, value, options);
86
- var newRankedValue = rankedValue;
87
- var minRanking = attributes.minRanking, maxRanking = attributes.maxRanking, threshold = attributes.threshold;
88
- if (newRank < minRanking && newRank >= RANKING_MATCHES) {
89
- newRank = minRanking;
90
- }
91
- else if (newRank > maxRanking) {
92
- newRank = maxRanking;
93
- }
94
- if (newRank > rank) {
95
- rank = newRank;
96
- keyIndex = i;
97
- keyThreshold = threshold;
98
- newRankedValue = itemValue;
99
- }
100
- return { rankedValue: newRankedValue, rank: rank, keyIndex: keyIndex, keyThreshold: keyThreshold };
101
- }, {
102
- rankedValue: item,
103
- rank: RANKING_NO_MATCH,
104
- keyIndex: -1,
105
- keyThreshold: options.threshold,
106
- });
107
- }
108
- /**
109
- * Gives a rankings score based on how well the two strings match.
110
- * @param {String} testString - the string to test against
111
- * @param {String} stringToRank - the string to rank
112
- * @param {Object} options - options for the match (like keepDiacritics for comparison)
113
- * @returns {Number} the ranking for how well stringToRank matches testString
114
- */
115
- function getMatchRanking(testString, stringToRank, options) {
116
- testString = prepareValueForComparison(testString, options);
117
- stringToRank = prepareValueForComparison(stringToRank, options);
118
- // too long
119
- if (stringToRank.length > testString.length) {
120
- return RANKING_NO_MATCH;
121
- }
122
- // case sensitive equals
123
- if (testString === stringToRank) {
124
- return RANKING_CASE_SENSITIVE_EQUAL;
125
- }
126
- // Lower casing before further comparison
127
- testString = testString.toLowerCase();
128
- stringToRank = stringToRank.toLowerCase();
129
- // case insensitive equals
130
- if (testString === stringToRank) {
131
- return RANKING_EQUAL;
132
- }
133
- // starts with
134
- if (testString.startsWith(stringToRank)) {
135
- return RANKING_STARTS_WITH;
136
- }
137
- // word starts with
138
- if (testString.includes(" ".concat(stringToRank))) {
139
- return RANKING_WORD_STARTS_WITH;
140
- }
141
- // contains
142
- if (testString.includes(stringToRank)) {
143
- return RANKING_CONTAINS;
144
- }
145
- else if (stringToRank.length === 1) {
146
- // If the only character in the given stringToRank
147
- // isn't even contained in the testString, then
148
- // it's definitely not a match.
149
- return RANKING_NO_MATCH;
150
- }
151
- // acronym
152
- if (getAcronym(testString).includes(stringToRank)) {
153
- return RANKING_ACRONYM;
154
- }
155
- // will return a number between RANKING_MATCHES and
156
- // RANKING_MATCHES + 1 depending on how close of a match it is.
157
- return getClosenessRanking(testString, stringToRank);
158
- }
159
- /**
160
- * Generates an acronym for a string.
161
- *
162
- * @param {String} string the string for which to produce the acronym
163
- * @returns {String} the acronym
164
- */
165
- function getAcronym(string) {
166
- var acronym = "";
167
- var wordsInString = string.split(" ");
168
- wordsInString.forEach(function (wordInString) {
169
- var splitByHyphenWords = wordInString.split("-");
170
- splitByHyphenWords.forEach(function (splitByHyphenWord) {
171
- acronym += splitByHyphenWord.substring(0, 1);
172
- });
173
- });
174
- return acronym;
175
- }
176
- /**
177
- * Returns a score based on how spread apart the
178
- * characters from the stringToRank are within the testString.
179
- * A number close to RANKING_MATCHES represents a loose match. A number close
180
- * to RANKING_MATCHES + 1 represents a tighter match.
181
- * @param {String} testString - the string to test against
182
- * @param {String} stringToRank - the string to rank
183
- * @returns {Number} the number between RANKING_MATCHES and
184
- * RANKING_MATCHES + 1 for how well stringToRank matches testString
185
- */
186
- function getClosenessRanking(testString, stringToRank) {
187
- var matchingInOrderCharCount = 0;
188
- var charNumber = 0;
189
- function findMatchingCharacter(matchChar, string, index) {
190
- for (var j = index, J = string.length; j < J; j++) {
191
- var stringChar = string[j];
192
- if (stringChar === matchChar) {
193
- matchingInOrderCharCount += 1;
194
- return j + 1;
195
- }
196
- }
197
- return -1;
198
- }
199
- function getRanking(spread) {
200
- var spreadPercentage = 1 / spread;
201
- var inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
202
- var ranking = RANKING_MATCHES + inOrderPercentage * spreadPercentage;
203
- return ranking;
204
- }
205
- var firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
206
- if (firstIndex < 0) {
207
- return RANKING_NO_MATCH;
208
- }
209
- charNumber = firstIndex;
210
- for (var i = 1, I = stringToRank.length; i < I; i++) {
211
- var matchChar = stringToRank[i];
212
- charNumber = findMatchingCharacter(matchChar, testString, charNumber);
213
- var found = charNumber > -1;
214
- if (!found) {
215
- return RANKING_NO_MATCH;
216
- }
217
- }
218
- var spread = charNumber - firstIndex;
219
- return getRanking(spread);
220
- }
221
- /**
222
- * Sorts items that have a rank, index, and keyIndex
223
- * @param {Object} a - the first item to sort
224
- * @param {Object} b - the second item to sort
225
- * @return {Number} -1 if a should come first, 1 if b should come first, 0 if equal
226
- */
227
- function sortRankedValues(a, b, baseSort) {
228
- var aFirst = -1;
229
- var bFirst = 1;
230
- var aRank = a.rank, aKeyIndex = a.keyIndex;
231
- var bRank = b.rank, bKeyIndex = b.keyIndex;
232
- var same = aRank === bRank;
233
- if (same) {
234
- if (aKeyIndex === bKeyIndex) {
235
- // use the base sort function as a tie-breaker
236
- return baseSort(a, b);
237
- }
238
- else {
239
- return aKeyIndex < bKeyIndex ? aFirst : bFirst;
240
- }
241
- }
242
- else {
243
- return aRank > bRank ? aFirst : bFirst;
244
- }
245
- }
246
- /**
247
- * Prepares value for comparison by stringifying it, removing diacritics (if specified)
248
- * @param {String} value - the value to clean
249
- * @param {Object} options - {keepDiacritics: whether to remove diacritics}
250
- * @return {String} the prepared value
251
- */
252
- function prepareValueForComparison(value, _a) {
253
- var keepDiacritics = _a.keepDiacritics;
254
- // value might not actually be a string at this point (we don't get to choose)
255
- // so part of preparing the value for comparison is ensure that it is a string
256
- value = "".concat(value); // toString
257
- if (!keepDiacritics) {
258
- value = (0, removeAccents_1.default)(value);
259
- }
260
- return value;
261
- }
262
- /**
263
- * Gets value for key in item at arbitrarily nested keypath
264
- * @param {Object} item - the item
265
- * @param {Object|Function} key - the potentially nested keypath or property callback
266
- * @return {Array} - an array containing the value(s) at the nested keypath
267
- */
268
- function getItemValues(item, key) {
269
- if (typeof key === "object") {
270
- key = key.key;
271
- }
272
- var value;
273
- if (typeof key === "function") {
274
- value = key(item);
275
- }
276
- else if (item == null) {
277
- value = null;
278
- }
279
- else if (Object.hasOwnProperty.call(item, key)) {
280
- value = item[key];
281
- }
282
- else if (key.includes(".")) {
283
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
284
- return getNestedValues(key, item);
285
- }
286
- else {
287
- value = null;
288
- }
289
- // because `value` can also be undefined
290
- if (value == null) {
291
- return [];
292
- }
293
- if (Array.isArray(value)) {
294
- return value;
295
- }
296
- return [String(value)];
297
- }
298
- /**
299
- * Given path: "foo.bar.baz"
300
- * And item: {foo: {bar: {baz: 'buzz'}}}
301
- * -> 'buzz'
302
- * @param path a dot-separated set of keys
303
- * @param item the item to get the value from
304
- */
305
- function getNestedValues(path, item) {
306
- var keys = path.split(".");
307
- var values = [item];
308
- for (var i = 0, I = keys.length; i < I; i++) {
309
- var nestedKey = keys[i];
310
- var nestedValues = [];
311
- for (var j = 0, J = values.length; j < J; j++) {
312
- var nestedItem = values[j];
313
- if (nestedItem == null)
314
- continue;
315
- if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
316
- var nestedValue = nestedItem[nestedKey];
317
- if (nestedValue != null) {
318
- nestedValues.push(nestedValue);
319
- }
320
- }
321
- else if (nestedKey === "*") {
322
- // ensure that values is an array
323
- nestedValues = nestedValues.concat(nestedItem);
324
- }
325
- }
326
- values = nestedValues;
327
- }
328
- if (Array.isArray(values[0])) {
329
- // keep allowing the implicit wildcard for an array of strings at the end of
330
- // the path; don't use `.flat()` because that's not available in node.js v10
331
- var result = [];
332
- return result.concat.apply(result, values);
333
- }
334
- // Based on our logic it should be an array of strings by now...
335
- // assuming the user's path terminated in strings
336
- return values;
337
- }
338
- /**
339
- * Gets all the values for the given keys in the given item and returns an array of those values
340
- * @param item - the item from which the values will be retrieved
341
- * @param keys - the keys to use to retrieve the values
342
- * @return objects with {itemValue, attributes}
343
- */
344
- function getAllValuesToRank(item, keys) {
345
- var allValues = [];
346
- for (var j = 0, J = keys.length; j < J; j++) {
347
- var key = keys[j];
348
- var attributes = getKeyAttributes(key);
349
- var itemValues = getItemValues(item, key);
350
- for (var i = 0, I = itemValues.length; i < I; i++) {
351
- allValues.push({
352
- itemValue: itemValues[i],
353
- attributes: attributes,
354
- });
355
- }
356
- }
357
- return allValues;
358
- }
359
- var defaultKeyAttributes = {
360
- maxRanking: Infinity,
361
- minRanking: -Infinity,
362
- };
363
- /**
364
- * Gets all the attributes for the given key
365
- * @param key - the key from which the attributes will be retrieved
366
- * @return object containing the key's attributes
367
- */
368
- function getKeyAttributes(key) {
369
- if (typeof key === "string") {
370
- return defaultKeyAttributes;
371
- }
372
- return tslib_1.__assign(tslib_1.__assign({}, defaultKeyAttributes), key);
373
- }
374
- exports.default = matchSorter;
package/mbToBytes.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mbToBytes = void 0;
4
- /**
5
- * Megabytes to bytes
6
- *
7
- * @category format
8
- */
9
- var mbToBytes = function (bytes) { return bytes * 1000 * 1000; };
10
- exports.mbToBytes = mbToBytes;
11
- exports.default = exports.mbToBytes;
package/mergeObjects.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeObjects = void 0;
4
- var tslib_1 = require("tslib");
5
- var isObject_1 = require("./isObject");
6
- /**
7
- * Merge two or more objects together. It mutates the target object.
8
- *
9
- * @category objects
10
- * @see https://stackoverflow.com/a/46973278/1938970
11
- */
12
- var mergeObjects = function (target) {
13
- var sources = [];
14
- for (var _i = 1; _i < arguments.length; _i++) {
15
- sources[_i - 1] = arguments[_i];
16
- }
17
- if (!sources.length) {
18
- return target;
19
- }
20
- var source = sources.shift();
21
- if (source === undefined) {
22
- return target;
23
- }
24
- if ((0, isObject_1.isObject)(target) && (0, isObject_1.isObject)(source)) {
25
- Object.keys(source).forEach(function (_key) {
26
- var key = _key;
27
- if ((0, isObject_1.isObject)(source[key])) {
28
- if (!target[key]) {
29
- // @ts-expect-error FIXME: ...
30
- target[key] = {};
31
- }
32
- (0, exports.mergeObjects)(target[key], source[key]);
33
- }
34
- else {
35
- target[key] = source[key];
36
- }
37
- });
38
- }
39
- return exports.mergeObjects.apply(void 0, tslib_1.__spreadArray([target], sources, false));
40
- };
41
- exports.mergeObjects = mergeObjects;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeUrlQueryParams = void 0;
4
- var tslib_1 = require("tslib");
5
- var isNull_1 = tslib_1.__importDefault(require("./isNull"));
6
- /**
7
- * Merge query parameters objects, it *mutates* the first given object argument
8
- *
9
- * @category location
10
- * @pure
11
- */
12
- function mergeUrlQueryParams(oldParams, newParams) {
13
- if (oldParams === void 0) { oldParams = {}; }
14
- if (newParams === void 0) { newParams = {}; }
15
- for (var key in newParams) {
16
- var value = newParams[key];
17
- if (oldParams[key] && (0, isNull_1.default)(value)) {
18
- delete oldParams[key];
19
- }
20
- else {
21
- oldParams[key] = value;
22
- }
23
- }
24
- return oldParams;
25
- }
26
- exports.mergeUrlQueryParams = mergeUrlQueryParams;
27
- exports.default = mergeUrlQueryParams;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.moveSortableArrayItemByKey = void 0;
4
- var tslib_1 = require("tslib");
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 arrays, dnd
11
- */
12
- function moveSortableArrayItemByKey(items, key, fromItem, toItem) {
13
- var itemsKeys = items.map(function (item) { return item[key]; });
14
- var idxFrom = itemsKeys.indexOf(fromItem[key]);
15
- var idxTo = itemsKeys.indexOf(toItem[key]);
16
- var item = items.splice(idxFrom, 1)[0];
17
- items.splice(idxTo, 0, item);
18
- return tslib_1.__spreadArray([], items, true);
19
- }
20
- exports.moveSortableArrayItemByKey = moveSortableArrayItemByKey;
21
- exports.default = moveSortableArrayItemByKey;
package/noop.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noop = void 0;
4
- /**
5
- * No operation function
6
- *
7
- * @category native
8
- */
9
- var noop = function () { return void 0; };
10
- exports.noop = noop;
11
- exports.default = exports.noop;
package/normaliseUrl.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normaliseUrl = void 0;
4
- var tslib_1 = require("tslib");
5
- var removeTrailingSlash_1 = tslib_1.__importDefault(require("./removeTrailingSlash"));
6
- /**
7
- * Normalise URL, it works both for absolute and relative URLs
8
- *
9
- * - replaces too many consecutive slashes (except `http{s}://`)
10
- * - removes the trailing slash
11
- *
12
- * @category location
13
- * @see https://stackoverflow.com/a/40649435/1938970
14
- */
15
- function normaliseUrl(absoluteUrl) {
16
- if (absoluteUrl === void 0) { absoluteUrl = ""; }
17
- return (0, removeTrailingSlash_1.default)(absoluteUrl.replace(/(:\/\/)|(\/)+/g, "$1$2"));
18
- }
19
- exports.normaliseUrl = normaliseUrl;
20
- exports.default = normaliseUrl;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normaliseUrlPathname = void 0;
4
- var tslib_1 = require("tslib");
5
- var removeTrailingSlash_1 = tslib_1.__importDefault(require("./removeTrailingSlash"));
6
- /**
7
- * Normalise URL pathname (relative URL)
8
- *
9
- * - replaces too many consecutive slashes
10
- * - removes the trailing slash
11
- *
12
- * @category location
13
- */
14
- function normaliseUrlPathname(pathname) {
15
- if (pathname === void 0) { pathname = ""; }
16
- return (0, removeTrailingSlash_1.default)(pathname.replace(/\/+/g, "/"));
17
- }
18
- exports.normaliseUrlPathname = normaliseUrlPathname;
19
- exports.default = normaliseUrlPathname;
package/objectOmit.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.objectOmit = void 0;
4
- /**
5
- * Omit object properties by removing the given keys, it returns a
6
- * new object.
7
- *
8
- * NOTE: most of the time using a normal [destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) is enough,
9
- * use this utility only when it makes sense.
10
- *
11
- * @category objects
12
- */
13
- function objectOmit(object, keys) {
14
- return Object.keys(object).reduce(function (output, key) {
15
- if (!keys.includes(key)) {
16
- output[key] =
17
- object[key];
18
- }
19
- return output;
20
- }, {});
21
- }
22
- exports.objectOmit = objectOmit;
23
- exports.default = objectOmit;
package/objectPick.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.objectPick = void 0;
4
- /**
5
- * Pick object properties by selecting only the given keys, it returns a
6
- * new object.
7
- *
8
- * @category objects
9
- */
10
- function objectPick(object, keys) {
11
- var output = {};
12
- var len = keys.length;
13
- while (len--) {
14
- output[keys[len]] = object[keys[len]];
15
- }
16
- return output;
17
- }
18
- exports.objectPick = objectPick;
19
- exports.default = objectPick;
package/parseCookie.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCookie = void 0;
4
- /**
5
- * Try decoding a string using a decoding function.
6
- */
7
- function tryDecode(str, decode) {
8
- try {
9
- return decode(str);
10
- }
11
- catch (e) {
12
- return str;
13
- }
14
- }
15
- /**
16
- * Parse a cookie header.
17
- *
18
- * Parse the given cookie header string into an object
19
- * The object has the various cookies as keys(names) => values
20
- *
21
- * @category cookie
22
- */
23
- function parseCookie(str, attributes) {
24
- if (attributes === void 0) { attributes = {}; }
25
- if (typeof str !== "string") {
26
- throw new TypeError("argument str must be a string");
27
- }
28
- var obj = {};
29
- var pairs = str.split(";");
30
- var _a = attributes.decode, decode = _a === void 0 ? decodeURIComponent : _a;
31
- for (var i = 0; i < pairs.length; i++) {
32
- var pair = pairs[i];
33
- var index = pair.indexOf("=");
34
- // skip things that don't look like key=value
35
- if (index < 0) {
36
- continue;
37
- }
38
- var key = pair.substring(0, index).trim();
39
- // only assign once
40
- if (undefined == obj[key]) {
41
- var val = pair.substring(index + 1, pair.length).trim();
42
- // quoted values
43
- if (val[0] === '"') {
44
- val = val.slice(1, -1);
45
- }
46
- obj[key] = tryDecode(val, decode);
47
- }
48
- }
49
- return obj;
50
- }
51
- exports.parseCookie = parseCookie;
52
- exports.default = parseCookie;
package/parseURL.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseURL = void 0;
4
- /**
5
- * Solution without DOM or specific env native methods
6
- *
7
- * @category location
8
- * @see https://stackoverflow.com/a/21553982/1938970
9
- */
10
- function parseURL(url) {
11
- var match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
12
- return (match && {
13
- href: url,
14
- protocol: match[1],
15
- host: match[2],
16
- hostname: match[3],
17
- port: match[4],
18
- pathname: match[5],
19
- search: match[6],
20
- hash: match[7],
21
- });
22
- }
23
- exports.parseURL = parseURL;
24
- exports.default = parseURL;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.quaranteneProps = void 0;
4
- /**
5
- * @category impl
6
- * @usage
7
- *
8
- * ```ts
9
- * const { _: { onKeyDown }, myOwnProp, ...rest } = quaranteneProps([
10
- * "onPointerLeave",
11
- * "onPointerMove",
12
- * "onClick",
13
- * "onPointerDown",
14
- * "onPointerUp",
15
- * "onKeyDown",
16
- * ]);
17
- * ```
18
- */
19
- function quaranteneProps(props, propsKeysToQuarantene) {
20
- // approach 1)
21
- var healthyProps = {
22
- _: {},
23
- };
24
- for (var key in props) {
25
- var prop = props[key];
26
- if (propsKeysToQuarantene.includes(key)) {
27
- healthyProps._[key] = prop;
28
- }
29
- else {
30
- // @ts-expect-error nevermind
31
- healthyProps[key] = prop;
32
- }
33
- }
34
- return healthyProps;
35
- }
36
- exports.quaranteneProps = quaranteneProps;
37
- exports.default = quaranteneProps;