@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/package.json CHANGED
@@ -1,16 +1,12 @@
1
1
  {
2
2
  "name": "@koine/utils",
3
3
  "sideEffects": false,
4
- "dependencies": {
5
- "clsx": "1.2.1",
6
- "ts-debounce": "^4.0.0",
7
- "type-fest": "^3.11.1"
8
- },
9
- "peerDependencies": {
10
- "tslib": "2.5.3"
11
- },
4
+ "dependencies": {},
5
+ "module": "./index.mjs",
12
6
  "main": "./index.js",
13
7
  "types": "./index.d.ts",
14
- "version": "2.0.0-beta.1",
15
- "module": "./index.mjs"
16
- }
8
+ "peerDependencies": {
9
+ "type-fest": "^4.1.0"
10
+ },
11
+ "version": "2.0.0-beta.11"
12
+ }
package/parseCookie.mjs CHANGED
@@ -1,11 +1,9 @@
1
1
  /**
2
2
  * Try decoding a string using a decoding function.
3
- */
4
- function tryDecode(str, decode) {
3
+ */ function tryDecode(str, decode) {
5
4
  try {
6
5
  return decode(str);
7
- }
8
- catch (e) {
6
+ } catch (e) {
9
7
  return str;
10
8
  }
11
9
  }
@@ -16,26 +14,24 @@ function tryDecode(str, decode) {
16
14
  * The object has the various cookies as keys(names) => values
17
15
  *
18
16
  * @category cookie
19
- */
20
- export function parseCookie(str, attributes) {
21
- if (attributes === void 0) { attributes = {}; }
17
+ */ export function parseCookie(str, attributes = {}) {
22
18
  if (typeof str !== "string") {
23
19
  throw new TypeError("argument str must be a string");
24
20
  }
25
- var obj = {};
26
- var pairs = str.split(";");
27
- var _a = attributes.decode, decode = _a === void 0 ? decodeURIComponent : _a;
28
- for (var i = 0; i < pairs.length; i++) {
29
- var pair = pairs[i];
30
- var index = pair.indexOf("=");
21
+ const obj = {};
22
+ const pairs = str.split(";");
23
+ const { decode = decodeURIComponent } = attributes;
24
+ for(let i = 0; i < pairs.length; i++){
25
+ const pair = pairs[i];
26
+ const index = pair.indexOf("=");
31
27
  // skip things that don't look like key=value
32
28
  if (index < 0) {
33
29
  continue;
34
30
  }
35
- var key = pair.substring(0, index).trim();
31
+ const key = pair.substring(0, index).trim();
36
32
  // only assign once
37
33
  if (undefined == obj[key]) {
38
- var val = pair.substring(index + 1, pair.length).trim();
34
+ let val = pair.substring(index + 1, pair.length).trim();
39
35
  // quoted values
40
36
  if (val[0] === '"') {
41
37
  val = val.slice(1, -1);
package/parseURL.mjs CHANGED
@@ -3,10 +3,9 @@
3
3
  *
4
4
  * @category location
5
5
  * @see https://stackoverflow.com/a/21553982/1938970
6
- */
7
- export function parseURL(url) {
8
- var match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
9
- return (match && {
6
+ */ export function parseURL(url) {
7
+ const match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
8
+ return match && {
10
9
  href: url,
11
10
  protocol: match[1],
12
11
  host: match[2],
@@ -14,7 +13,7 @@ export function parseURL(url) {
14
13
  port: match[4],
15
14
  pathname: match[5],
16
15
  search: match[6],
17
- hash: match[7],
18
- });
16
+ hash: match[7]
17
+ };
19
18
  }
20
19
  export default parseURL;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @category impl
3
- * @usage
3
+ * @example
4
4
  *
5
5
  * ```ts
6
6
  * const { _: { onKeyDown }, myOwnProp, ...rest } = quaranteneProps([
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @category impl
3
- * @usage
3
+ * @example
4
4
  *
5
5
  * ```ts
6
6
  * const { _: { onKeyDown }, myOwnProp, ...rest } = quaranteneProps([
@@ -12,18 +12,16 @@
12
12
  * "onKeyDown",
13
13
  * ]);
14
14
  * ```
15
- */
16
- export function quaranteneProps(props, propsKeysToQuarantene) {
15
+ */ export function quaranteneProps(props, propsKeysToQuarantene) {
17
16
  // approach 1)
18
- var healthyProps = {
19
- _: {},
17
+ const healthyProps = {
18
+ _: {}
20
19
  };
21
- for (var key in props) {
22
- var prop = props[key];
20
+ for(const key in props){
21
+ const prop = props[key];
23
22
  if (propsKeysToQuarantene.includes(key)) {
24
23
  healthyProps._[key] = prop;
25
- }
26
- else {
24
+ } else {
27
25
  // @ts-expect-error nevermind
28
26
  healthyProps[key] = prop;
29
27
  }
package/randomInt.mjs CHANGED
@@ -2,8 +2,7 @@
2
2
  * Get random int (min and max included)
3
3
  *
4
4
  * @category math
5
- */
6
- export function randomInt(min, max) {
5
+ */ export function randomInt(min, max) {
7
6
  return Math.floor(Math.random() * (max - min + 1) + min);
8
7
  }
9
8
  export default randomInt;
package/randomKey.mjs CHANGED
@@ -3,9 +3,8 @@
3
3
  *
4
4
  * @category misc
5
5
  * @see https://stackoverflow.com/a/15106541/1938970
6
- */
7
- export function randomKey(obj) {
8
- var keys = Object.keys(obj);
9
- return keys[(keys.length * Math.random()) << 0];
6
+ */ export function randomKey(obj) {
7
+ const keys = Object.keys(obj);
8
+ return keys[keys.length * Math.random() << 0];
10
9
  }
11
10
  export default randomKey;
package/readCookie.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Read cookie
3
+ *
4
+ * @category cookie
5
+ */
1
6
  export declare function readCookie<T extends Record<string, unknown> = Record<string, string>>(name?: null): T;
2
7
  export declare function readCookie<T extends Record<string, unknown> = Record<string, string>, N extends keyof T = keyof T>(name: N): T[N];
3
8
  export default readCookie;
package/readCookie.mjs CHANGED
@@ -11,19 +11,18 @@ export function readCookie(name) {
11
11
  }
12
12
  return name ? "" : {};
13
13
  }
14
- var cookies = document.cookie ? document.cookie.split("; ") : [];
15
- var all = {};
16
- for (var i = 0; i < cookies.length; i++) {
17
- var parts = cookies[i].split("=");
18
- var value = parts.slice(1).join("=");
14
+ const cookies = document.cookie ? document.cookie.split("; ") : [];
15
+ const all = {};
16
+ for(let i = 0; i < cookies.length; i++){
17
+ const parts = cookies[i].split("=");
18
+ const value = parts.slice(1).join("=");
19
19
  try {
20
- var found = decodeURIComponent(parts[0]);
20
+ const found = decodeURIComponent(parts[0]);
21
21
  all[found] = converterRead(value);
22
22
  if (name === found) {
23
23
  break;
24
24
  }
25
- }
26
- catch (e) {
25
+ } catch (e) {
27
26
  if (process.env["NODE_ENV"] !== "production") {
28
27
  console.warn("[@koine/utils:readCookie] failed to decode", value);
29
28
  }
package/removeAccents.mjs CHANGED
@@ -1,14 +1,11 @@
1
1
  import { accentsSets } from "./accentSets";
2
2
  /**
3
3
  * @category text
4
- */
5
- export function removeAccents(text, sets) {
6
- if (text === void 0) { text = ""; }
7
- if (sets === void 0) { sets = accentsSets; }
8
- var len = sets.length;
9
- while (len--) {
10
- var _a = sets[len], to = _a[0], from = _a[1];
11
- text = text.replace(new RegExp("[".concat(from, "]"), "gi"), to);
4
+ */ export function removeAccents(text = "", sets = accentsSets) {
5
+ let len = sets.length;
6
+ while(len--){
7
+ const [to, from] = sets[len];
8
+ text = text.replace(new RegExp(`[${from}]`, "gi"), to);
12
9
  }
13
10
  return text;
14
11
  }
package/removeCookie.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 removeCookie(name: string, attributes?: CookieAttributesClient): void;
10
6
  export default removeCookie;
package/removeCookie.mjs CHANGED
@@ -1,15 +1,12 @@
1
- import { __assign } from "tslib";
2
1
  import { defaultAttributesClient } from "./cookie";
3
2
  import { setCookie } from "./setCookie";
4
3
  /**
5
4
  * @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
- export function removeCookie(name, attributes) {
12
- if (attributes === void 0) { attributes = {}; }
13
- setCookie(name, "", __assign(__assign(__assign({}, defaultAttributesClient), attributes), { expires: -1 }));
5
+ */ export function removeCookie(name, attributes = {}) {
6
+ setCookie(name, "", {
7
+ ...defaultAttributesClient,
8
+ ...attributes,
9
+ expires: -1
10
+ });
14
11
  }
15
12
  export default removeCookie;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // /**
3
2
  // * FIXME: Type 'Set<any>' can only be iterated through when using the
4
3
  // * '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
@@ -3,13 +3,11 @@
3
3
  * comparison of each object's given key
4
4
  *
5
5
  * @category array
6
- */
7
- export function removeDuplicatesByKey(array, key) {
8
- if (array === void 0) { array = []; }
9
- var keysMap = {};
10
- var output = [];
11
- for (var i = 0; i < array.length; i++) {
12
- var item = array[i];
6
+ */ export function removeDuplicatesByKey(array = [], key) {
7
+ const keysMap = {};
8
+ const output = [];
9
+ for(let i = 0; i < array.length; i++){
10
+ const item = array[i];
13
11
  if (!keysMap[item[key]]) {
14
12
  output.push(item);
15
13
  keysMap[item[key]] = true;
@@ -1,10 +1,9 @@
1
- import { removeIndexesFromArray } from "./removeIndexesFromArray";
2
1
  import { findDuplicatedIndexes } from "./findDuplicatedIndexes";
2
+ import { removeIndexesFromArray } from "./removeIndexesFromArray";
3
3
  /**
4
4
  * @category array
5
- */
6
- export function removeDuplicatesComparing(from, to) {
7
- var indexes = findDuplicatedIndexes(from);
5
+ */ export function removeDuplicatesComparing(from, to) {
6
+ const indexes = findDuplicatedIndexes(from);
8
7
  return removeIndexesFromArray(to, indexes);
9
8
  }
10
9
  export default removeDuplicatesComparing;
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * @category array
3
- */
4
- export function removeIndexesFromArray(arr, indexes) {
5
- var output = [];
6
- for (var i = 0; i < arr.length; i++) {
3
+ */ export function removeIndexesFromArray(arr, indexes) {
4
+ const output = [];
5
+ for(let i = 0; i < arr.length; i++){
7
6
  // eslint-disable-next-line no-prototype-builtins
8
7
  if (!indexes.hasOwnProperty(i)) {
9
8
  output.push(arr[i]);
@@ -2,9 +2,7 @@
2
2
  * Strips out the trailing slash
3
3
  *
4
4
  * @category location
5
- */
6
- export function removeTralingSlash(urlLike) {
7
- if (urlLike === void 0) { urlLike = ""; }
5
+ */ export function removeTralingSlash(urlLike = "") {
8
6
  return urlLike.replace(/\/*$/, "");
9
7
  }
10
8
  export default removeTralingSlash;
@@ -2,7 +2,6 @@
2
2
  * Remove the given keys from the given URL query parameters
3
3
  *
4
4
  * @category location
5
- * @pure
6
5
  */
7
6
  export declare function removeUrlQueryParams(url: string, paramsToRemove?: string[]): string;
8
7
  export default removeUrlQueryParams;
@@ -4,14 +4,11 @@ import getUrlQueryParams from "./getUrlQueryParams";
4
4
  * Remove the given keys from the given URL query parameters
5
5
  *
6
6
  * @category location
7
- * @pure
8
- */
9
- export function removeUrlQueryParams(url, paramsToRemove) {
10
- if (paramsToRemove === void 0) { paramsToRemove = []; }
11
- var parts = url.split("?");
12
- var allParams = getUrlQueryParams(url);
13
- var params = {};
14
- for (var key in allParams) {
7
+ */ export function removeUrlQueryParams(url, paramsToRemove = []) {
8
+ const parts = url.split("?");
9
+ const allParams = getUrlQueryParams(url);
10
+ const params = {};
11
+ for(const key in allParams){
15
12
  if (!paramsToRemove.includes(key)) {
16
13
  params[key] = allParams[key];
17
14
  }
package/render.d.ts CHANGED
@@ -33,9 +33,10 @@ type RenderFunction = (data: object) => string;
33
33
  * <%! %> for interpolation with encoding
34
34
  * ```
35
35
  *
36
+ * @category impl
36
37
  * @example
37
38
  *
38
- * ```js
39
+ * ```ts
39
40
  * import { render } from "...";
40
41
  *
41
42
  * const data = { name: "XYZ" };
package/render.mjs CHANGED
@@ -1,57 +1,51 @@
1
- var varname = "data";
2
- var evaluate = /<%([\s\S]+?(\}?)+)%>/g;
3
- var interpolate = /<%=([\s\S]+?)%>/g;
4
- var conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
5
- var iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
1
+ const varname = "data";
2
+ const evaluate = /<%([\s\S]+?(\}?)+)%>/g;
3
+ const interpolate = /<%=([\s\S]+?)%>/g;
4
+ const conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
5
+ const iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
6
6
  // const encode = /<%!([\s\S]+?)%>/g;
7
- var use = /<%#([\s\S]+?)%>/g;
8
- var useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
9
- var define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
10
- var defineParams = /^\s*([\w$]+):([\s\S]+)/;
11
- var start = "'+(";
12
- var end = ")+'";
7
+ const use = /<%#([\s\S]+?)%>/g;
8
+ const useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
9
+ const define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
10
+ const defineParams = /^\s*([\w$]+):([\s\S]+)/;
11
+ const start = "'+(";
12
+ const end = ")+'";
13
13
  // const startencode = "'+encodeHTML(";
14
- var skip = /$^/;
15
- var resolveDefs = function (block, def) {
16
- return (typeof block === "string" ? block : block.toString())
17
- .replace(define || skip, function (_, code, assign, value) {
14
+ const skip = /$^/;
15
+ const resolveDefs = (block, def)=>(typeof block === "string" ? block : block.toString()).replace(define || skip, (_, code, assign, value)=>{
18
16
  if (code.indexOf("def.") === 0) {
19
17
  code = code.substring(4);
20
18
  }
21
19
  if (!(code in def)) {
22
20
  if (assign === ":") {
23
- value.replace(defineParams,
24
- // @ts-expect-error nevermind
25
- function (_, param, v) {
26
- def[code] = { arg: param, text: v };
21
+ value.replace(defineParams, // @ts-expect-error nevermind
22
+ (_, param, v)=>{
23
+ def[code] = {
24
+ arg: param,
25
+ text: v
26
+ };
27
27
  });
28
28
  // @ts-expect-error nevermind
29
- if (!(code in def))
30
- def[code] = value;
31
- }
32
- else {
29
+ if (!(code in def)) def[code] = value;
30
+ } else {
33
31
  new Function("def", "def['" + code + "']=" + value)(def);
34
32
  }
35
33
  }
36
34
  return "";
37
- })
38
- .replace(use || skip, function (_, code) {
39
- code = code.replace(useParams, function (_, s, d, param) {
35
+ }).replace(use || skip, (_, code)=>{
36
+ code = code.replace(useParams, (_, s, d, param)=>{
40
37
  if (def[d] && def[d].arg && param) {
41
- var rw = (d + ":" + param).replace(/'|\\/g, "_");
38
+ const rw = (d + ":" + param).replace(/'|\\/g, "_");
42
39
  def.__exp = def.__exp || {};
43
40
  def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
44
41
  return s + "def.__exp['" + rw + "']";
45
42
  }
46
43
  return s;
47
44
  });
48
- var v = new Function("def", "return " + code)(def);
45
+ const v = new Function("def", "return " + code)(def);
49
46
  return v ? resolveDefs(v, def) : v;
50
47
  });
51
- };
52
- var unescape = function (code) {
53
- return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
54
- };
48
+ const unescape = (code)=>code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
55
49
  /**
56
50
  * Render template (adapted from doT.js)
57
51
  *
@@ -73,9 +67,10 @@ var unescape = function (code) {
73
67
  * <%! %> for interpolation with encoding
74
68
  * ```
75
69
  *
70
+ * @category impl
76
71
  * @example
77
72
  *
78
- * ```js
73
+ * ```ts
79
74
  * import { render } from "...";
80
75
  *
81
76
  * const data = { name: "XYZ" };
@@ -87,79 +82,30 @@ var unescape = function (code) {
87
82
  *
88
83
  * @borrows [olado/doT by Laura Doktorova](https://github.com/olado/doT)
89
84
  * @see https://olado.github.io/doT/index.html
90
- */
91
- export var render = function (tmpl, def) {
92
- var sid = 0;
93
- var indv;
94
- var str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
95
- str = ("var X='" +
96
- str
97
- .replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ")
98
- .replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "")
99
- .replace(/'|\\/g, "\\$&")
100
- .replace(interpolate || skip, function (_, code) { return start + unescape(code) + end; })
101
- // .replace(
102
- // encode || skip,
103
- // (_, code) => cse.startencode + unescape(code) + cse.end
104
- // )
105
- .replace(conditional || skip, function (_, elseCase, code) {
106
- return elseCase
107
- ? code
108
- ? "';}else if(" + unescape(code) + "){X+='"
109
- : "';}else{X+='"
110
- : code
111
- ? "';if(" + unescape(code) + "){X+='"
112
- : "';}X+='";
113
- })
114
- .replace(iterate || skip, function (_, arr, vName, iName) {
115
- if (!arr)
116
- return "';} } X+='";
117
- sid++;
118
- indv = iName || "i" + sid;
119
- arr = unescape(arr);
120
- return ("';var arr" +
121
- sid +
122
- "=" +
123
- arr +
124
- ";if(arr" +
125
- sid +
126
- "){var " +
127
- vName +
128
- "," +
129
- indv +
130
- "=-1,l" +
131
- sid +
132
- "=arr" +
133
- sid +
134
- ".length-1;while(" +
135
- indv +
136
- "<l" +
137
- sid +
138
- "){" +
139
- vName +
140
- "=arr" +
141
- sid +
142
- "[" +
143
- indv +
144
- "+=1];X+='");
145
- })
146
- .replace(evaluate || skip, function (_, code) { return "';" + unescape(code) + "X+='"; }) +
147
- "';return X;")
148
- .replace(/\n/g, "\\n")
149
- .replace(/\t/g, "\\t")
150
- .replace(/\r/g, "\\r")
151
- .replace(/(\s|;|\}|^|\{)X\+='';/g, "$1")
152
- .replace(/\+''/g, "");
85
+ */ export const render = (tmpl, def)=>{
86
+ let sid = 0;
87
+ let indv;
88
+ let str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
89
+ str = ("var X='" + str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "").replace(/'|\\/g, "\\$&").replace(interpolate || skip, (_, code)=>start + unescape(code) + end)// .replace(
90
+ // encode || skip,
91
+ // (_, code) => cse.startencode + unescape(code) + cse.end
92
+ // )
93
+ .replace(conditional || skip, (_, elseCase, code)=>elseCase ? code ? "';}else if(" + unescape(code) + "){X+='" : "';}else{X+='" : code ? "';if(" + unescape(code) + "){X+='" : "';}X+='").replace(iterate || skip, (_, arr, vName, iName)=>{
94
+ if (!arr) return "';} } X+='";
95
+ sid++;
96
+ indv = iName || "i" + sid;
97
+ arr = unescape(arr);
98
+ return "';var arr" + sid + "=" + arr + ";if(arr" + sid + "){var " + vName + "," + indv + "=-1,l" + sid + "=arr" + sid + ".length-1;while(" + indv + "<l" + sid + "){" + vName + "=arr" + sid + "[" + indv + "+=1];X+='";
99
+ }).replace(evaluate || skip, (_, code)=>"';" + unescape(code) + "X+='") + "';return X;").replace(/\n/g, "\\n").replace(/\t/g, "\\t").replace(/\r/g, "\\r").replace(/(\s|;|\}|^|\{)X\+='';/g, "$1").replace(/\+''/g, "");
153
100
  //.replace(/(\s|;|\}|^|\{)X\+=''\+/g,'$1X+=');
154
101
  try {
155
102
  return new Function(varname, str);
156
- }
157
- catch (e) {
103
+ } catch (e) {
158
104
  if (process.env["NODE_ENV"] !== "production") {
159
105
  console.log("Could not create a template function: " + str);
160
106
  throw e;
161
107
  }
162
108
  }
163
- return function () { return ""; };
109
+ return ()=>"";
164
110
  };
165
111
  export default render;
package/roundTo.mjs CHANGED
@@ -3,28 +3,26 @@
3
3
  *
4
4
  * @category math
5
5
  * @see https://stackoverflow.com/a/15762794/1938970
6
- */
7
- export function roundTo(num, decimals) {
8
- if (decimals === void 0) { decimals = 2; }
6
+ */ export function roundTo(num, decimals = 2) {
9
7
  if (isFinite(num) && !isNaN(num)) {
10
8
  // method 1
11
9
  // return Number(num).toFixed(decimals);
12
10
  // method 2: @see https://stackoverflow.com/a/43532829/1938970
13
- var multiplicator = Math.pow(10, decimals);
11
+ const multiplicator = Math.pow(10, decimals);
14
12
  return Math.round(num * multiplicator) / multiplicator + "";
15
- // method 3: @see https://stackoverflow.com/a/15762794/1938970
16
- // let negative = false;
17
- // if (num < 0) {
18
- // negative = true;
19
- // num = num * -1;
20
- // }
21
- // const multiplicator = Math.pow(10, decimals);
22
- // const outputStr = parseFloat((num * multiplicator).toFixed(11));
23
- // let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
24
- // if (negative) {
25
- // return (Number(outputNum) * -1).toFixed(decimals);
26
- // }
27
- // return outputNum;
13
+ // method 3: @see https://stackoverflow.com/a/15762794/1938970
14
+ // let negative = false;
15
+ // if (num < 0) {
16
+ // negative = true;
17
+ // num = num * -1;
18
+ // }
19
+ // const multiplicator = Math.pow(10, decimals);
20
+ // const outputStr = parseFloat((num * multiplicator).toFixed(11));
21
+ // let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
22
+ // if (negative) {
23
+ // return (Number(outputNum) * -1).toFixed(decimals);
24
+ // }
25
+ // return outputNum;
28
26
  }
29
27
  if (process.env["NODE_ENV"] !== "production") {
30
28
  console.warn("[@koine/utils] math:roundTo -> given not a finite number as first arg");
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @file
2
+ * @module
3
3
  *
4
4
  * @category cookie
5
5
  *
@@ -18,10 +18,6 @@ import { type CookieAttributesServer } from "./cookie";
18
18
  * => "foo=bar; httpOnly"
19
19
  *
20
20
  * @category cookie
21
- *
22
- * All cookie related code is inspired and adapted from:
23
- * - [js-cookie](https://github.com/js-cookie/js-cookie)
24
- * - [cookie](https://github.com/jshttp/cookie)
25
21
  */
26
22
  export declare function serializeCookie(name: string, val: string, attributes?: CookieAttributesServer): string;
27
23
  export default serializeCookie;