@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
@@ -1,22 +1,20 @@
1
1
  /**
2
- * @file
2
+ * @module
3
3
  *
4
4
  * @category cookie
5
5
  *
6
6
  * All cookie related code is inspired and adapted from:
7
7
  * - [js-cookie](https://github.com/js-cookie/js-cookie)
8
8
  * - [cookie](https://github.com/jshttp/cookie)
9
- */
10
- import { isNumber } from "./isNumber";
9
+ */ import { isNumber } from "./isNumber";
11
10
  /**
12
11
  * RegExp to match field-content in RFC 7230 sec 3.2
13
12
  *
14
13
  * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
15
14
  * field-vchar = VCHAR / obs-text
16
15
  * obs-text = %x80-FF
17
- */
18
- // eslint-disable-next-line no-control-regex
19
- var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
16
+ */ // eslint-disable-next-line no-control-regex
17
+ const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
20
18
  /**
21
19
  * Serialize data into a cookie header.
22
20
  *
@@ -27,16 +25,10 @@ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
27
25
  * => "foo=bar; httpOnly"
28
26
  *
29
27
  * @category cookie
30
- *
31
- * All cookie related code is inspired and adapted from:
32
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
33
- * - [cookie](https://github.com/jshttp/cookie)
34
- */
35
- export function serializeCookie(name, val, attributes) {
36
- if (attributes === void 0) { attributes = {}; }
37
- 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;
38
- var maxAge = attributes.maxAge, expires = attributes.expires;
39
- var value = encode(val);
28
+ */ export function serializeCookie(name, val, attributes = {}) {
29
+ const { encode = encodeURIComponent, domain, path, httpOnly, secure, sameSite } = attributes;
30
+ let { maxAge, expires } = attributes;
31
+ const value = encode(val);
40
32
  if (process.env["NODE_ENV"] !== "production") {
41
33
  if (!fieldContentRegExp.test(name)) {
42
34
  throw new TypeError("argument name is invalid");
@@ -48,7 +40,7 @@ export function serializeCookie(name, val, attributes) {
48
40
  throw new TypeError("argument val is invalid");
49
41
  }
50
42
  }
51
- var str = name + "=" + value;
43
+ let str = name + "=" + value;
52
44
  if (null != maxAge) {
53
45
  maxAge = maxAge - 0;
54
46
  if (isNaN(maxAge) || !isFinite(maxAge)) {
@@ -85,7 +77,7 @@ export function serializeCookie(name, val, attributes) {
85
77
  str += "; Secure";
86
78
  }
87
79
  if (sameSite) {
88
- switch (sameSite.toLowerCase()) {
80
+ switch(sameSite.toLowerCase()){
89
81
  case "lax":
90
82
  str += "; SameSite=Lax";
91
83
  break;
@@ -95,8 +87,6 @@ export function serializeCookie(name, val, attributes) {
95
87
  case "none":
96
88
  str += "; SameSite=None";
97
89
  break;
98
- // default:
99
- // throw new TypeError('option sameSite is invalid');
100
90
  }
101
91
  }
102
92
  return str;
package/setCookie.d.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  import { type CookieAttributesClient } from "./cookie";
2
2
  /**
3
3
  * @category cookie
4
- *
5
- * All cookie related code is inspired and adapted from:
6
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
7
- * - [cookie](https://github.com/jshttp/cookie)
8
4
  */
9
5
  export declare function setCookie<T extends string = string>(name: string, value: string | T, attributes?: CookieAttributesClient): string | undefined;
10
6
  export default setCookie;
package/setCookie.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { __assign, __rest } from "tslib";
2
1
  import { defaultAttributesClient } from "./cookie";
3
2
  import isNumber from "./isNumber";
4
3
  import isUndefined from "./isUndefined";
@@ -7,16 +6,14 @@ function converterWrite(value) {
7
6
  }
8
7
  /**
9
8
  * @category cookie
10
- *
11
- * All cookie related code is inspired and adapted from:
12
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
13
- * - [cookie](https://github.com/jshttp/cookie)
14
- */
15
- export function setCookie(name, value, attributes) {
16
- if (attributes === void 0) { attributes = {}; }
9
+ */ export function setCookie(name, value, attributes = {}) {
17
10
  // eslint-disable-next-line prefer-const
18
- var expires = attributes.expires, restAttrs = __rest(attributes, ["expires"]);
19
- var cleanedAttrs = __assign(__assign({ expires: "" }, defaultAttributesClient), restAttrs);
11
+ let { expires, ...restAttrs } = attributes;
12
+ const cleanedAttrs = {
13
+ expires: "",
14
+ ...defaultAttributesClient,
15
+ ...restAttrs
16
+ };
20
17
  if (isUndefined(document)) {
21
18
  if (process.env["NODE_ENV"] !== "production") {
22
19
  console.warn("[@koine/utils:setCookie] document is undefined");
@@ -29,12 +26,10 @@ export function setCookie(name, value, attributes) {
29
26
  if (expires) {
30
27
  cleanedAttrs.expires = expires.toUTCString();
31
28
  }
32
- name = encodeURIComponent(name)
33
- .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
34
- .replace(/[()]/g, escape);
35
- var stringifiedAttributes = "";
36
- for (var name_1 in attributes) {
37
- var attrName = name_1;
29
+ name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
30
+ let stringifiedAttributes = "";
31
+ for(const name in attributes){
32
+ const attrName = name;
38
33
  if (!attributes[attrName]) {
39
34
  continue;
40
35
  }
@@ -49,10 +44,8 @@ export function setCookie(name, value, attributes) {
49
44
  // Consume the characters of the unparsed-attributes up to,
50
45
  // not including, the first %x3B (";") character.
51
46
  // ...
52
- stringifiedAttributes +=
53
- "=" + String(attributes[attrName]).split(";")[0];
47
+ stringifiedAttributes += "=" + String(attributes[attrName]).split(";")[0];
54
48
  }
55
- return (document.cookie =
56
- name + "=" + converterWrite(value) + stringifiedAttributes);
49
+ return document.cookie = name + "=" + converterWrite(value) + stringifiedAttributes;
57
50
  }
58
51
  export default setCookie;
package/shuffle.d.ts CHANGED
@@ -2,15 +2,16 @@
2
2
  * Creates an array of shuffled values, using a version of the
3
3
  * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
4
4
  *
5
- * @see lodash.shuffle
6
- * @since 0.1.0
7
- * @category arrays
8
- * @param {Array} array The array to shuffle.
9
- * @returns {Array} Returns the new shuffled array.
5
+ * @category array
6
+ * @borrows [lodash.shuffle](https://github.com/lodash/lodash/blob/master/shuffle.js)
10
7
  * @example
11
- *
8
+ * ```ts
12
9
  * shuffle([1, 2, 3, 4])
13
10
  * // => [4, 1, 3, 2]
11
+ * ```
12
+ *
13
+ * @param array The array to shuffle.
14
+ * @returns The new shuffled array.
14
15
  */
15
16
  export declare function shuffle<T>(array: T[]): T[];
16
17
  export default shuffle;
package/shuffle.mjs CHANGED
@@ -1,29 +1,30 @@
1
- import { __spreadArray } from "tslib";
2
1
  /**
3
2
  * Creates an array of shuffled values, using a version of the
4
3
  * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
5
4
  *
6
- * @see lodash.shuffle
7
- * @since 0.1.0
8
- * @category arrays
9
- * @param {Array} array The array to shuffle.
10
- * @returns {Array} Returns the new shuffled array.
5
+ * @category array
6
+ * @borrows [lodash.shuffle](https://github.com/lodash/lodash/blob/master/shuffle.js)
11
7
  * @example
12
- *
8
+ * ```ts
13
9
  * shuffle([1, 2, 3, 4])
14
10
  * // => [4, 1, 3, 2]
15
- */
16
- export function shuffle(array) {
17
- var length = array == null ? 0 : array.length;
11
+ * ```
12
+ *
13
+ * @param array The array to shuffle.
14
+ * @returns The new shuffled array.
15
+ */ export function shuffle(array) {
16
+ const length = array == null ? 0 : array.length;
18
17
  if (!length) {
19
18
  return [];
20
19
  }
21
- var index = -1;
22
- var lastIndex = length - 1;
23
- var result = __spreadArray([], array, true);
24
- while (++index < length) {
25
- var rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
26
- var value = result[rand];
20
+ let index = -1;
21
+ const lastIndex = length - 1;
22
+ const result = [
23
+ ...array
24
+ ];
25
+ while(++index < length){
26
+ const rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
27
+ const value = result[rand];
27
28
  result[rand] = result[index];
28
29
  result[index] = value;
29
30
  }
package/slugify.d.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  * - replaces the punctuation with dashes
6
6
  *
7
7
  * @category text
8
- * @see https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021
8
+ *
9
+ * @borrows [mathewbyrne's gist](https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021)
9
10
  */
10
11
  export declare function slugify(text: string, separator?: string): string;
11
12
  export default slugify;
package/slugify.mjs CHANGED
@@ -7,17 +7,20 @@ import { removeAccents } from "./removeAccents";
7
7
  * - replaces the punctuation with dashes
8
8
  *
9
9
  * @category text
10
- * @see https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021
11
- */
12
- export function slugify(text, separator) {
13
- if (separator === void 0) { separator = "-"; }
14
- return removeAccents(text.toString().toLowerCase().trim(), accentsSets.concat([["-", "[·/_,:;']"]]))
15
- .replace(/\s+/g, "-") // replace spaces with -
16
- .replace(/&/g, "-and-") // replace & with 'and'
17
- .replace(/[^\w-]+/g, "") // remove all non-word chars
18
- .replace(/--+/g, "-") // replace multiple - with single -
19
- .replace(/^-+/, "") // trim - from start of text
20
- .replace(/-+$/, "") // trim - from end of text
21
- .replace(/-/g, separator);
10
+ *
11
+ * @borrows [mathewbyrne's gist](https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021)
12
+ */ export function slugify(text, separator = "-") {
13
+ return removeAccents(text.toString().toLowerCase().trim(), accentsSets.concat([
14
+ [
15
+ "-",
16
+ "[·/_,:;']"
17
+ ]
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);
22
25
  }
23
26
  export default slugify;
package/split.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  export type Split<S extends string, D extends string> = string extends S ? string[] : S extends "" ? [] : S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
2
+ /**
3
+ * @category native
4
+ * @category text
5
+ */
2
6
  export declare function split<T extends string, D extends string>(str: T, delimiter: D): Split<T, D>;
3
7
  export default split;
package/split.mjs CHANGED
@@ -1,4 +1,7 @@
1
- export function split(str, delimiter) {
1
+ /**
2
+ * @category native
3
+ * @category text
4
+ */ export function split(str, delimiter) {
2
5
  return str.split(delimiter);
3
6
  }
4
7
  export default split;
package/swapMap.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Swap object map key/value
3
3
  *
4
- * @category objects
4
+ * @category object
5
5
  */
6
6
  export declare function swapMap<T extends Record<string, string | number | symbol> = Record<string, string | number | symbol>>(map?: T): Record<T[keyof T], keyof T>;
7
7
  export default swapMap;
package/swapMap.mjs CHANGED
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * Swap object map key/value
3
3
  *
4
- * @category objects
5
- */
6
- export function swapMap(map) {
7
- if (map === void 0) { map = {}; }
8
- var output = {};
9
- for (var key in map) {
4
+ * @category object
5
+ */ export function swapMap(map = {}) {
6
+ const output = {};
7
+ for(const key in map){
10
8
  output[map[key]] = key;
11
9
  }
12
10
  return output;
package/throttle.d.ts CHANGED
@@ -1,8 +1,9 @@
1
+ /// <reference types="node" />
1
2
  /**
2
3
  * Throttle function (e.g. for resize / scroll handlers)
3
4
  *
4
5
  * @category function
5
- * @see https://github.com/Mobius1/Rangeable/
6
+ * @borrows [Mobius1/Rangeable](https://github.com/Mobius1/Rangeable/)
6
7
  */
7
8
  export declare function throttle<TFn extends Function, TContext>(fn: TFn, limit: number, context?: TContext): (this: TContext, ...args: any[]) => NodeJS.Timeout | undefined;
8
9
  export default throttle;
package/throttle.mjs CHANGED
@@ -1,22 +1,16 @@
1
- import { __spreadArray } from "tslib";
2
1
  /**
3
2
  * Throttle function (e.g. for resize / scroll handlers)
4
3
  *
5
4
  * @category function
6
- * @see https://github.com/Mobius1/Rangeable/
7
- */
8
- export function throttle(fn, limit, context) {
9
- var wait;
10
- return function () {
11
- var args = [];
12
- for (var _i = 0; _i < arguments.length; _i++) {
13
- args[_i] = arguments[_i];
14
- }
5
+ * @borrows [Mobius1/Rangeable](https://github.com/Mobius1/Rangeable/)
6
+ */ export function throttle(fn, limit, context) {
7
+ let wait;
8
+ return function(...args) {
15
9
  context = context || this;
16
10
  if (!wait) {
17
- fn.apply.apply(fn, __spreadArray([context], args, false));
11
+ fn.apply(context, ...args);
18
12
  wait = true;
19
- return setTimeout(function () {
13
+ return setTimeout(function() {
20
14
  wait = false;
21
15
  }, limit);
22
16
  }
package/titleCase.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
- * @category typography
3
- * @see https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts
4
- * @author Blake Embrey (hello@blakeembrey.com)
2
+ * @category text
3
+ *
4
+ * @borrows [blakeembrey/change-case](https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts)
5
+ * @license Blake Embrey (hello@blakeembrey.com)
5
6
  */
6
7
  export declare const titleCase: (input?: null | string) => string;
7
8
  export default titleCase;
package/titleCase.mjs CHANGED
@@ -1,11 +1,7 @@
1
1
  /**
2
- * @category typography
3
- * @see https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts
4
- * @author Blake Embrey (hello@blakeembrey.com)
5
- */
6
- export var titleCase = function (input) {
7
- return input
8
- ? input.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase(); })
9
- : "";
10
- };
2
+ * @category text
3
+ *
4
+ * @borrows [blakeembrey/change-case](https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts)
5
+ * @license Blake Embrey (hello@blakeembrey.com)
6
+ */ export const titleCase = (input)=>input ? input.replace(/\w\S*/g, (txt)=>txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase()) : "";
11
7
  export default titleCase;
package/toNumber.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  import { isNumber } from "./isNumber";
2
2
  /**
3
3
  * @category cast
4
- */
5
- export function toNumber(input, fallback) {
4
+ */ export function toNumber(input, fallback) {
6
5
  return isNumber(input) ? input : input ? parseFloat(input) : fallback || 0;
7
6
  }
8
7
  export default toNumber;
package/toRgba.mjs CHANGED
@@ -4,12 +4,10 @@
4
4
  // hexRgb(hexColor, { format: "css", alpha });
5
5
  /**
6
6
  * @category colors
7
- */
8
- export function toRgba(hex, alpha) {
9
- if (alpha === void 0) { alpha = 1; }
10
- var r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
7
+ */ export function toRgba(hex, alpha = 1) {
8
+ const r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
11
9
  if (r) {
12
- return "rgba(".concat(parseInt(r[1], 16), ",").concat(parseInt(r[2], 16), ",").concat(parseInt(r[3], 16), ",").concat(alpha, ")");
10
+ return `rgba(${parseInt(r[1], 16)},${parseInt(r[2], 16)},${parseInt(r[3], 16)},${alpha})`;
13
11
  }
14
12
  return "";
15
13
  }
@@ -7,10 +7,7 @@ import isString from "./isString";
7
7
  * - replaces whitespaces with dashes
8
8
  *
9
9
  * @category location
10
- */
11
- export function transformToUrlPathname(toPathname) {
12
- return isString(toPathname)
13
- ? "/".concat(encodeURIComponent(toPathname.replace(/\s/g, "-").toLowerCase()))
14
- : "";
10
+ */ export function transformToUrlPathname(toPathname) {
11
+ return isString(toPathname) ? `/${encodeURIComponent(toPathname.replace(/\s/g, "-").toLowerCase())}` : "";
15
12
  }
16
13
  export default transformToUrlPathname;
package/truncate.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Truncate string
3
3
  *
4
- * @category typography
4
+ * @category text
5
5
  */
6
6
  export declare const truncate: (input: undefined | null | string, length: number) => string;
7
7
  export default truncate;
package/truncate.mjs CHANGED
@@ -1,13 +1,6 @@
1
1
  /**
2
2
  * Truncate string
3
3
  *
4
- * @category typography
5
- */
6
- export var truncate = function (input, length) {
7
- return input
8
- ? input.length > length
9
- ? input.substring(0, length) + "..."
10
- : input
11
- : "";
12
- };
4
+ * @category text
5
+ */ export const truncate = (input, length)=>input ? input.length > length ? input.substring(0, length) + "..." : input : "";
13
6
  export default truncate;
package/tryUntil.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  /**
2
- * @borrows [https://levelup.gitconnected.com/javascript-wait-until-something-happens-or-timeout-82636839ea93]
2
+ * @category function
3
+ * @category async
4
+ *
5
+ * @borrows [Javascript: Wait Until Something Happens or Timeout](https://levelup.gitconnected.com/javascript-wait-until-something-happens-or-timeout-82636839ea93)
3
6
  *
4
7
  * @param timeout in `ms`
5
8
  * @param interval in `ms`
package/tryUntil.mjs CHANGED
@@ -1,27 +1,27 @@
1
1
  /**
2
- * @borrows [https://levelup.gitconnected.com/javascript-wait-until-something-happens-or-timeout-82636839ea93]
2
+ * @category function
3
+ * @category async
4
+ *
5
+ * @borrows [Javascript: Wait Until Something Happens or Timeout](https://levelup.gitconnected.com/javascript-wait-until-something-happens-or-timeout-82636839ea93)
3
6
  *
4
7
  * @param timeout in `ms`
5
8
  * @param interval in `ms`
6
- */
7
- export var tryUntil = function (test, timeout, interval, resolve, reject) {
9
+ */ export const tryUntil = (test, timeout, interval, resolve, reject)=>{
8
10
  // return new Promise((resolve, reject) => {
9
- var timeWas = new Date();
10
- var wait = setInterval(function () {
11
+ const timeWas = new Date();
12
+ const wait = setInterval(function() {
11
13
  if (test()) {
12
14
  // console.log("resolved after", new Date() - timeWas, "ms");
13
15
  clearInterval(wait);
14
16
  resolve();
15
- // @ts-expect-error ...
16
- }
17
- else if (new Date() - timeWas > timeout) {
17
+ // @ts-expect-error ...
18
+ } else if (new Date() - timeWas > timeout) {
18
19
  // Timeout
19
20
  // console.log("rejected after", new Date() - timeWas, "ms");
20
21
  clearInterval(wait);
21
- if (reject)
22
- reject();
22
+ if (reject) reject();
23
23
  }
24
24
  }, interval);
25
- // });
25
+ // });
26
26
  };
27
27
  export default tryUntil;
package/types.mjs CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ // import type { Replace } from "@koine/utils";
2
+ export { };
package/typings.d.ts CHANGED
@@ -1,9 +1,4 @@
1
1
  /**
2
2
  * List here the global variables used by third party scripts supported within
3
- * the `koine` ecosystem. For instance Google Analytics globally available
4
- * variables.
3
+ * the `koine` ecosystem.
5
4
  */
6
-
7
- // declare type NullableRecord<T> = {
8
- // [K in keyof T]: T[K] | null;
9
- // };
package/uid.mjs CHANGED
@@ -1,12 +1,10 @@
1
- var lastId = 0;
1
+ let lastId = 0;
2
2
  /**
3
3
  * Super basic UID increment-based generator
4
4
  *
5
5
  * @category uid
6
- */
7
- export var uid = function (prefix) {
8
- if (prefix === void 0) { prefix = "id"; }
6
+ */ export const uid = (prefix = "id")=>{
9
7
  lastId++;
10
- return "".concat(prefix, "-").concat(lastId);
8
+ return `${prefix}-${lastId}`;
11
9
  };
12
10
  export default uid;
@@ -5,9 +5,8 @@ import updateUrlQueryParams from "./updateUrlQueryParams";
5
5
  *
6
6
  * @category location
7
7
  * @pure
8
- */
9
- export function updateLinkParams($anchor, newParams) {
10
- var href = updateUrlQueryParams($anchor.href, newParams);
8
+ */ export function updateLinkParams($anchor, newParams) {
9
+ const href = updateUrlQueryParams($anchor.href, newParams);
11
10
  $anchor.href = href;
12
11
  return href;
13
12
  }
@@ -3,7 +3,6 @@ import { type AnyQueryParams } from "./location";
3
3
  * Update a URL string query parameters merging the given new query parameters
4
4
  *
5
5
  * @category location
6
- * @pure
7
6
  */
8
7
  export declare function updateUrlQueryParams(url: string, newParams?: NonNullable<AnyQueryParams>): string;
9
8
  export default updateUrlQueryParams;
@@ -5,14 +5,9 @@ import mergeUrlQueryParams from "./mergeUrlQueryParams";
5
5
  * Update a URL string query parameters merging the given new query parameters
6
6
  *
7
7
  * @category location
8
- * @pure
9
- */
10
- export function updateUrlQueryParams(url, newParams) {
11
- if (newParams === void 0) { newParams = {}; }
12
- var parts = url.split("?");
13
- var allParams = parts[1]
14
- ? mergeUrlQueryParams(getUrlQueryParams(url), newParams)
15
- : newParams;
8
+ */ export function updateUrlQueryParams(url, newParams = {}) {
9
+ const parts = url.split("?");
10
+ const allParams = parts[1] ? mergeUrlQueryParams(getUrlQueryParams(url), newParams) : newParams;
16
11
  return parts[0] + buildUrlQueryString(allParams);
17
12
  }
18
13
  export default updateUrlQueryParams;
package/uppercase.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * Replacement for native `toUpperCase` tyescript ready (type narrowing ready)
3
3
  *
4
4
  * @category native
5
+ * @category text
5
6
  */
6
7
  export declare const uppercase: <T extends string>(str?: T | null | undefined) => Uppercase<T>;
7
8
  export default uppercase;
package/uppercase.mjs CHANGED
@@ -2,8 +2,6 @@
2
2
  * Replacement for native `toUpperCase` tyescript ready (type narrowing ready)
3
3
  *
4
4
  * @category native
5
- */
6
- export var uppercase = function (str) {
7
- return (str || "").toUpperCase();
8
- };
5
+ * @category text
6
+ */ export const uppercase = (str)=>(str || "").toUpperCase();
9
7
  export default uppercase;
package/uuid.mjs CHANGED
@@ -3,11 +3,8 @@
3
3
  *
4
4
  * @category uid
5
5
  * @see https://stackoverflow.com/a/2117523/1938970
6
- */
7
- export var uuid = function () {
8
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
9
- var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
6
+ */ export const uuid = ()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c)=>{
7
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 0x3 | 0x8;
10
8
  return v.toString(16);
11
9
  });
12
- };
13
10
  export default uuid;
package/uuidNumeric.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * @category uid
3
3
  * @see https://stackoverflow.com/a/18048162/1938970
4
- */
5
- export var uuidNumeric = function () { return new Date().valueOf(); };
4
+ */ export const uuidNumeric = ()=>new Date().valueOf();
6
5
  export default uuidNumeric;
package/wait.mjs CHANGED
@@ -2,8 +2,5 @@
2
2
  * A promisified `setTimeout`
3
3
  *
4
4
  * @category async
5
- */
6
- export var wait = function (milliseconds) {
7
- return new Promise(function (resolve) { return setTimeout(resolve, milliseconds); });
8
- };
5
+ */ export const wait = (milliseconds)=>new Promise((resolve)=>setTimeout(resolve, milliseconds));
9
6
  export default wait;
package/without.mjs CHANGED
@@ -1,6 +1,4 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
- // TODO: finish this up, this is not exported yet
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */ // TODO: finish this up, this is not exported yet
4
2
  // ready to copy-paste to https://www.typescriptlang.org/play
5
3
  // type EmptyObject = Record<string, never>;
6
4
  // type EmptyArray = never[];