yummies 7.19.4 → 7.20.1

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 (162) hide show
  1. package/assert.cjs +1 -1
  2. package/assert.cjs.map +1 -1
  3. package/assert.js +1 -1
  4. package/assert.js.map +1 -1
  5. package/async.cjs +147 -137
  6. package/async.cjs.map +1 -1
  7. package/async.d.ts +98 -131
  8. package/async.js +147 -137
  9. package/async.js.map +1 -1
  10. package/common.cjs +3 -1
  11. package/common.cjs.map +1 -1
  12. package/common.d.ts +18 -24
  13. package/common.js +3 -1
  14. package/common.js.map +1 -1
  15. package/complex.cjs +1 -0
  16. package/complex.cjs.map +1 -1
  17. package/complex.js +1 -0
  18. package/complex.js.map +1 -1
  19. package/cookie.cjs +1 -1
  20. package/cookie.cjs.map +1 -1
  21. package/cookie.d.ts +0 -18
  22. package/cookie.js +1 -1
  23. package/cookie.js.map +1 -1
  24. package/css-cx.cjs +78 -0
  25. package/css-cx.cjs.map +1 -0
  26. package/css-cx.d.ts +69 -0
  27. package/css-cx.js +74 -0
  28. package/css-cx.js.map +1 -0
  29. package/css.cjs +32 -111
  30. package/css.cjs.map +1 -1
  31. package/css.d.ts +32 -42
  32. package/css.js +30 -107
  33. package/css.js.map +1 -1
  34. package/data.cjs +60 -50
  35. package/data.cjs.map +1 -1
  36. package/data.d.ts +21 -34
  37. package/data.js +60 -50
  38. package/data.js.map +1 -1
  39. package/date-time.cjs +104 -98
  40. package/date-time.cjs.map +1 -1
  41. package/date-time.d.ts +51 -57
  42. package/date-time.js +104 -97
  43. package/date-time.js.map +1 -1
  44. package/device.cjs +14 -19
  45. package/device.cjs.map +1 -1
  46. package/device.d.ts +15 -26
  47. package/device.js +14 -19
  48. package/device.js.map +1 -1
  49. package/encodings.cjs +1 -1
  50. package/encodings.cjs.map +1 -1
  51. package/encodings.d.ts +0 -17
  52. package/encodings.js +1 -1
  53. package/encodings.js.map +1 -1
  54. package/errors.cjs +1 -18
  55. package/errors.cjs.map +1 -1
  56. package/errors.d.ts +0 -17
  57. package/errors.js +1 -17
  58. package/errors.js.map +1 -1
  59. package/file.cjs +3 -17
  60. package/file.cjs.map +1 -1
  61. package/file.d.ts +1 -16
  62. package/file.js +3 -17
  63. package/file.js.map +1 -1
  64. package/format.cjs +1 -1
  65. package/format.cjs.map +1 -1
  66. package/format.js +1 -1
  67. package/format.js.map +1 -1
  68. package/html.cjs +112 -175
  69. package/html.cjs.map +1 -1
  70. package/html.d.ts +58 -57
  71. package/html.js +111 -172
  72. package/html.js.map +1 -1
  73. package/id-nanoid.cjs +36 -0
  74. package/id-nanoid.cjs.map +1 -0
  75. package/id-nanoid.d.ts +26 -0
  76. package/id-nanoid.js +32 -0
  77. package/id-nanoid.js.map +1 -0
  78. package/id.cjs +10 -45
  79. package/id.cjs.map +1 -1
  80. package/id.d.ts +27 -36
  81. package/id.js +6 -40
  82. package/id.js.map +1 -1
  83. package/imports.cjs +3 -18
  84. package/imports.cjs.map +1 -1
  85. package/imports.d.ts +1 -16
  86. package/imports.js +3 -17
  87. package/imports.js.map +1 -1
  88. package/math.cjs +16 -12
  89. package/math.cjs.map +1 -1
  90. package/math.d.ts +9 -24
  91. package/math.js +16 -12
  92. package/math.js.map +1 -1
  93. package/media.cjs +88 -89
  94. package/media.cjs.map +1 -1
  95. package/media.d.ts +72 -80
  96. package/media.js +88 -88
  97. package/media.js.map +1 -1
  98. package/mobx.cjs +0 -1
  99. package/mobx.cjs.map +1 -1
  100. package/mobx.js.map +1 -1
  101. package/ms.cjs +3 -17
  102. package/ms.cjs.map +1 -1
  103. package/ms.d.ts +1 -16
  104. package/ms.js +3 -17
  105. package/ms.js.map +1 -1
  106. package/number.cjs +1 -17
  107. package/number.cjs.map +1 -1
  108. package/number.d.ts +0 -16
  109. package/number.js +1 -17
  110. package/number.js.map +1 -1
  111. package/package.json +6 -6
  112. package/parser.cjs +1 -1
  113. package/parser.cjs.map +1 -1
  114. package/parser.js +1 -1
  115. package/parser.js.map +1 -1
  116. package/price.cjs +1 -1
  117. package/price.cjs.map +1 -1
  118. package/price.d.ts +0 -16
  119. package/price.js +1 -1
  120. package/price.js.map +1 -1
  121. package/random.cjs +37 -39
  122. package/random.cjs.map +1 -1
  123. package/random.d.ts +31 -40
  124. package/random.js +37 -39
  125. package/random.js.map +1 -1
  126. package/react.cjs +0 -1
  127. package/react.cjs.map +1 -1
  128. package/react.js.map +1 -1
  129. package/sanitize-html.cjs +82 -0
  130. package/sanitize-html.cjs.map +1 -0
  131. package/sanitize-html.d.ts +28 -0
  132. package/sanitize-html.js +79 -0
  133. package/sanitize-html.js.map +1 -0
  134. package/sound.cjs +1 -17
  135. package/sound.cjs.map +1 -1
  136. package/sound.d.ts +0 -16
  137. package/sound.js +1 -17
  138. package/sound.js.map +1 -1
  139. package/storage.cjs +7 -5
  140. package/storage.cjs.map +1 -1
  141. package/storage.d.ts +3 -17
  142. package/storage.js +7 -5
  143. package/storage.js.map +1 -1
  144. package/text.cjs +3 -17
  145. package/text.cjs.map +1 -1
  146. package/text.d.ts +1 -16
  147. package/text.js +3 -17
  148. package/text.js.map +1 -1
  149. package/type-guard.cjs +38 -1
  150. package/type-guard.cjs.map +1 -1
  151. package/type-guard.d.ts +38 -0
  152. package/type-guard.js +38 -1
  153. package/type-guard.js.map +1 -1
  154. package/types.d.ts +20 -1
  155. package/types.global.d.ts +19 -0
  156. package/vibrate.cjs +1 -17
  157. package/vibrate.cjs.map +1 -1
  158. package/vibrate.d.ts +0 -16
  159. package/vibrate.js +1 -17
  160. package/vibrate.js.map +1 -1
  161. /package/{chunk-pbuEa-1d.js → chunk-D7D4PA-g.js} +0 -0
  162. /package/{chunk-CZWwpsFl.cjs → chunk-DakpK96I.cjs} +0 -0
package/id.d.ts CHANGED
@@ -1,39 +1,3 @@
1
- /**
2
- * ---header-docs-section---
3
- * # yummies/id
4
- *
5
- * ## Description
6
- *
7
- * Fast, URL-friendly identifiers based on **nanoid** with curated alphabets and lengths. Use for
8
- * client-generated keys, trace ids, or UI instance ids where UUID size is unnecessary. Collisions are
9
- * unlikely at these lengths but still assume server-side uniqueness for persisted entities.
10
- *
11
- * ## Usage
12
- *
13
- * ```ts
14
- * import { generateId } from "yummies/id";
15
- * ```
16
- */
17
- /**
18
- * Uses the alphabet `abcdefghijklmnopqrstuvwxyz0123456789`.
19
- * Length: 6.
20
- */
21
- declare const generateId: (size?: number) => string;
22
- /**
23
- * Uses the alphabet `abcdefghijklmnopqrstuvwxyz0123456789`.
24
- * Length: 4.
25
- */
26
- declare const generateShortId: (size?: number) => string;
27
- /**
28
- * Uses the alphabet `0123456789`.
29
- * Length: 6.
30
- */
31
- declare const generateNumericId: (size?: number) => string;
32
- /**
33
- * Uses the alphabet `0123456789`.
34
- * Length: 4.
35
- */
36
- declare const generateNumericShortId: (size?: number) => string;
37
1
  /**
38
2
  * Creates a function that generates unique strings based on call order.
39
3
  *
@@ -54,6 +18,7 @@ declare const generateNumericShortId: (size?: number) => string;
54
18
  * @returns {()=>string}
55
19
  */
56
20
  declare const createLinearNumericIdGenerator: (size?: number) => () => string;
21
+
57
22
  /**
58
23
  *
59
24
  * @example
@@ -70,6 +35,7 @@ declare const createLinearNumericIdGenerator: (size?: number) => () => string;
70
35
  *
71
36
  */
72
37
  declare const generateLinearNumericId: () => string;
38
+
73
39
  /**
74
40
  * Is not recommended to use.
75
41
  *
@@ -77,4 +43,29 @@ declare const generateLinearNumericId: () => string;
77
43
  */
78
44
  declare const generateStackBasedId: () => string;
79
45
 
46
+ /**
47
+ * @internal Separate chunk so nanoid is tree-shaken away when generateId/generateShortId/etc.
48
+ * are not used. Consumers import from `yummies/id` — this module is not a public entry point.
49
+ */
50
+ /**
51
+ * Uses the alphabet `abcdefghijklmnopqrstuvwxyz0123456789`.
52
+ * Length: 6.
53
+ */
54
+ declare const generateId: (size?: number) => string;
55
+ /**
56
+ * Uses the alphabet `abcdefghijklmnopqrstuvwxyz0123456789`.
57
+ * Length: 4.
58
+ */
59
+ declare const generateShortId: (size?: number) => string;
60
+ /**
61
+ * Uses the alphabet `0123456789`.
62
+ * Length: 6.
63
+ */
64
+ declare const generateNumericId: (size?: number) => string;
65
+ /**
66
+ * Uses the alphabet `0123456789`.
67
+ * Length: 4.
68
+ */
69
+ declare const generateNumericShortId: (size?: number) => string;
70
+
80
71
  export { createLinearNumericIdGenerator, generateId, generateLinearNumericId, generateNumericId, generateNumericShortId, generateShortId, generateStackBasedId };
package/id.js CHANGED
@@ -1,43 +1,5 @@
1
- import { customAlphabet } from "nanoid";
2
- //#region src/id.ts
3
- /**
4
- * ---header-docs-section---
5
- * # yummies/id
6
- *
7
- * ## Description
8
- *
9
- * Fast, URL-friendly identifiers based on **nanoid** with curated alphabets and lengths. Use for
10
- * client-generated keys, trace ids, or UI instance ids where UUID size is unnecessary. Collisions are
11
- * unlikely at these lengths but still assume server-side uniqueness for persisted entities.
12
- *
13
- * ## Usage
14
- *
15
- * ```ts
16
- * import { generateId } from "yummies/id";
17
- * ```
18
- */
19
- var DIGITS = "0123456789";
20
- var ALPHABET = `abcdefghijklmnopqrstuvwxyz${DIGITS}`;
21
- /**
22
- * Uses the alphabet `abcdefghijklmnopqrstuvwxyz0123456789`.
23
- * Length: 6.
24
- */
25
- var generateId = customAlphabet(ALPHABET, 6);
26
- /**
27
- * Uses the alphabet `abcdefghijklmnopqrstuvwxyz0123456789`.
28
- * Length: 4.
29
- */
30
- var generateShortId = customAlphabet(ALPHABET, 4);
31
- /**
32
- * Uses the alphabet `0123456789`.
33
- * Length: 6.
34
- */
35
- var generateNumericId = customAlphabet(DIGITS, 6);
36
- /**
37
- * Uses the alphabet `0123456789`.
38
- * Length: 4.
39
- */
40
- var generateNumericShortId = customAlphabet(DIGITS, 4);
1
+ import { generateId, generateNumericId, generateNumericShortId, generateShortId } from "./id-nanoid.js";
2
+ //#region src/id/create-linear-numeric-id-generator.ts
41
3
  /**
42
4
  * Creates a function that generates unique strings based on call order.
43
5
  *
@@ -63,6 +25,8 @@ var createLinearNumericIdGenerator = (size = 9) => {
63
25
  return (lastCount++).toString().padStart(size, "0");
64
26
  };
65
27
  };
28
+ //#endregion
29
+ //#region src/id/generate-linear-numeric-id.ts
66
30
  /**
67
31
  *
68
32
  * @example
@@ -79,6 +43,8 @@ var createLinearNumericIdGenerator = (size = 9) => {
79
43
  *
80
44
  */
81
45
  var generateLinearNumericId = createLinearNumericIdGenerator();
46
+ //#endregion
47
+ //#region src/id/generate-stack-based-id.ts
82
48
  /**
83
49
  * Is not recommended to use.
84
50
  *
package/id.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"id.js","names":[],"sources":["../src/id.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/id\n *\n * ## Description\n *\n * Fast, URL-friendly identifiers based on **nanoid** with curated alphabets and lengths. Use for\n * client-generated keys, trace ids, or UI instance ids where UUID size is unnecessary. Collisions are\n * unlikely at these lengths but still assume server-side uniqueness for persisted entities.\n *\n * ## Usage\n *\n * ```ts\n * import { generateId } from \"yummies/id\";\n * ```\n */\n\nimport { customAlphabet } from 'nanoid';\n\nconst DIGITS = '0123456789';\nconst LATIN_CHARS = 'abcdefghijklmnopqrstuvwxyz';\n\nconst ALPHABET = `${LATIN_CHARS}${DIGITS}`;\n\n/**\n * Uses the alphabet `abcdefghijklmnopqrstuvwxyz0123456789`.\n * Length: 6.\n */\nexport const generateId = customAlphabet(ALPHABET, 6);\n\n/**\n * Uses the alphabet `abcdefghijklmnopqrstuvwxyz0123456789`.\n * Length: 4.\n */\nexport const generateShortId = customAlphabet(ALPHABET, 4);\n\n/**\n * Uses the alphabet `0123456789`.\n * Length: 6.\n */\nexport const generateNumericId = customAlphabet(DIGITS, 6);\n\n/**\n * Uses the alphabet `0123456789`.\n * Length: 4.\n */\nexport const generateNumericShortId = customAlphabet(DIGITS, 4);\n\n/**\n * Creates a function that generates unique strings based on call order.\n *\n * @example\n * ```ts\n * generateLinearNumericId = createLinearNumericIdGenerator(6);\n * generateLinearNumericId() // '000000'\n * generateLinearNumericId() // '000001'\n * ...\n * generateLinearNumericId() // '999999'\n * generateLinearNumericId() // '1000000'\n * ...\n * generateLinearNumericId() // '9999999'\n * generateLinearNumericId() // '10000000'\n * ```\n *\n * @param size Minimum string length.\n * @returns {()=>string}\n */\nexport const createLinearNumericIdGenerator = (size: number = 9) => {\n let lastCount = 0;\n return () => {\n return (lastCount++).toString().padStart(size, '0');\n };\n};\n\n/**\n *\n * @example\n * ```ts\n * generateLinearNumericId() // '000000000'\n * generateLinearNumericId() // '000000001'\n * ...\n * generateLinearNumericId() // '999999999'\n * generateLinearNumericId() // '1000000000'\n * ...\n * generateLinearNumericId() // '9999999999'\n * generateLinearNumericId() // '10000000000'\n * ```\n *\n */\nexport const generateLinearNumericId = createLinearNumericIdGenerator();\n\n/**\n * Is not recommended to use.\n *\n * Generates execution stack based pseudo-id (just sliced string from error stack)\n */\nexport const generateStackBasedId = () =>\n new Error().stack!.split('\\n').slice(1, 4).join('');\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,IAAM,SAAS;AAGf,IAAM,WAAW,6BAAiB;;;;;AAMlC,IAAa,aAAa,eAAe,UAAU,EAAE;;;;;AAMrD,IAAa,kBAAkB,eAAe,UAAU,EAAE;;;;;AAM1D,IAAa,oBAAoB,eAAe,QAAQ,EAAE;;;;;AAM1D,IAAa,yBAAyB,eAAe,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;AAqB/D,IAAa,kCAAkC,OAAe,MAAM;CAClE,IAAI,YAAY;AAChB,cAAa;AACX,UAAQ,aAAa,UAAU,CAAC,SAAS,MAAM,IAAI;;;;;;;;;;;;;;;;;;AAmBvD,IAAa,0BAA0B,gCAAgC;;;;;;AAOvE,IAAa,8CACX,IAAI,OAAO,EAAC,MAAO,MAAM,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC,KAAK,GAAG"}
1
+ {"version":3,"file":"id.js","names":[],"sources":["../src/id/create-linear-numeric-id-generator.ts","../src/id/generate-linear-numeric-id.ts","../src/id/generate-stack-based-id.ts"],"sourcesContent":["/**\n * Creates a function that generates unique strings based on call order.\n *\n * @example\n * ```ts\n * generateLinearNumericId = createLinearNumericIdGenerator(6);\n * generateLinearNumericId() // '000000'\n * generateLinearNumericId() // '000001'\n * ...\n * generateLinearNumericId() // '999999'\n * generateLinearNumericId() // '1000000'\n * ...\n * generateLinearNumericId() // '9999999'\n * generateLinearNumericId() // '10000000'\n * ```\n *\n * @param size Minimum string length.\n * @returns {()=>string}\n */\nexport const createLinearNumericIdGenerator = (size: number = 9) => {\n let lastCount = 0;\n return () => {\n return (lastCount++).toString().padStart(size, '0');\n };\n};\n","import { createLinearNumericIdGenerator } from './create-linear-numeric-id-generator.js';\n\n/**\n *\n * @example\n * ```ts\n * generateLinearNumericId() // '000000000'\n * generateLinearNumericId() // '000000001'\n * ...\n * generateLinearNumericId() // '999999999'\n * generateLinearNumericId() // '1000000000'\n * ...\n * generateLinearNumericId() // '9999999999'\n * generateLinearNumericId() // '10000000000'\n * ```\n *\n */\nexport const generateLinearNumericId = createLinearNumericIdGenerator();\n","/**\n * Is not recommended to use.\n *\n * Generates execution stack based pseudo-id (just sliced string from error stack)\n */\nexport const generateStackBasedId = () =>\n new Error().stack!.split('\\n').slice(1, 4).join('');\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,kCAAkC,OAAe,MAAM;CAClE,IAAI,YAAY;CAChB,aAAa;EACX,QAAQ,aAAa,SAAS,EAAE,SAAS,MAAM,GAAG;CACpD;AACF;;;;;;;;;;;;;;;;;;ACPA,IAAa,0BAA0B,+BAA+B;;;;;;;;ACZtE,IAAa,8CACX,IAAI,MAAM,GAAE,MAAO,MAAM,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE"}
package/imports.cjs CHANGED
@@ -1,23 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("./chunk-CZWwpsFl.cjs");
3
2
  let yummies_async = require("yummies/async");
4
- //#region src/imports.ts
5
- /**
6
- * ---header-docs-section---
7
- * # yummies/imports
8
- *
9
- * ## Description
10
- *
11
- * Patterns for **dynamic `import()`**: retry with backoff, unpacking `{ default }` from mixed ESM
12
- * shapes, and typed helpers around lazy-loaded modules. Ideal for code-split routes, optional panels,
13
- * and resilient loading when the network or CDN flakes without freezing the whole app.
14
- *
15
- * ## Usage
16
- *
17
- * ```ts
18
- * import { fetchLazyModule } from "yummies/imports";
19
- * ```
20
- */
3
+ //#region src/imports/fetch-lazy-module.ts
21
4
  /**
22
5
  * Lazily loads a module with retry support.
23
6
  *
@@ -39,6 +22,8 @@ var fetchLazyModule = async (fetchModule, attempts = 3, delay = 1e3) => {
39
22
  }
40
23
  throw lastError;
41
24
  };
25
+ //#endregion
26
+ //#region src/imports/unpack-async-module.ts
42
27
  /**
43
28
  * Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.
44
29
  *
package/imports.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"imports.cjs","names":[],"sources":["../src/imports.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/imports\n *\n * ## Description\n *\n * Patterns for **dynamic `import()`**: retry with backoff, unpacking `{ default }` from mixed ESM\n * shapes, and typed helpers around lazy-loaded modules. Ideal for code-split routes, optional panels,\n * and resilient loading when the network or CDN flakes without freezing the whole app.\n *\n * ## Usage\n *\n * ```ts\n * import { fetchLazyModule } from \"yummies/imports\";\n * ```\n */\n\nimport { sleep } from 'yummies/async';\n\n/**\n * Lazily loads a module with retry support.\n *\n * @example\n * ```ts\n * fetchLazyModule(() => import('./test.ts'), 3) // starts loading test.ts\n * // If loading test.ts fails, fetchLazyModule retries by calling fetchModule() again\n * // It retries as many times as specified by attempts (3 by default)\n * ```\n */\nexport const fetchLazyModule = async <T>(\n fetchModule: () => Promise<T>,\n attempts = 3,\n delay = 1000,\n): Promise<T> => {\n const attemptsArray = Array.from<typeof fetchModule>({\n length: attempts,\n }).fill(fetchModule);\n\n let lastError: null | Error = null;\n\n for await (const attempt of attemptsArray) {\n try {\n if (lastError !== null) {\n await sleep(delay);\n }\n return await attempt();\n } catch (error) {\n lastError = error as Error;\n }\n }\n throw lastError;\n};\n\nexport type PackedAsyncModule<T> = Promise<T | { default: T }>;\n\n/**\n * Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.\n *\n * @example\n * ```ts\n * const component = await unpackAsyncModule(import('./Component.ts'));\n * ```\n */\nexport const unpackAsyncModule = async <T>(\n maybeModule: T | PackedAsyncModule<T>,\n): Promise<T> => {\n if (maybeModule instanceof Promise) {\n const data = (await maybeModule) as any;\n\n if ((data as any).default) {\n return (data as any).default;\n } else {\n return data;\n }\n }\n\n return maybeModule;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,kBAAkB,OAC7B,aACA,WAAW,GACX,QAAQ,QACO;CACf,MAAM,gBAAgB,MAAM,KAAyB,EACnD,QAAQ,UACT,CAAC,CAAC,KAAK,YAAY;CAEpB,IAAI,YAA0B;AAE9B,YAAW,MAAM,WAAW,cAC1B,KAAI;AACF,MAAI,cAAc,KAChB,QAAA,GAAA,cAAA,OAAY,MAAM;AAEpB,SAAO,MAAM,SAAS;UACf,OAAO;AACd,cAAY;;AAGhB,OAAM;;;;;;;;;;AAaR,IAAa,oBAAoB,OAC/B,gBACe;AACf,KAAI,uBAAuB,SAAS;EAClC,MAAM,OAAQ,MAAM;AAEpB,MAAK,KAAa,QAChB,QAAQ,KAAa;MAErB,QAAO;;AAIX,QAAO"}
1
+ {"version":3,"file":"imports.cjs","names":[],"sources":["../src/imports/fetch-lazy-module.ts","../src/imports/unpack-async-module.ts"],"sourcesContent":["import { sleep } from 'yummies/async';\n\n/**\n * Lazily loads a module with retry support.\n *\n * @example\n * ```ts\n * fetchLazyModule(() => import('./test.ts'), 3) // starts loading test.ts\n * // If loading test.ts fails, fetchLazyModule retries by calling fetchModule() again\n * // It retries as many times as specified by attempts (3 by default)\n * ```\n */\nexport const fetchLazyModule = async <T>(\n fetchModule: () => Promise<T>,\n attempts = 3,\n delay = 1000,\n): Promise<T> => {\n const attemptsArray = Array.from<typeof fetchModule>({\n length: attempts,\n }).fill(fetchModule);\n\n let lastError: null | Error = null;\n\n for await (const attempt of attemptsArray) {\n try {\n if (lastError !== null) {\n await sleep(delay);\n }\n return await attempt();\n } catch (error) {\n lastError = error as Error;\n }\n }\n throw lastError;\n};\n","export type PackedAsyncModule<T> = Promise<T | { default: T }>;\n\n/**\n * Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.\n *\n * @example\n * ```ts\n * const component = await unpackAsyncModule(import('./Component.ts'));\n * ```\n */\nexport const unpackAsyncModule = async <T>(\n maybeModule: T | PackedAsyncModule<T>,\n): Promise<T> => {\n if (maybeModule instanceof Promise) {\n const data = (await maybeModule) as any;\n\n if ((data as any).default) {\n return (data as any).default;\n } else {\n return data;\n }\n }\n\n return maybeModule;\n};\n"],"mappings":";;;;;;;;;;;;;AAYA,IAAa,kBAAkB,OAC7B,aACA,WAAW,GACX,QAAQ,QACO;CACf,MAAM,gBAAgB,MAAM,KAAyB,EACnD,QAAQ,SACV,CAAC,EAAE,KAAK,WAAW;CAEnB,IAAI,YAA0B;CAE9B,WAAW,MAAM,WAAW,eAC1B,IAAI;EACF,IAAI,cAAc,MAChB,OAAA,GAAA,cAAA,OAAY,KAAK;EAEnB,OAAO,MAAM,QAAQ;CACvB,SAAS,OAAO;EACd,YAAY;CACd;CAEF,MAAM;AACR;;;;;;;;;;;ACxBA,IAAa,oBAAoB,OAC/B,gBACe;CACf,IAAI,uBAAuB,SAAS;EAClC,MAAM,OAAQ,MAAM;EAEpB,IAAK,KAAa,SAChB,OAAQ,KAAa;OAErB,OAAO;CAEX;CAEA,OAAO;AACT"}
package/imports.d.ts CHANGED
@@ -1,19 +1,3 @@
1
- /**
2
- * ---header-docs-section---
3
- * # yummies/imports
4
- *
5
- * ## Description
6
- *
7
- * Patterns for **dynamic `import()`**: retry with backoff, unpacking `{ default }` from mixed ESM
8
- * shapes, and typed helpers around lazy-loaded modules. Ideal for code-split routes, optional panels,
9
- * and resilient loading when the network or CDN flakes without freezing the whole app.
10
- *
11
- * ## Usage
12
- *
13
- * ```ts
14
- * import { fetchLazyModule } from "yummies/imports";
15
- * ```
16
- */
17
1
  /**
18
2
  * Lazily loads a module with retry support.
19
3
  *
@@ -25,6 +9,7 @@
25
9
  * ```
26
10
  */
27
11
  declare const fetchLazyModule: <T>(fetchModule: () => Promise<T>, attempts?: number, delay?: number) => Promise<T>;
12
+
28
13
  type PackedAsyncModule<T> = Promise<T | {
29
14
  default: T;
30
15
  }>;
package/imports.js CHANGED
@@ -1,21 +1,5 @@
1
1
  import { sleep } from "yummies/async";
2
- //#region src/imports.ts
3
- /**
4
- * ---header-docs-section---
5
- * # yummies/imports
6
- *
7
- * ## Description
8
- *
9
- * Patterns for **dynamic `import()`**: retry with backoff, unpacking `{ default }` from mixed ESM
10
- * shapes, and typed helpers around lazy-loaded modules. Ideal for code-split routes, optional panels,
11
- * and resilient loading when the network or CDN flakes without freezing the whole app.
12
- *
13
- * ## Usage
14
- *
15
- * ```ts
16
- * import { fetchLazyModule } from "yummies/imports";
17
- * ```
18
- */
2
+ //#region src/imports/fetch-lazy-module.ts
19
3
  /**
20
4
  * Lazily loads a module with retry support.
21
5
  *
@@ -37,6 +21,8 @@ var fetchLazyModule = async (fetchModule, attempts = 3, delay = 1e3) => {
37
21
  }
38
22
  throw lastError;
39
23
  };
24
+ //#endregion
25
+ //#region src/imports/unpack-async-module.ts
40
26
  /**
41
27
  * Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.
42
28
  *
package/imports.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"imports.js","names":[],"sources":["../src/imports.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/imports\n *\n * ## Description\n *\n * Patterns for **dynamic `import()`**: retry with backoff, unpacking `{ default }` from mixed ESM\n * shapes, and typed helpers around lazy-loaded modules. Ideal for code-split routes, optional panels,\n * and resilient loading when the network or CDN flakes without freezing the whole app.\n *\n * ## Usage\n *\n * ```ts\n * import { fetchLazyModule } from \"yummies/imports\";\n * ```\n */\n\nimport { sleep } from 'yummies/async';\n\n/**\n * Lazily loads a module with retry support.\n *\n * @example\n * ```ts\n * fetchLazyModule(() => import('./test.ts'), 3) // starts loading test.ts\n * // If loading test.ts fails, fetchLazyModule retries by calling fetchModule() again\n * // It retries as many times as specified by attempts (3 by default)\n * ```\n */\nexport const fetchLazyModule = async <T>(\n fetchModule: () => Promise<T>,\n attempts = 3,\n delay = 1000,\n): Promise<T> => {\n const attemptsArray = Array.from<typeof fetchModule>({\n length: attempts,\n }).fill(fetchModule);\n\n let lastError: null | Error = null;\n\n for await (const attempt of attemptsArray) {\n try {\n if (lastError !== null) {\n await sleep(delay);\n }\n return await attempt();\n } catch (error) {\n lastError = error as Error;\n }\n }\n throw lastError;\n};\n\nexport type PackedAsyncModule<T> = Promise<T | { default: T }>;\n\n/**\n * Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.\n *\n * @example\n * ```ts\n * const component = await unpackAsyncModule(import('./Component.ts'));\n * ```\n */\nexport const unpackAsyncModule = async <T>(\n maybeModule: T | PackedAsyncModule<T>,\n): Promise<T> => {\n if (maybeModule instanceof Promise) {\n const data = (await maybeModule) as any;\n\n if ((data as any).default) {\n return (data as any).default;\n } else {\n return data;\n }\n }\n\n return maybeModule;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,kBAAkB,OAC7B,aACA,WAAW,GACX,QAAQ,QACO;CACf,MAAM,gBAAgB,MAAM,KAAyB,EACnD,QAAQ,UACT,CAAC,CAAC,KAAK,YAAY;CAEpB,IAAI,YAA0B;AAE9B,YAAW,MAAM,WAAW,cAC1B,KAAI;AACF,MAAI,cAAc,KAChB,OAAM,MAAM,MAAM;AAEpB,SAAO,MAAM,SAAS;UACf,OAAO;AACd,cAAY;;AAGhB,OAAM;;;;;;;;;;AAaR,IAAa,oBAAoB,OAC/B,gBACe;AACf,KAAI,uBAAuB,SAAS;EAClC,MAAM,OAAQ,MAAM;AAEpB,MAAK,KAAa,QAChB,QAAQ,KAAa;MAErB,QAAO;;AAIX,QAAO"}
1
+ {"version":3,"file":"imports.js","names":[],"sources":["../src/imports/fetch-lazy-module.ts","../src/imports/unpack-async-module.ts"],"sourcesContent":["import { sleep } from 'yummies/async';\n\n/**\n * Lazily loads a module with retry support.\n *\n * @example\n * ```ts\n * fetchLazyModule(() => import('./test.ts'), 3) // starts loading test.ts\n * // If loading test.ts fails, fetchLazyModule retries by calling fetchModule() again\n * // It retries as many times as specified by attempts (3 by default)\n * ```\n */\nexport const fetchLazyModule = async <T>(\n fetchModule: () => Promise<T>,\n attempts = 3,\n delay = 1000,\n): Promise<T> => {\n const attemptsArray = Array.from<typeof fetchModule>({\n length: attempts,\n }).fill(fetchModule);\n\n let lastError: null | Error = null;\n\n for await (const attempt of attemptsArray) {\n try {\n if (lastError !== null) {\n await sleep(delay);\n }\n return await attempt();\n } catch (error) {\n lastError = error as Error;\n }\n }\n throw lastError;\n};\n","export type PackedAsyncModule<T> = Promise<T | { default: T }>;\n\n/**\n * Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.\n *\n * @example\n * ```ts\n * const component = await unpackAsyncModule(import('./Component.ts'));\n * ```\n */\nexport const unpackAsyncModule = async <T>(\n maybeModule: T | PackedAsyncModule<T>,\n): Promise<T> => {\n if (maybeModule instanceof Promise) {\n const data = (await maybeModule) as any;\n\n if ((data as any).default) {\n return (data as any).default;\n } else {\n return data;\n }\n }\n\n return maybeModule;\n};\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,kBAAkB,OAC7B,aACA,WAAW,GACX,QAAQ,QACO;CACf,MAAM,gBAAgB,MAAM,KAAyB,EACnD,QAAQ,SACV,CAAC,EAAE,KAAK,WAAW;CAEnB,IAAI,YAA0B;CAE9B,WAAW,MAAM,WAAW,eAC1B,IAAI;EACF,IAAI,cAAc,MAChB,MAAM,MAAM,KAAK;EAEnB,OAAO,MAAM,QAAQ;CACvB,SAAS,OAAO;EACd,YAAY;CACd;CAEF,MAAM;AACR;;;;;;;;;;;ACxBA,IAAa,oBAAoB,OAC/B,gBACe;CACf,IAAI,uBAAuB,SAAS;EAClC,MAAM,OAAQ,MAAM;EAEpB,IAAK,KAAa,SAChB,OAAQ,KAAa;OAErB,OAAO;CAEX;CAEA,OAAO;AACT"}
package/math.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/math.ts
2
+ //#region src/math/deg-to-rad.ts
3
3
  /**
4
4
  * Converts degrees to radians.
5
5
  *
@@ -11,17 +11,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
11
11
  function degToRad(deg) {
12
12
  return deg * (Math.PI / 180);
13
13
  }
14
- /**
15
- * Converts radians to degrees.
16
- *
17
- * @example
18
- * ```ts
19
- * radToDeg(Math.PI); // 180
20
- * ```
21
- */
22
- function radToDeg(rad) {
23
- return rad * (180 / Math.PI);
24
- }
14
+ //#endregion
15
+ //#region src/math/percent-from.ts
25
16
  /**
26
17
  * Returns what percentage `value` is of `from`.
27
18
  * @example
@@ -34,6 +25,19 @@ var percentFrom = (value, from) => {
34
25
  return (value ?? 0) / (from ?? 0) * 100 || 0;
35
26
  };
36
27
  //#endregion
28
+ //#region src/math/rad-to-deg.ts
29
+ /**
30
+ * Converts radians to degrees.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * radToDeg(Math.PI); // 180
35
+ * ```
36
+ */
37
+ function radToDeg(rad) {
38
+ return rad * (180 / Math.PI);
39
+ }
40
+ //#endregion
37
41
  exports.degToRad = degToRad;
38
42
  exports.percentFrom = percentFrom;
39
43
  exports.radToDeg = radToDeg;
package/math.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"math.cjs","names":[],"sources":["../src/math.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/math\n *\n * ## Description\n *\n * Tiny math helpers: degree/radian conversion and nullable-safe percentage calculations. They wrap\n * common formulas so components do not repeat magic numbers or null checks when deriving layout or\n * charts from partially loaded data.\n *\n * ## Usage\n *\n * ```ts\n * import { degToRad, percentFrom } from \"yummies/math\";\n * ```\n */\n\nimport type { Maybe } from 'yummies/types';\n\n/**\n * Converts degrees to radians.\n *\n * @example\n * ```ts\n * degToRad(180); // Math.PI\n * ```\n */\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\n}\n\n/**\n * Converts radians to degrees.\n *\n * @example\n * ```ts\n * radToDeg(Math.PI); // 180\n * ```\n */\nexport function radToDeg(rad: number) {\n return rad * (180 / Math.PI);\n}\n\n/**\n * Returns what percentage `value` is of `from`.\n * @example\n * ```ts\n * percentFrom(500, 2000) // 25\n * percentFrom(1000, 2000) // 50\n * ```\n */\nexport const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {\n return ((value ?? 0) / (from ?? 0)) * 100 || 0;\n};\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,SAAS,KAAa;AACpC,QAAO,OAAO,KAAK,KAAK;;;;;;;;;;AAW1B,SAAgB,SAAS,KAAa;AACpC,QAAO,OAAO,MAAM,KAAK;;;;;;;;;;AAW3B,IAAa,eAAe,OAAsB,SAAwB;AACxE,SAAS,SAAS,MAAM,QAAQ,KAAM,OAAO"}
1
+ {"version":3,"file":"math.cjs","names":[],"sources":["../src/math/deg-to-rad.ts","../src/math/percent-from.ts","../src/math/rad-to-deg.ts"],"sourcesContent":["/**\n * Converts degrees to radians.\n *\n * @example\n * ```ts\n * degToRad(180); // Math.PI\n * ```\n */\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\n}\n","import type { Maybe } from 'yummies/types';\n\n/**\n * Returns what percentage `value` is of `from`.\n * @example\n * ```ts\n * percentFrom(500, 2000) // 25\n * percentFrom(1000, 2000) // 50\n * ```\n */\nexport const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {\n return ((value ?? 0) / (from ?? 0)) * 100 || 0;\n};\n","/**\n * Converts radians to degrees.\n *\n * @example\n * ```ts\n * radToDeg(Math.PI); // 180\n * ```\n */\nexport function radToDeg(rad: number) {\n return rad * (180 / Math.PI);\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,SAAS,KAAa;CACpC,OAAO,OAAO,KAAK,KAAK;AAC1B;;;;;;;;;;;ACAA,IAAa,eAAe,OAAsB,SAAwB;CACxE,QAAS,SAAS,MAAM,QAAQ,KAAM,OAAO;AAC/C;;;;;;;;;;;ACJA,SAAgB,SAAS,KAAa;CACpC,OAAO,OAAO,MAAM,KAAK;AAC3B"}
package/math.d.ts CHANGED
@@ -1,31 +1,25 @@
1
1
  import { Maybe } from 'yummies/types';
2
2
 
3
3
  /**
4
- * ---header-docs-section---
5
- * # yummies/math
6
- *
7
- * ## Description
8
- *
9
- * Tiny math helpers: degree/radian conversion and nullable-safe percentage calculations. They wrap
10
- * common formulas so components do not repeat magic numbers or null checks when deriving layout or
11
- * charts from partially loaded data.
12
- *
13
- * ## Usage
4
+ * Converts degrees to radians.
14
5
  *
6
+ * @example
15
7
  * ```ts
16
- * import { degToRad, percentFrom } from "yummies/math";
8
+ * degToRad(180); // Math.PI
17
9
  * ```
18
10
  */
11
+ declare function degToRad(deg: number): number;
19
12
 
20
13
  /**
21
- * Converts degrees to radians.
22
- *
14
+ * Returns what percentage `value` is of `from`.
23
15
  * @example
24
16
  * ```ts
25
- * degToRad(180); // Math.PI
17
+ * percentFrom(500, 2000) // 25
18
+ * percentFrom(1000, 2000) // 50
26
19
  * ```
27
20
  */
28
- declare function degToRad(deg: number): number;
21
+ declare const percentFrom: (value: Maybe<number>, from: Maybe<number>) => number;
22
+
29
23
  /**
30
24
  * Converts radians to degrees.
31
25
  *
@@ -35,14 +29,5 @@ declare function degToRad(deg: number): number;
35
29
  * ```
36
30
  */
37
31
  declare function radToDeg(rad: number): number;
38
- /**
39
- * Returns what percentage `value` is of `from`.
40
- * @example
41
- * ```ts
42
- * percentFrom(500, 2000) // 25
43
- * percentFrom(1000, 2000) // 50
44
- * ```
45
- */
46
- declare const percentFrom: (value: Maybe<number>, from: Maybe<number>) => number;
47
32
 
48
33
  export { degToRad, percentFrom, radToDeg };
package/math.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/math.ts
1
+ //#region src/math/deg-to-rad.ts
2
2
  /**
3
3
  * Converts degrees to radians.
4
4
  *
@@ -10,17 +10,8 @@
10
10
  function degToRad(deg) {
11
11
  return deg * (Math.PI / 180);
12
12
  }
13
- /**
14
- * Converts radians to degrees.
15
- *
16
- * @example
17
- * ```ts
18
- * radToDeg(Math.PI); // 180
19
- * ```
20
- */
21
- function radToDeg(rad) {
22
- return rad * (180 / Math.PI);
23
- }
13
+ //#endregion
14
+ //#region src/math/percent-from.ts
24
15
  /**
25
16
  * Returns what percentage `value` is of `from`.
26
17
  * @example
@@ -33,6 +24,19 @@ var percentFrom = (value, from) => {
33
24
  return (value ?? 0) / (from ?? 0) * 100 || 0;
34
25
  };
35
26
  //#endregion
27
+ //#region src/math/rad-to-deg.ts
28
+ /**
29
+ * Converts radians to degrees.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * radToDeg(Math.PI); // 180
34
+ * ```
35
+ */
36
+ function radToDeg(rad) {
37
+ return rad * (180 / Math.PI);
38
+ }
39
+ //#endregion
36
40
  export { degToRad, percentFrom, radToDeg };
37
41
 
38
42
  //# sourceMappingURL=math.js.map
package/math.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"math.js","names":[],"sources":["../src/math.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/math\n *\n * ## Description\n *\n * Tiny math helpers: degree/radian conversion and nullable-safe percentage calculations. They wrap\n * common formulas so components do not repeat magic numbers or null checks when deriving layout or\n * charts from partially loaded data.\n *\n * ## Usage\n *\n * ```ts\n * import { degToRad, percentFrom } from \"yummies/math\";\n * ```\n */\n\nimport type { Maybe } from 'yummies/types';\n\n/**\n * Converts degrees to radians.\n *\n * @example\n * ```ts\n * degToRad(180); // Math.PI\n * ```\n */\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\n}\n\n/**\n * Converts radians to degrees.\n *\n * @example\n * ```ts\n * radToDeg(Math.PI); // 180\n * ```\n */\nexport function radToDeg(rad: number) {\n return rad * (180 / Math.PI);\n}\n\n/**\n * Returns what percentage `value` is of `from`.\n * @example\n * ```ts\n * percentFrom(500, 2000) // 25\n * percentFrom(1000, 2000) // 50\n * ```\n */\nexport const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {\n return ((value ?? 0) / (from ?? 0)) * 100 || 0;\n};\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,SAAS,KAAa;AACpC,QAAO,OAAO,KAAK,KAAK;;;;;;;;;;AAW1B,SAAgB,SAAS,KAAa;AACpC,QAAO,OAAO,MAAM,KAAK;;;;;;;;;;AAW3B,IAAa,eAAe,OAAsB,SAAwB;AACxE,SAAS,SAAS,MAAM,QAAQ,KAAM,OAAO"}
1
+ {"version":3,"file":"math.js","names":[],"sources":["../src/math/deg-to-rad.ts","../src/math/percent-from.ts","../src/math/rad-to-deg.ts"],"sourcesContent":["/**\n * Converts degrees to radians.\n *\n * @example\n * ```ts\n * degToRad(180); // Math.PI\n * ```\n */\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\n}\n","import type { Maybe } from 'yummies/types';\n\n/**\n * Returns what percentage `value` is of `from`.\n * @example\n * ```ts\n * percentFrom(500, 2000) // 25\n * percentFrom(1000, 2000) // 50\n * ```\n */\nexport const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {\n return ((value ?? 0) / (from ?? 0)) * 100 || 0;\n};\n","/**\n * Converts radians to degrees.\n *\n * @example\n * ```ts\n * radToDeg(Math.PI); // 180\n * ```\n */\nexport function radToDeg(rad: number) {\n return rad * (180 / Math.PI);\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,SAAS,KAAa;CACpC,OAAO,OAAO,KAAK,KAAK;AAC1B;;;;;;;;;;;ACAA,IAAa,eAAe,OAAsB,SAAwB;CACxE,QAAS,SAAS,MAAM,QAAQ,KAAM,OAAO;AAC/C;;;;;;;;;;;ACJA,SAAgB,SAAS,KAAa;CACpC,OAAO,OAAO,MAAM,KAAK;AAC3B"}