yummies 7.11.0 → 7.13.0
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.
- package/README.md +5 -87
- package/async.cjs +179 -48
- package/async.cjs.map +1 -1
- package/async.d.ts +125 -7
- package/async.js +180 -54
- package/async.js.map +1 -1
- package/chunk-CVq3Gv4J.cjs +50 -0
- package/chunk-YKewjYmz.js +37 -0
- package/common.cjs +48 -8
- package/common.cjs.map +1 -1
- package/common.d.ts +53 -2
- package/common.js +49 -11
- package/common.js.map +1 -1
- package/complex.cjs +275 -128
- package/complex.cjs.map +1 -1
- package/complex.d.ts +66 -0
- package/complex.js +275 -133
- package/complex.js.map +1 -1
- package/cookie.cjs +17 -7
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +26 -0
- package/cookie.js +18 -9
- package/cookie.js.map +1 -1
- package/css.cjs +163 -39
- package/css.cjs.map +1 -1
- package/css.d.ts +115 -6
- package/css.js +159 -41
- package/css.js.map +1 -1
- package/data.cjs +90 -55
- package/data.cjs.map +1 -1
- package/data.d.ts +50 -0
- package/data.js +91 -61
- package/data.js.map +1 -1
- package/date-time.cjs +594 -412
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +105 -0
- package/date-time.js +591 -421
- package/date-time.js.map +1 -1
- package/device.cjs +65 -23
- package/device.cjs.map +1 -1
- package/device.d.ts +49 -0
- package/device.js +66 -31
- package/device.js.map +1 -1
- package/encodings.cjs +275 -266
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +25 -0
- package/encodings.js +276 -268
- package/encodings.js.map +1 -1
- package/errors.cjs +36 -18
- package/errors.cjs.map +1 -1
- package/errors.d.ts +17 -0
- package/errors.js +35 -19
- package/errors.js.map +1 -1
- package/file.cjs +58 -24
- package/file.cjs.map +1 -1
- package/file.d.ts +32 -0
- package/file.js +59 -27
- package/file.js.map +1 -1
- package/format.cjs +125 -83
- package/format.cjs.map +1 -1
- package/format.d.ts +18 -0
- package/format.js +118 -82
- package/format.js.map +1 -1
- package/html.cjs +242 -137
- package/html.cjs.map +1 -1
- package/html.d.ts +81 -0
- package/html.js +239 -150
- package/html.js.map +1 -1
- package/id.cjs +90 -17
- package/id.cjs.map +1 -1
- package/id.d.ts +16 -0
- package/id.js +89 -24
- package/id.js.map +1 -1
- package/imports.cjs +57 -29
- package/imports.cjs.map +1 -1
- package/imports.d.ts +24 -0
- package/imports.js +56 -31
- package/imports.js.map +1 -1
- package/math.cjs +32 -6
- package/math.cjs.map +1 -1
- package/math.d.ts +33 -0
- package/math.js +33 -10
- package/math.js.map +1 -1
- package/media.cjs +291 -84
- package/media.cjs.map +1 -1
- package/media.d.ts +204 -2
- package/media.js +290 -93
- package/media.js.map +1 -1
- package/mobx.cjs +449 -193
- package/mobx.cjs.map +1 -1
- package/mobx.d.ts +108 -0
- package/mobx.js +447 -200
- package/mobx.js.map +1 -1
- package/ms.cjs +37 -10
- package/ms.cjs.map +1 -1
- package/ms.d.ts +16 -0
- package/ms.js +38 -13
- package/ms.js.map +1 -1
- package/number.cjs +29 -7
- package/number.cjs.map +1 -1
- package/number.d.ts +16 -0
- package/number.js +30 -9
- package/number.js.map +1 -1
- package/package.json +11 -3
- package/parser.cjs +117 -64
- package/parser.cjs.map +1 -1
- package/parser.d.ts +17 -0
- package/parser.js +111 -64
- package/parser.js.map +1 -1
- package/price.cjs +24 -18
- package/price.cjs.map +1 -1
- package/price.d.ts +24 -0
- package/price.js +25 -20
- package/price.js.map +1 -1
- package/random.cjs +95 -13
- package/random.cjs.map +1 -1
- package/random.d.ts +80 -0
- package/random.js +96 -22
- package/random.js.map +1 -1
- package/react.cjs +673 -214
- package/react.cjs.map +1 -1
- package/react.d.ts +21 -0
- package/react.js +674 -239
- package/react.js.map +1 -1
- package/sound.cjs +30 -9
- package/sound.cjs.map +1 -1
- package/sound.d.ts +16 -0
- package/sound.js +31 -11
- package/sound.js.map +1 -1
- package/storage.cjs +49 -50
- package/storage.cjs.map +1 -1
- package/storage.d.ts +24 -0
- package/storage.js +50 -53
- package/storage.js.map +1 -1
- package/text.cjs +67 -34
- package/text.cjs.map +1 -1
- package/text.d.ts +16 -0
- package/text.js +68 -37
- package/text.js.map +1 -1
- package/type-guard.cjs +292 -72
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +18 -0
- package/type-guard.js +288 -73
- package/type-guard.js.map +1 -1
- package/types.cjs +0 -2
- package/types.d.ts +41 -0
- package/types.global.cjs +0 -2
- package/types.global.d.ts +41 -0
- package/types.global.js +0 -2
- package/types.js +0 -2
- package/vibrate.cjs +47 -6
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +39 -1
- package/vibrate.js +48 -8
- package/vibrate.js.map +1 -1
- package/types.cjs.map +0 -1
- package/types.global.cjs.map +0 -1
- package/types.global.js.map +0 -1
- package/types.js.map +0 -1
package/id.js
CHANGED
|
@@ -1,26 +1,91 @@
|
|
|
1
1
|
import { customAlphabet } from "nanoid";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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);
|
|
41
|
+
/**
|
|
42
|
+
* Creates a function that generates unique strings based on call order.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* generateLinearNumericId = createLinearNumericIdGenerator(6);
|
|
47
|
+
* generateLinearNumericId() // '000000'
|
|
48
|
+
* generateLinearNumericId() // '000001'
|
|
49
|
+
* ...
|
|
50
|
+
* generateLinearNumericId() // '999999'
|
|
51
|
+
* generateLinearNumericId() // '1000000'
|
|
52
|
+
* ...
|
|
53
|
+
* generateLinearNumericId() // '9999999'
|
|
54
|
+
* generateLinearNumericId() // '10000000'
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @param size Minimum string length.
|
|
58
|
+
* @returns {()=>string}
|
|
59
|
+
*/
|
|
60
|
+
var createLinearNumericIdGenerator = (size = 9) => {
|
|
61
|
+
let lastCount = 0;
|
|
62
|
+
return () => {
|
|
63
|
+
return (lastCount++).toString().padStart(size, "0");
|
|
64
|
+
};
|
|
14
65
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* generateLinearNumericId() // '000000000'
|
|
71
|
+
* generateLinearNumericId() // '000000001'
|
|
72
|
+
* ...
|
|
73
|
+
* generateLinearNumericId() // '999999999'
|
|
74
|
+
* generateLinearNumericId() // '1000000000'
|
|
75
|
+
* ...
|
|
76
|
+
* generateLinearNumericId() // '9999999999'
|
|
77
|
+
* generateLinearNumericId() // '10000000000'
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
var generateLinearNumericId = createLinearNumericIdGenerator();
|
|
82
|
+
/**
|
|
83
|
+
* Is not recommended to use.
|
|
84
|
+
*
|
|
85
|
+
* Generates execution stack based pseudo-id (just sliced string from error stack)
|
|
86
|
+
*/
|
|
87
|
+
var generateStackBasedId = () => (/* @__PURE__ */ new Error()).stack.split("\n").slice(1, 4).join("");
|
|
88
|
+
//#endregion
|
|
89
|
+
export { createLinearNumericIdGenerator, generateId, generateLinearNumericId, generateNumericId, generateNumericShortId, generateShortId, generateStackBasedId };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=id.js.map
|
package/id.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id.js","sources":["../src/id.ts"],"sourcesContent":["import { 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"],"
|
|
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"}
|
package/imports.cjs
CHANGED
|
@@ -1,34 +1,62 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
require("./chunk-CVq3Gv4J.cjs");
|
|
3
|
+
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
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Lazily loads a module with retry support.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* fetchLazyModule(() => import('./test.ts'), 3) // starts loading test.ts
|
|
27
|
+
* // If loading test.ts fails, fetchLazyModule retries by calling fetchModule() again
|
|
28
|
+
* // It retries as many times as specified by attempts (3 by default)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
var fetchLazyModule = async (fetchModule, attempts = 3, delay = 1e3) => {
|
|
32
|
+
const attemptsArray = Array.from({ length: attempts }).fill(fetchModule);
|
|
33
|
+
let lastError = null;
|
|
34
|
+
for await (const attempt of attemptsArray) try {
|
|
35
|
+
if (lastError !== null) await (0, yummies_async.sleep)(delay);
|
|
36
|
+
return await attempt();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
lastError = error;
|
|
39
|
+
}
|
|
40
|
+
throw lastError;
|
|
20
41
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const component = await unpackAsyncModule(import('./Component.ts'));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
var unpackAsyncModule = async (maybeModule) => {
|
|
51
|
+
if (maybeModule instanceof Promise) {
|
|
52
|
+
const data = await maybeModule;
|
|
53
|
+
if (data.default) return data.default;
|
|
54
|
+
else return data;
|
|
55
|
+
}
|
|
56
|
+
return maybeModule;
|
|
31
57
|
};
|
|
58
|
+
//#endregion
|
|
32
59
|
exports.fetchLazyModule = fetchLazyModule;
|
|
33
60
|
exports.unpackAsyncModule = unpackAsyncModule;
|
|
34
|
-
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=imports.cjs.map
|
package/imports.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imports.cjs","sources":["../src/imports.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\nexport type PackedAsyncModule<T> = Promise<T | { default: T }>;\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"],"
|
|
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"}
|
package/imports.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
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
|
+
*/
|
|
1
17
|
/**
|
|
2
18
|
* Lazily loads a module with retry support.
|
|
3
19
|
*
|
|
@@ -12,6 +28,14 @@ declare const fetchLazyModule: <T>(fetchModule: () => Promise<T>, attempts?: num
|
|
|
12
28
|
type PackedAsyncModule<T> = Promise<T | {
|
|
13
29
|
default: T;
|
|
14
30
|
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const component = await unpackAsyncModule(import('./Component.ts'));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
15
39
|
declare const unpackAsyncModule: <T>(maybeModule: T | PackedAsyncModule<T>) => Promise<T>;
|
|
16
40
|
|
|
17
41
|
export { fetchLazyModule, unpackAsyncModule };
|
package/imports.js
CHANGED
|
@@ -1,34 +1,59 @@
|
|
|
1
1
|
import { sleep } from "yummies/async";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Lazily loads a module with retry support.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* fetchLazyModule(() => import('./test.ts'), 3) // starts loading test.ts
|
|
25
|
+
* // If loading test.ts fails, fetchLazyModule retries by calling fetchModule() again
|
|
26
|
+
* // It retries as many times as specified by attempts (3 by default)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
var fetchLazyModule = async (fetchModule, attempts = 3, delay = 1e3) => {
|
|
30
|
+
const attemptsArray = Array.from({ length: attempts }).fill(fetchModule);
|
|
31
|
+
let lastError = null;
|
|
32
|
+
for await (const attempt of attemptsArray) try {
|
|
33
|
+
if (lastError !== null) await sleep(delay);
|
|
34
|
+
return await attempt();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
lastError = error;
|
|
37
|
+
}
|
|
38
|
+
throw lastError;
|
|
18
39
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Resolves either a direct value or an asynchronously imported module and unwraps its `default` export.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const component = await unpackAsyncModule(import('./Component.ts'));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
var unpackAsyncModule = async (maybeModule) => {
|
|
49
|
+
if (maybeModule instanceof Promise) {
|
|
50
|
+
const data = await maybeModule;
|
|
51
|
+
if (data.default) return data.default;
|
|
52
|
+
else return data;
|
|
53
|
+
}
|
|
54
|
+
return maybeModule;
|
|
29
55
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=imports.js.map
|
|
56
|
+
//#endregion
|
|
57
|
+
export { fetchLazyModule, unpackAsyncModule };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=imports.js.map
|
package/imports.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imports.js","sources":["../src/imports.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\nexport type PackedAsyncModule<T> = Promise<T | { default: T }>;\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"],"
|
|
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"}
|
package/math.cjs
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/math.ts
|
|
3
|
+
/**
|
|
4
|
+
* Converts degrees to radians.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* degToRad(180); // Math.PI
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
3
11
|
function degToRad(deg) {
|
|
4
|
-
|
|
12
|
+
return deg * (Math.PI / 180);
|
|
5
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Converts radians to degrees.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* radToDeg(Math.PI); // 180
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
6
22
|
function radToDeg(rad) {
|
|
7
|
-
|
|
23
|
+
return rad * (180 / Math.PI);
|
|
8
24
|
}
|
|
9
|
-
|
|
10
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Returns what percentage `value` is of `from`.
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* percentFrom(500, 2000) // 25
|
|
30
|
+
* percentFrom(1000, 2000) // 50
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
var percentFrom = (value, from) => {
|
|
34
|
+
return (value ?? 0) / (from ?? 0) * 100 || 0;
|
|
11
35
|
};
|
|
36
|
+
//#endregion
|
|
12
37
|
exports.degToRad = degToRad;
|
|
13
38
|
exports.percentFrom = percentFrom;
|
|
14
39
|
exports.radToDeg = radToDeg;
|
|
15
|
-
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=math.cjs.map
|
package/math.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.cjs","sources":["../src/math.ts"],"sourcesContent":["import type { Maybe } from 'yummies/types';\n\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\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"],"
|
|
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"}
|
package/math.d.ts
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
import { Maybe } from 'yummies/types';
|
|
2
2
|
|
|
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
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { degToRad, percentFrom } from "yummies/math";
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Converts degrees to radians.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* degToRad(180); // Math.PI
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
3
28
|
declare function degToRad(deg: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Converts radians to degrees.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* radToDeg(Math.PI); // 180
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
4
37
|
declare function radToDeg(rad: number): number;
|
|
5
38
|
/**
|
|
6
39
|
* Returns what percentage `value` is of `from`.
|
package/math.js
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
|
+
//#region src/math.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts degrees to radians.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* degToRad(180); // Math.PI
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
1
10
|
function degToRad(deg) {
|
|
2
|
-
|
|
11
|
+
return deg * (Math.PI / 180);
|
|
3
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Converts radians to degrees.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* radToDeg(Math.PI); // 180
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
function radToDeg(rad) {
|
|
5
|
-
|
|
22
|
+
return rad * (180 / Math.PI);
|
|
6
23
|
}
|
|
7
|
-
|
|
8
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Returns what percentage `value` is of `from`.
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* percentFrom(500, 2000) // 25
|
|
29
|
+
* percentFrom(1000, 2000) // 50
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
var percentFrom = (value, from) => {
|
|
33
|
+
return (value ?? 0) / (from ?? 0) * 100 || 0;
|
|
9
34
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=math.js.map
|
|
35
|
+
//#endregion
|
|
36
|
+
export { degToRad, percentFrom, radToDeg };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=math.js.map
|
package/math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.js","sources":["../src/math.ts"],"sourcesContent":["import type { Maybe } from 'yummies/types';\n\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\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"],"
|
|
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"}
|