@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/randomInt.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomInt = void 0;
4
- /**
5
- * Get random int (min and max included)
6
- *
7
- * @category math
8
- */
9
- function randomInt(min, max) {
10
- return Math.floor(Math.random() * (max - min + 1) + min);
11
- }
12
- exports.randomInt = randomInt;
13
- exports.default = randomInt;
package/randomKey.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomKey = void 0;
4
- /**
5
- * Get random key from given object
6
- *
7
- * @category misc
8
- * @see https://stackoverflow.com/a/15106541/1938970
9
- */
10
- function randomKey(obj) {
11
- var keys = Object.keys(obj);
12
- return keys[(keys.length * Math.random()) << 0];
13
- }
14
- exports.randomKey = randomKey;
15
- exports.default = randomKey;
package/readCookie.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readCookie = void 0;
4
- function converterRead(value) {
5
- if (value[0] === '"') {
6
- value = value.slice(1, -1);
7
- }
8
- return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
9
- }
10
- function readCookie(name) {
11
- if (typeof document === "undefined") {
12
- if (process.env["NODE_ENV"] !== "production") {
13
- console.warn("[@koine/utils:readCookie] document is undefined");
14
- }
15
- return name ? "" : {};
16
- }
17
- var cookies = document.cookie ? document.cookie.split("; ") : [];
18
- var all = {};
19
- for (var i = 0; i < cookies.length; i++) {
20
- var parts = cookies[i].split("=");
21
- var value = parts.slice(1).join("=");
22
- try {
23
- var found = decodeURIComponent(parts[0]);
24
- all[found] = converterRead(value);
25
- if (name === found) {
26
- break;
27
- }
28
- }
29
- catch (e) {
30
- if (process.env["NODE_ENV"] !== "production") {
31
- console.warn("[@koine/utils:readCookie] failed to decode", value);
32
- }
33
- }
34
- }
35
- return name ? all[name] : all;
36
- }
37
- exports.readCookie = readCookie;
38
- exports.default = readCookie;
package/removeAccents.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeAccents = void 0;
4
- var accentSets_1 = require("./accentSets");
5
- /**
6
- * @category text
7
- */
8
- function removeAccents(text, sets) {
9
- if (text === void 0) { text = ""; }
10
- if (sets === void 0) { sets = accentSets_1.accentsSets; }
11
- var len = sets.length;
12
- while (len--) {
13
- var _a = sets[len], to = _a[0], from = _a[1];
14
- text = text.replace(new RegExp("[".concat(from, "]"), "gi"), to);
15
- }
16
- return text;
17
- }
18
- exports.removeAccents = removeAccents;
19
- exports.default = removeAccents;
package/removeCookie.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeCookie = void 0;
4
- var tslib_1 = require("tslib");
5
- var cookie_1 = require("./cookie");
6
- var setCookie_1 = require("./setCookie");
7
- /**
8
- * @category cookie
9
- *
10
- * All cookie related code is inspired and adapted from:
11
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
12
- * - [cookie](https://github.com/jshttp/cookie)
13
- */
14
- function removeCookie(name, attributes) {
15
- if (attributes === void 0) { attributes = {}; }
16
- (0, setCookie_1.setCookie)(name, "", tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, cookie_1.defaultAttributesClient), attributes), { expires: -1 }));
17
- }
18
- exports.removeCookie = removeCookie;
19
- exports.default = removeCookie;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- // /**
3
- // * FIXME: Type 'Set<any>' can only be iterated through when using the
4
- // * '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
5
- // * I am not sure I want to use those ts options here. Let's keep it commented
6
- // * for now
7
- // *
8
- // * @category array
9
- // */
10
- // export function removeDuplicates<T extends any[]>(arr: T) {
11
- // return [...new Set(arr)];
12
- // }
13
- // export default removeDuplicates;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeDuplicatesByKey = void 0;
4
- /**
5
- * Remove duplicated array objects, equality is determined by a strict (`===`)
6
- * comparison of each object's given key
7
- *
8
- * @category array
9
- */
10
- function removeDuplicatesByKey(array, key) {
11
- if (array === void 0) { array = []; }
12
- var keysMap = {};
13
- var output = [];
14
- for (var i = 0; i < array.length; i++) {
15
- var item = array[i];
16
- if (!keysMap[item[key]]) {
17
- output.push(item);
18
- keysMap[item[key]] = true;
19
- }
20
- }
21
- return output;
22
- }
23
- exports.removeDuplicatesByKey = removeDuplicatesByKey;
24
- exports.default = removeDuplicatesByKey;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeDuplicatesComparing = void 0;
4
- var removeIndexesFromArray_1 = require("./removeIndexesFromArray");
5
- var findDuplicatedIndexes_1 = require("./findDuplicatedIndexes");
6
- /**
7
- * @category array
8
- */
9
- function removeDuplicatesComparing(from, to) {
10
- var indexes = (0, findDuplicatedIndexes_1.findDuplicatedIndexes)(from);
11
- return (0, removeIndexesFromArray_1.removeIndexesFromArray)(to, indexes);
12
- }
13
- exports.removeDuplicatesComparing = removeDuplicatesComparing;
14
- exports.default = removeDuplicatesComparing;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeIndexesFromArray = void 0;
4
- /**
5
- * @category array
6
- */
7
- function removeIndexesFromArray(arr, indexes) {
8
- var output = [];
9
- for (var i = 0; i < arr.length; i++) {
10
- // eslint-disable-next-line no-prototype-builtins
11
- if (!indexes.hasOwnProperty(i)) {
12
- output.push(arr[i]);
13
- }
14
- }
15
- return output;
16
- }
17
- exports.removeIndexesFromArray = removeIndexesFromArray;
18
- exports.default = removeIndexesFromArray;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeTralingSlash = void 0;
4
- /**
5
- * Strips out the trailing slash
6
- *
7
- * @category location
8
- */
9
- function removeTralingSlash(urlLike) {
10
- if (urlLike === void 0) { urlLike = ""; }
11
- return urlLike.replace(/\/*$/, "");
12
- }
13
- exports.removeTralingSlash = removeTralingSlash;
14
- exports.default = removeTralingSlash;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeUrlQueryParams = void 0;
4
- var tslib_1 = require("tslib");
5
- var buildUrlQueryString_1 = tslib_1.__importDefault(require("./buildUrlQueryString"));
6
- var getUrlQueryParams_1 = tslib_1.__importDefault(require("./getUrlQueryParams"));
7
- /**
8
- * Remove the given keys from the given URL query parameters
9
- *
10
- * @category location
11
- * @pure
12
- */
13
- function removeUrlQueryParams(url, paramsToRemove) {
14
- if (paramsToRemove === void 0) { paramsToRemove = []; }
15
- var parts = url.split("?");
16
- var allParams = (0, getUrlQueryParams_1.default)(url);
17
- var params = {};
18
- for (var key in allParams) {
19
- if (!paramsToRemove.includes(key)) {
20
- params[key] = allParams[key];
21
- }
22
- }
23
- return parts[0] + (0, buildUrlQueryString_1.default)(params);
24
- }
25
- exports.removeUrlQueryParams = removeUrlQueryParams;
26
- exports.default = removeUrlQueryParams;
package/render.js DELETED
@@ -1,169 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.render = void 0;
4
- var varname = "data";
5
- var evaluate = /<%([\s\S]+?(\}?)+)%>/g;
6
- var interpolate = /<%=([\s\S]+?)%>/g;
7
- var conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
8
- var iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
9
- // const encode = /<%!([\s\S]+?)%>/g;
10
- var use = /<%#([\s\S]+?)%>/g;
11
- var useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
12
- var define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
13
- var defineParams = /^\s*([\w$]+):([\s\S]+)/;
14
- var start = "'+(";
15
- var end = ")+'";
16
- // const startencode = "'+encodeHTML(";
17
- var skip = /$^/;
18
- var resolveDefs = function (block, def) {
19
- return (typeof block === "string" ? block : block.toString())
20
- .replace(define || skip, function (_, code, assign, value) {
21
- if (code.indexOf("def.") === 0) {
22
- code = code.substring(4);
23
- }
24
- if (!(code in def)) {
25
- if (assign === ":") {
26
- value.replace(defineParams,
27
- // @ts-expect-error nevermind
28
- function (_, param, v) {
29
- def[code] = { arg: param, text: v };
30
- });
31
- // @ts-expect-error nevermind
32
- if (!(code in def))
33
- def[code] = value;
34
- }
35
- else {
36
- new Function("def", "def['" + code + "']=" + value)(def);
37
- }
38
- }
39
- return "";
40
- })
41
- .replace(use || skip, function (_, code) {
42
- code = code.replace(useParams, function (_, s, d, param) {
43
- if (def[d] && def[d].arg && param) {
44
- var rw = (d + ":" + param).replace(/'|\\/g, "_");
45
- def.__exp = def.__exp || {};
46
- def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
47
- return s + "def.__exp['" + rw + "']";
48
- }
49
- return s;
50
- });
51
- var v = new Function("def", "return " + code)(def);
52
- return v ? resolveDefs(v, def) : v;
53
- });
54
- };
55
- var unescape = function (code) {
56
- return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
57
- };
58
- /**
59
- * Render template (adapted from doT.js)
60
- *
61
- * The data made available to the template is always on the `data` key, e.g.:
62
- * `renderer({ myVal: "xx" })`
63
- * ... will be accessible on
64
- * `<%= data.myVal %>`
65
- *
66
- * The default delimiters are customised to work without conflicts with Blade and Twig:
67
- * ```
68
- * <% %> for evaluation
69
- * <%= %> for interpolation
70
- * <%? %> for conditionals
71
- * <%~ %> for array iteration
72
- * <%# %> for compile-time evaluation/includes and partials
73
- * <%## #%> for compile-time defines
74
- *
75
- * Unsupported:
76
- * <%! %> for interpolation with encoding
77
- * ```
78
- *
79
- * @example
80
- *
81
- * ```js
82
- * import { render } from "...";
83
- *
84
- * const data = { name: "XYZ" };
85
- * const tpl = `Hello <%= data.name %>`;
86
- * const renderer = render(tpl);
87
- *
88
- * console.log(renderer(data)); // outputs 'Hello XYZ'
89
- * ```
90
- *
91
- * @borrows [olado/doT by Laura Doktorova](https://github.com/olado/doT)
92
- * @see https://olado.github.io/doT/index.html
93
- */
94
- var render = function (tmpl, def) {
95
- var sid = 0;
96
- var indv;
97
- var str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
98
- str = ("var X='" +
99
- str
100
- .replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ")
101
- .replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "")
102
- .replace(/'|\\/g, "\\$&")
103
- .replace(interpolate || skip, function (_, code) { return start + unescape(code) + end; })
104
- // .replace(
105
- // encode || skip,
106
- // (_, code) => cse.startencode + unescape(code) + cse.end
107
- // )
108
- .replace(conditional || skip, function (_, elseCase, code) {
109
- return elseCase
110
- ? code
111
- ? "';}else if(" + unescape(code) + "){X+='"
112
- : "';}else{X+='"
113
- : code
114
- ? "';if(" + unescape(code) + "){X+='"
115
- : "';}X+='";
116
- })
117
- .replace(iterate || skip, function (_, arr, vName, iName) {
118
- if (!arr)
119
- return "';} } X+='";
120
- sid++;
121
- indv = iName || "i" + sid;
122
- arr = unescape(arr);
123
- return ("';var arr" +
124
- sid +
125
- "=" +
126
- arr +
127
- ";if(arr" +
128
- sid +
129
- "){var " +
130
- vName +
131
- "," +
132
- indv +
133
- "=-1,l" +
134
- sid +
135
- "=arr" +
136
- sid +
137
- ".length-1;while(" +
138
- indv +
139
- "<l" +
140
- sid +
141
- "){" +
142
- vName +
143
- "=arr" +
144
- sid +
145
- "[" +
146
- indv +
147
- "+=1];X+='");
148
- })
149
- .replace(evaluate || skip, function (_, code) { return "';" + unescape(code) + "X+='"; }) +
150
- "';return X;")
151
- .replace(/\n/g, "\\n")
152
- .replace(/\t/g, "\\t")
153
- .replace(/\r/g, "\\r")
154
- .replace(/(\s|;|\}|^|\{)X\+='';/g, "$1")
155
- .replace(/\+''/g, "");
156
- //.replace(/(\s|;|\}|^|\{)X\+=''\+/g,'$1X+=');
157
- try {
158
- return new Function(varname, str);
159
- }
160
- catch (e) {
161
- if (process.env["NODE_ENV"] !== "production") {
162
- console.log("Could not create a template function: " + str);
163
- throw e;
164
- }
165
- }
166
- return function () { return ""; };
167
- };
168
- exports.render = render;
169
- exports.default = exports.render;
package/roundTo.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.roundTo = void 0;
4
- /**
5
- * Round to given number of the given number of decimals
6
- *
7
- * @category math
8
- * @see https://stackoverflow.com/a/15762794/1938970
9
- */
10
- function roundTo(num, decimals) {
11
- if (decimals === void 0) { decimals = 2; }
12
- if (isFinite(num) && !isNaN(num)) {
13
- // method 1
14
- // return Number(num).toFixed(decimals);
15
- // method 2: @see https://stackoverflow.com/a/43532829/1938970
16
- var multiplicator = Math.pow(10, decimals);
17
- return Math.round(num * multiplicator) / multiplicator + "";
18
- // method 3: @see https://stackoverflow.com/a/15762794/1938970
19
- // let negative = false;
20
- // if (num < 0) {
21
- // negative = true;
22
- // num = num * -1;
23
- // }
24
- // const multiplicator = Math.pow(10, decimals);
25
- // const outputStr = parseFloat((num * multiplicator).toFixed(11));
26
- // let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
27
- // if (negative) {
28
- // return (Number(outputNum) * -1).toFixed(decimals);
29
- // }
30
- // return outputNum;
31
- }
32
- if (process.env["NODE_ENV"] !== "production") {
33
- console.warn("[@koine/utils] math:roundTo -> given not a finite number as first arg");
34
- }
35
- return "";
36
- }
37
- exports.roundTo = roundTo;
38
- exports.default = roundTo;
@@ -1,108 +0,0 @@
1
- "use strict";
2
- /**
3
- * @file
4
- *
5
- * @category cookie
6
- *
7
- * All cookie related code is inspired and adapted from:
8
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
9
- * - [cookie](https://github.com/jshttp/cookie)
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.serializeCookie = void 0;
13
- var isNumber_1 = require("./isNumber");
14
- /**
15
- * RegExp to match field-content in RFC 7230 sec 3.2
16
- *
17
- * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
18
- * field-vchar = VCHAR / obs-text
19
- * obs-text = %x80-FF
20
- */
21
- // eslint-disable-next-line no-control-regex
22
- var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
23
- /**
24
- * Serialize data into a cookie header.
25
- *
26
- * Serialize the a name value pair into a cookie string suitable for
27
- * http headers. An optional attributes object specified cookie parameters.
28
- *
29
- * serialize('foo', 'bar', { httpOnly: true })
30
- * => "foo=bar; httpOnly"
31
- *
32
- * @category cookie
33
- *
34
- * All cookie related code is inspired and adapted from:
35
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
36
- * - [cookie](https://github.com/jshttp/cookie)
37
- */
38
- function serializeCookie(name, val, attributes) {
39
- if (attributes === void 0) { attributes = {}; }
40
- var _a = attributes.encode, encode = _a === void 0 ? encodeURIComponent : _a, domain = attributes.domain, path = attributes.path, httpOnly = attributes.httpOnly, secure = attributes.secure, sameSite = attributes.sameSite;
41
- var maxAge = attributes.maxAge, expires = attributes.expires;
42
- var value = encode(val);
43
- if (process.env["NODE_ENV"] !== "production") {
44
- if (!fieldContentRegExp.test(name)) {
45
- throw new TypeError("argument name is invalid");
46
- }
47
- if (typeof attributes.encode !== "function") {
48
- throw new TypeError("option encode is invalid");
49
- }
50
- if (value && !fieldContentRegExp.test(value)) {
51
- throw new TypeError("argument val is invalid");
52
- }
53
- }
54
- var str = name + "=" + value;
55
- if (null != maxAge) {
56
- maxAge = maxAge - 0;
57
- if (isNaN(maxAge) || !isFinite(maxAge)) {
58
- throw new TypeError("option maxAge is invalid");
59
- }
60
- str += "; Max-Age=" + Math.floor(maxAge);
61
- }
62
- if (domain) {
63
- if (process.env["NODE_ENV"] !== "production") {
64
- if (!fieldContentRegExp.test(domain)) {
65
- throw new TypeError("option domain is invalid");
66
- }
67
- }
68
- str += "; Domain=" + domain;
69
- }
70
- if (path) {
71
- if (process.env["NODE_ENV"] !== "production") {
72
- if (!fieldContentRegExp.test(path)) {
73
- throw new TypeError("option path is invalid");
74
- }
75
- }
76
- str += "; Path=" + path;
77
- }
78
- if (expires) {
79
- if ((0, isNumber_1.isNumber)(expires)) {
80
- expires = new Date(Date.now() + expires * 864e5);
81
- }
82
- str += "; Expires=" + expires.toUTCString();
83
- }
84
- if (httpOnly) {
85
- str += "; HttpOnly";
86
- }
87
- if (secure) {
88
- str += "; Secure";
89
- }
90
- if (sameSite) {
91
- switch (sameSite.toLowerCase()) {
92
- case "lax":
93
- str += "; SameSite=Lax";
94
- break;
95
- case "strict":
96
- str += "; SameSite=Strict";
97
- break;
98
- case "none":
99
- str += "; SameSite=None";
100
- break;
101
- // default:
102
- // throw new TypeError('option sameSite is invalid');
103
- }
104
- }
105
- return str;
106
- }
107
- exports.serializeCookie = serializeCookie;
108
- exports.default = serializeCookie;
package/setCookie.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setCookie = void 0;
4
- var tslib_1 = require("tslib");
5
- var cookie_1 = require("./cookie");
6
- var isNumber_1 = tslib_1.__importDefault(require("./isNumber"));
7
- var isUndefined_1 = tslib_1.__importDefault(require("./isUndefined"));
8
- function converterWrite(value) {
9
- return encodeURIComponent(value).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
10
- }
11
- /**
12
- * @category cookie
13
- *
14
- * All cookie related code is inspired and adapted from:
15
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
16
- * - [cookie](https://github.com/jshttp/cookie)
17
- */
18
- function setCookie(name, value, attributes) {
19
- if (attributes === void 0) { attributes = {}; }
20
- // eslint-disable-next-line prefer-const
21
- var expires = attributes.expires, restAttrs = tslib_1.__rest(attributes, ["expires"]);
22
- var cleanedAttrs = tslib_1.__assign(tslib_1.__assign({ expires: "" }, cookie_1.defaultAttributesClient), restAttrs);
23
- if ((0, isUndefined_1.default)(document)) {
24
- if (process.env["NODE_ENV"] !== "production") {
25
- console.warn("[@koine/utils:setCookie] document is undefined");
26
- }
27
- return undefined;
28
- }
29
- if ((0, isNumber_1.default)(expires)) {
30
- expires = new Date(Date.now() + expires * 864e5);
31
- }
32
- if (expires) {
33
- cleanedAttrs.expires = expires.toUTCString();
34
- }
35
- name = encodeURIComponent(name)
36
- .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
37
- .replace(/[()]/g, escape);
38
- var stringifiedAttributes = "";
39
- for (var name_1 in attributes) {
40
- var attrName = name_1;
41
- if (!attributes[attrName]) {
42
- continue;
43
- }
44
- stringifiedAttributes += "; " + attrName;
45
- if (attributes[attrName] === true) {
46
- continue;
47
- }
48
- // Considers RFC 6265 section 5.2:
49
- // ...
50
- // 3. If the remaining unparsed-attributes contains a %x3B (";")
51
- // character:
52
- // Consume the characters of the unparsed-attributes up to,
53
- // not including, the first %x3B (";") character.
54
- // ...
55
- stringifiedAttributes +=
56
- "=" + String(attributes[attrName]).split(";")[0];
57
- }
58
- return (document.cookie =
59
- name + "=" + converterWrite(value) + stringifiedAttributes);
60
- }
61
- exports.setCookie = setCookie;
62
- exports.default = setCookie;
package/shuffle.js DELETED
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shuffle = void 0;
4
- var tslib_1 = require("tslib");
5
- /**
6
- * Creates an array of shuffled values, using a version of the
7
- * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
8
- *
9
- * @see lodash.shuffle
10
- * @since 0.1.0
11
- * @category arrays
12
- * @param {Array} array The array to shuffle.
13
- * @returns {Array} Returns the new shuffled array.
14
- * @example
15
- *
16
- * shuffle([1, 2, 3, 4])
17
- * // => [4, 1, 3, 2]
18
- */
19
- function shuffle(array) {
20
- var length = array == null ? 0 : array.length;
21
- if (!length) {
22
- return [];
23
- }
24
- var index = -1;
25
- var lastIndex = length - 1;
26
- var result = tslib_1.__spreadArray([], array, true);
27
- while (++index < length) {
28
- var rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
29
- var value = result[rand];
30
- result[rand] = result[index];
31
- result[index] = value;
32
- }
33
- return result;
34
- }
35
- exports.shuffle = shuffle;
36
- exports.default = shuffle;
package/slugify.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.slugify = void 0;
4
- var accentSets_1 = require("./accentSets");
5
- var removeAccents_1 = require("./removeAccents");
6
- /**
7
- * Slugify a text
8
- *
9
- * - replaces the accented letters
10
- * - replaces the punctuation with dashes
11
- *
12
- * @category text
13
- * @see https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021
14
- */
15
- function slugify(text, separator) {
16
- if (separator === void 0) { separator = "-"; }
17
- return (0, removeAccents_1.removeAccents)(text.toString().toLowerCase().trim(), accentSets_1.accentsSets.concat([["-", "[·/_,:;']"]]))
18
- .replace(/\s+/g, "-") // replace spaces with -
19
- .replace(/&/g, "-and-") // replace & with 'and'
20
- .replace(/[^\w-]+/g, "") // remove all non-word chars
21
- .replace(/--+/g, "-") // replace multiple - with single -
22
- .replace(/^-+/, "") // trim - from start of text
23
- .replace(/-+$/, "") // trim - from end of text
24
- .replace(/-/g, separator);
25
- }
26
- exports.slugify = slugify;
27
- exports.default = slugify;