yummies 7.19.4 → 7.20.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/assert.cjs +1 -1
- package/assert.cjs.map +1 -1
- package/assert.js +1 -1
- package/assert.js.map +1 -1
- package/async.cjs +147 -137
- package/async.cjs.map +1 -1
- package/async.d.ts +98 -131
- package/async.js +147 -137
- package/async.js.map +1 -1
- package/common.cjs +3 -1
- package/common.cjs.map +1 -1
- package/common.d.ts +18 -24
- package/common.js +3 -1
- package/common.js.map +1 -1
- package/complex.cjs +1 -0
- package/complex.cjs.map +1 -1
- package/complex.js +1 -0
- package/complex.js.map +1 -1
- package/cookie.cjs +1 -1
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +0 -18
- package/cookie.js +1 -1
- package/cookie.js.map +1 -1
- package/css-cx.cjs +78 -0
- package/css-cx.cjs.map +1 -0
- package/css-cx.d.ts +69 -0
- package/css-cx.js +74 -0
- package/css-cx.js.map +1 -0
- package/css.cjs +32 -111
- package/css.cjs.map +1 -1
- package/css.d.ts +32 -42
- package/css.js +30 -107
- package/css.js.map +1 -1
- package/data.cjs +60 -50
- package/data.cjs.map +1 -1
- package/data.d.ts +21 -34
- package/data.js +60 -50
- package/data.js.map +1 -1
- package/date-time.cjs +104 -98
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +51 -57
- package/date-time.js +104 -97
- package/date-time.js.map +1 -1
- package/device.cjs +14 -19
- package/device.cjs.map +1 -1
- package/device.d.ts +15 -26
- package/device.js +14 -19
- package/device.js.map +1 -1
- package/encodings.cjs +1 -1
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +0 -17
- package/encodings.js +1 -1
- package/encodings.js.map +1 -1
- package/errors.cjs +1 -18
- package/errors.cjs.map +1 -1
- package/errors.d.ts +0 -17
- package/errors.js +1 -17
- package/errors.js.map +1 -1
- package/file.cjs +3 -17
- package/file.cjs.map +1 -1
- package/file.d.ts +1 -16
- package/file.js +3 -17
- package/file.js.map +1 -1
- package/format.cjs +1 -1
- package/format.cjs.map +1 -1
- package/format.js +1 -1
- package/format.js.map +1 -1
- package/html.cjs +112 -175
- package/html.cjs.map +1 -1
- package/html.d.ts +58 -57
- package/html.js +111 -172
- package/html.js.map +1 -1
- package/id-nanoid.cjs +36 -0
- package/id-nanoid.cjs.map +1 -0
- package/id-nanoid.d.ts +26 -0
- package/id-nanoid.js +32 -0
- package/id-nanoid.js.map +1 -0
- package/id.cjs +10 -45
- package/id.cjs.map +1 -1
- package/id.d.ts +27 -36
- package/id.js +6 -40
- package/id.js.map +1 -1
- package/imports.cjs +3 -18
- package/imports.cjs.map +1 -1
- package/imports.d.ts +1 -16
- package/imports.js +3 -17
- package/imports.js.map +1 -1
- package/math.cjs +16 -12
- package/math.cjs.map +1 -1
- package/math.d.ts +9 -24
- package/math.js +16 -12
- package/math.js.map +1 -1
- package/media.cjs +88 -89
- package/media.cjs.map +1 -1
- package/media.d.ts +72 -80
- package/media.js +88 -88
- package/media.js.map +1 -1
- package/mobx.cjs +0 -1
- package/mobx.cjs.map +1 -1
- package/mobx.js.map +1 -1
- package/ms.cjs +3 -17
- package/ms.cjs.map +1 -1
- package/ms.d.ts +1 -16
- package/ms.js +3 -17
- package/ms.js.map +1 -1
- package/number.cjs +1 -17
- package/number.cjs.map +1 -1
- package/number.d.ts +0 -16
- package/number.js +1 -17
- package/number.js.map +1 -1
- package/package.json +6 -6
- package/parser.cjs +1 -1
- package/parser.cjs.map +1 -1
- package/parser.js +1 -1
- package/parser.js.map +1 -1
- package/price.cjs +1 -1
- package/price.cjs.map +1 -1
- package/price.d.ts +0 -16
- package/price.js +1 -1
- package/price.js.map +1 -1
- package/random.cjs +37 -39
- package/random.cjs.map +1 -1
- package/random.d.ts +31 -40
- package/random.js +37 -39
- package/random.js.map +1 -1
- package/react.cjs +0 -1
- package/react.cjs.map +1 -1
- package/react.js.map +1 -1
- package/sanitize-html.cjs +82 -0
- package/sanitize-html.cjs.map +1 -0
- package/sanitize-html.d.ts +28 -0
- package/sanitize-html.js +79 -0
- package/sanitize-html.js.map +1 -0
- package/sound.cjs +1 -17
- package/sound.cjs.map +1 -1
- package/sound.d.ts +0 -16
- package/sound.js +1 -17
- package/sound.js.map +1 -1
- package/storage.cjs +7 -5
- package/storage.cjs.map +1 -1
- package/storage.d.ts +3 -17
- package/storage.js +7 -5
- package/storage.js.map +1 -1
- package/text.cjs +3 -17
- package/text.cjs.map +1 -1
- package/text.d.ts +1 -16
- package/text.js +3 -17
- package/text.js.map +1 -1
- package/type-guard.cjs +38 -1
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +38 -0
- package/type-guard.js +38 -1
- package/type-guard.js.map +1 -1
- package/types.d.ts +10 -1
- package/types.global.d.ts +9 -0
- package/vibrate.cjs +1 -17
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +0 -16
- package/vibrate.js +1 -17
- package/vibrate.js.map +1 -1
- /package/{chunk-pbuEa-1d.js → chunk-D7D4PA-g.js} +0 -0
- /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 {
|
|
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"
|
|
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":["
|
|
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":["
|
|
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
|
-
|
|
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"
|
|
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
|
-
*
|
|
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
|
-
*
|
|
8
|
+
* degToRad(180); // Math.PI
|
|
17
9
|
* ```
|
|
18
10
|
*/
|
|
11
|
+
declare function degToRad(deg: number): number;
|
|
19
12
|
|
|
20
13
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
14
|
+
* Returns what percentage `value` is of `from`.
|
|
23
15
|
* @example
|
|
24
16
|
* ```ts
|
|
25
|
-
*
|
|
17
|
+
* percentFrom(500, 2000) // 25
|
|
18
|
+
* percentFrom(1000, 2000) // 50
|
|
26
19
|
* ```
|
|
27
20
|
*/
|
|
28
|
-
declare
|
|
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
|
-
|
|
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"
|
|
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"}
|