@kikiutils/shared 9.0.0 → 9.2.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 +23 -3
- package/dist/clipboard.cjs +87 -0
- package/dist/clipboard.cjs.map +1 -0
- package/dist/clipboard.d.ts +60 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.mjs +84 -0
- package/dist/clipboard.mjs.map +1 -0
- package/dist/consola.cjs +1 -1
- package/dist/consola.cjs.map +1 -1
- package/dist/consola.d.ts +1 -1
- package/dist/consola.mjs +1 -1
- package/dist/consola.mjs.map +1 -1
- package/dist/crypto-hash.cjs +1 -0
- package/dist/crypto-hash.cjs.map +1 -1
- package/dist/crypto-hash.d.ts +1 -0
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.mjs +1 -0
- package/dist/crypto-hash.mjs.map +1 -1
- package/dist/datetime.cjs +3 -0
- package/dist/datetime.cjs.map +1 -1
- package/dist/datetime.d.ts +3 -0
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.mjs +3 -0
- package/dist/datetime.mjs.map +1 -1
- package/dist/enum.cjs +2 -0
- package/dist/enum.cjs.map +1 -1
- package/dist/enum.d.ts +2 -0
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.mjs +2 -0
- package/dist/enum.mjs.map +1 -1
- package/dist/env.cjs +2 -0
- package/dist/env.cjs.map +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.mjs +2 -0
- package/dist/env.mjs.map +1 -1
- package/dist/general.cjs.map +1 -1
- package/dist/general.d.ts +1 -0
- package/dist/general.d.ts.map +1 -1
- package/dist/general.mjs.map +1 -1
- package/dist/math.cjs +1 -0
- package/dist/math.cjs.map +1 -1
- package/dist/math.d.ts +3 -0
- package/dist/math.d.ts.map +1 -1
- package/dist/math.mjs +1 -0
- package/dist/math.mjs.map +1 -1
- package/dist/number.cjs +1 -0
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.ts +1 -0
- package/dist/number.d.ts.map +1 -1
- package/dist/number.mjs +1 -0
- package/dist/number.mjs.map +1 -1
- package/dist/pino.cjs +1 -1
- package/dist/pino.cjs.map +1 -1
- package/dist/pino.d.ts +1 -1
- package/dist/pino.mjs +1 -1
- package/dist/pino.mjs.map +1 -1
- package/dist/random.cjs +8 -7
- package/dist/random.cjs.map +1 -1
- package/dist/random.d.ts +8 -7
- package/dist/random.d.ts.map +1 -1
- package/dist/random.mjs +8 -7
- package/dist/random.mjs.map +1 -1
- package/dist/string.cjs +1 -0
- package/dist/string.cjs.map +1 -1
- package/dist/string.d.ts +1 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.mjs +1 -0
- package/dist/string.mjs.map +1 -1
- package/dist/url.cjs +21 -0
- package/dist/url.cjs.map +1 -0
- package/dist/url.d.ts +12 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.mjs +19 -0
- package/dist/url.mjs.map +1 -0
- package/dist/vue.cjs +64 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.ts +31 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.mjs +59 -0
- package/dist/vue.mjs.map +1 -0
- package/dist/web.cjs +18 -0
- package/dist/web.cjs.map +1 -0
- package/dist/web.d.ts +9 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.mjs +16 -0
- package/dist/web.mjs.map +1 -0
- package/package.json +5 -2
- package/src/clipboard.ts +85 -0
- package/src/consola.ts +1 -1
- package/src/crypto-hash.ts +1 -0
- package/src/datetime.ts +3 -0
- package/src/enum.ts +2 -0
- package/src/env.ts +2 -0
- package/src/general.ts +1 -0
- package/src/math.ts +3 -0
- package/src/number.ts +1 -0
- package/src/pino.ts +1 -1
- package/src/random.ts +8 -7
- package/src/string.ts +1 -0
- package/src/url.ts +16 -0
- package/src/vue.ts +62 -0
- package/src/web.ts +13 -0
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ A lightweight modular utility library for JavaScript and TypeScript, offering se
|
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
+
- 📋 Clipboard utilities for copying text and blobs to the clipboard (Browser only)
|
|
14
15
|
- 📜 Simple and flexible logging with Consola and Pino
|
|
15
16
|
- 🔒 Secure hash utilities: MD5, SHA3-224/256/384/512
|
|
16
17
|
- 📅 Datetime utilities for formatting, ranges, and offsets
|
|
@@ -20,7 +21,6 @@ A lightweight modular utility library for JavaScript and TypeScript, offering se
|
|
|
20
21
|
- 💎 Number formatting (e.g. compact, currency, padding)
|
|
21
22
|
- 🔤 String tools such as random string generation and casing helpers
|
|
22
23
|
- 🌐 URL utilities for parsing and building query strings
|
|
23
|
-
- 🖥️ Web utilities using DOM APIs (e.g. `scrollToTop`) (Browser only)
|
|
24
24
|
- 🧩 Vue 3 utilities
|
|
25
25
|
- ⚙️ General-purpose utilities like value extractors and type guards
|
|
26
26
|
- 📦 Modular by design — import only what you need via `@kikiutils/shared/<module>`
|
|
@@ -68,7 +68,12 @@ Each module file includes function-level comments and usage examples.
|
|
|
68
68
|
|
|
69
69
|
### [consola](./src/consola.ts)
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
Console logger integration.
|
|
72
|
+
|
|
73
|
+
### [clipboard](./src/clipboard.ts)
|
|
74
|
+
|
|
75
|
+
- `copyBlobToClipboard`
|
|
76
|
+
- `copyTextToClipboard`
|
|
72
77
|
|
|
73
78
|
### [crypto-hash](./src/crypto-hash.ts)
|
|
74
79
|
|
|
@@ -114,7 +119,7 @@ Each module file includes function-level comments and usage examples.
|
|
|
114
119
|
|
|
115
120
|
### [pino](./src/pino.ts)
|
|
116
121
|
|
|
117
|
-
|
|
122
|
+
Pino logger integration.
|
|
118
123
|
|
|
119
124
|
### [random](./src/random.ts)
|
|
120
125
|
|
|
@@ -124,6 +129,21 @@ Each module file includes function-level comments and usage examples.
|
|
|
124
129
|
|
|
125
130
|
- `randomString`
|
|
126
131
|
|
|
132
|
+
### [url](./src/url.ts)
|
|
133
|
+
|
|
134
|
+
- `appendRedirectParamToUrl`
|
|
135
|
+
|
|
136
|
+
### [vue](./src/vue.ts)
|
|
137
|
+
|
|
138
|
+
- `appendRedirectParamFromCurrentRouteToUrl`
|
|
139
|
+
- `clearIntervalRef`
|
|
140
|
+
- `clearTimeoutRef`
|
|
141
|
+
- `usePreserveScroll`
|
|
142
|
+
|
|
143
|
+
### [web](./src/web.ts)
|
|
144
|
+
|
|
145
|
+
- `appendRedirectParamFromCurrentLocationToUrl`
|
|
146
|
+
|
|
127
147
|
## License
|
|
128
148
|
|
|
129
149
|
[MIT License](./LICENSE)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ Usage Notes:
|
|
7
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
8
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
9
|
+
* - Not supported in Safari and some older browsers.
|
|
10
|
+
*
|
|
11
|
+
* @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content).
|
|
12
|
+
* @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
15
|
+
* - `{ ok: true }` if the copy succeeded
|
|
16
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const blob = new Blob(['Hello world'], { type: 'text/plain' });
|
|
21
|
+
* const result = await copyBlobToClipboard(blob);
|
|
22
|
+
* if (result.ok) {
|
|
23
|
+
* console.log('Copied blob!');
|
|
24
|
+
* } else {
|
|
25
|
+
* console.error('Copy failed:', result.error);
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
async function copyBlobToClipboard(blob, options) {
|
|
30
|
+
if (!navigator.clipboard?.write) {
|
|
31
|
+
return {
|
|
32
|
+
error: new Error('Clipboard.write is not supported in this browser.'),
|
|
33
|
+
ok: false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const item = new ClipboardItem({ [blob.type]: blob }, options);
|
|
38
|
+
await navigator.clipboard.write([item]);
|
|
39
|
+
return { ok: true };
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
error,
|
|
44
|
+
ok: false,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Attempts to copy the given text to the user's clipboard using the modern Clipboard API.
|
|
50
|
+
*
|
|
51
|
+
* ⚠️ Usage Notes:
|
|
52
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
53
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
54
|
+
* - Not supported in some older browsers (especially legacy Safari).
|
|
55
|
+
*
|
|
56
|
+
* @param {string} text - The string to be copied to the clipboard.
|
|
57
|
+
*
|
|
58
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
59
|
+
* - `{ ok: true }` if the copy succeeded
|
|
60
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const result = await copyTextToClipboard('Hello!');
|
|
65
|
+
* if (result.ok) {
|
|
66
|
+
* console.log('Copied!');
|
|
67
|
+
* } else {
|
|
68
|
+
* console.error('Copy failed:', result.error);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
async function copyTextToClipboard(text) {
|
|
73
|
+
try {
|
|
74
|
+
await navigator.clipboard.writeText(text);
|
|
75
|
+
return { ok: true };
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
return {
|
|
79
|
+
error,
|
|
80
|
+
ok: false,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.copyBlobToClipboard = copyBlobToClipboard;
|
|
86
|
+
exports.copyTextToClipboard = copyTextToClipboard;
|
|
87
|
+
//# sourceMappingURL=clipboard.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.cjs","sources":["../src/clipboard.ts"],"sourcesContent":["type CopyResult =\n | { error: unknown; ok: false }\n | { ok: true };\n\n/**\n * Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.\n *\n * ⚠️ Usage Notes:\n * - Must be called in a **secure context** (HTTPS or localhost).\n * - Must be called **in response to a user interaction** (e.g. click, input).\n * - Not supported in Safari and some older browsers.\n *\n * @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content).\n * @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor.\n *\n * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:\n * - `{ ok: true }` if the copy succeeded\n * - `{ ok: false, error }` if the copy failed, with the error included\n *\n * @example\n * ```typescript\n * const blob = new Blob(['Hello world'], { type: 'text/plain' });\n * const result = await copyBlobToClipboard(blob);\n * if (result.ok) {\n * console.log('Copied blob!');\n * } else {\n * console.error('Copy failed:', result.error);\n * }\n * ```\n */\nexport async function copyBlobToClipboard(blob: Blob, options?: ClipboardItemOptions): Promise<CopyResult> {\n if (!navigator.clipboard?.write) {\n return {\n error: new Error('Clipboard.write is not supported in this browser.'),\n ok: false,\n };\n }\n\n try {\n const item = new ClipboardItem({ [blob.type]: blob }, options);\n await navigator.clipboard.write([item]);\n return { ok: true };\n } catch (error) {\n return {\n error,\n ok: false,\n };\n }\n}\n\n/**\n * Attempts to copy the given text to the user's clipboard using the modern Clipboard API.\n *\n * ⚠️ Usage Notes:\n * - Must be called in a **secure context** (HTTPS or localhost).\n * - Must be called **in response to a user interaction** (e.g. click, input).\n * - Not supported in some older browsers (especially legacy Safari).\n *\n * @param {string} text - The string to be copied to the clipboard.\n *\n * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:\n * - `{ ok: true }` if the copy succeeded\n * - `{ ok: false, error }` if the copy failed, with the error included\n *\n * @example\n * ```typescript\n * const result = await copyTextToClipboard('Hello!');\n * if (result.ok) {\n * console.log('Copied!');\n * } else {\n * console.error('Copy failed:', result.error);\n * }\n * ```\n */\nexport async function copyTextToClipboard(text: string): Promise<CopyResult> {\n try {\n await navigator.clipboard.writeText(text);\n return { ok: true };\n } catch (error) {\n return {\n error,\n ok: false,\n };\n }\n}\n"],"names":[],"mappings":";;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACI,eAAe,mBAAmB,CAAC,IAAU,EAAE,OAA8B,EAAA;AAChF,IAAA,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE;QAC7B,OAAO;AACH,YAAA,KAAK,EAAE,IAAI,KAAK,CAAC,mDAAmD,CAAC;AACrE,YAAA,EAAE,EAAE,KAAK;SACZ;;AAGL,IAAA,IAAI;AACA,QAAA,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,EAAE,OAAO,CAAC;QAC9D,MAAM,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;AACvC,QAAA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE;;IACrB,OAAO,KAAK,EAAE;QACZ,OAAO;YACH,KAAK;AACL,YAAA,EAAE,EAAE,KAAK;SACZ;;AAET;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACI,eAAe,mBAAmB,CAAC,IAAY,EAAA;AAClD,IAAA,IAAI;QACA,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC;AACzC,QAAA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE;;IACrB,OAAO,KAAK,EAAE;QACZ,OAAO;YACH,KAAK;AACL,YAAA,EAAE,EAAE,KAAK;SACZ;;AAET;;;;;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
type CopyResult = {
|
|
2
|
+
error: unknown;
|
|
3
|
+
ok: false;
|
|
4
|
+
} | {
|
|
5
|
+
ok: true;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.
|
|
9
|
+
*
|
|
10
|
+
* ⚠️ Usage Notes:
|
|
11
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
12
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
13
|
+
* - Not supported in Safari and some older browsers.
|
|
14
|
+
*
|
|
15
|
+
* @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content).
|
|
16
|
+
* @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor.
|
|
17
|
+
*
|
|
18
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
19
|
+
* - `{ ok: true }` if the copy succeeded
|
|
20
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const blob = new Blob(['Hello world'], { type: 'text/plain' });
|
|
25
|
+
* const result = await copyBlobToClipboard(blob);
|
|
26
|
+
* if (result.ok) {
|
|
27
|
+
* console.log('Copied blob!');
|
|
28
|
+
* } else {
|
|
29
|
+
* console.error('Copy failed:', result.error);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function copyBlobToClipboard(blob: Blob, options?: ClipboardItemOptions): Promise<CopyResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Attempts to copy the given text to the user's clipboard using the modern Clipboard API.
|
|
36
|
+
*
|
|
37
|
+
* ⚠️ Usage Notes:
|
|
38
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
39
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
40
|
+
* - Not supported in some older browsers (especially legacy Safari).
|
|
41
|
+
*
|
|
42
|
+
* @param {string} text - The string to be copied to the clipboard.
|
|
43
|
+
*
|
|
44
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
45
|
+
* - `{ ok: true }` if the copy succeeded
|
|
46
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const result = await copyTextToClipboard('Hello!');
|
|
51
|
+
* if (result.ok) {
|
|
52
|
+
* console.log('Copied!');
|
|
53
|
+
* } else {
|
|
54
|
+
* console.error('Copy failed:', result.error);
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function copyTextToClipboard(text: string): Promise<CopyResult>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=clipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GACX;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,KAAK,CAAA;CAAE,GAC7B;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAkBzG;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAU3E"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.
|
|
3
|
+
*
|
|
4
|
+
* ⚠️ Usage Notes:
|
|
5
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
6
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
7
|
+
* - Not supported in Safari and some older browsers.
|
|
8
|
+
*
|
|
9
|
+
* @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content).
|
|
10
|
+
* @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
13
|
+
* - `{ ok: true }` if the copy succeeded
|
|
14
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const blob = new Blob(['Hello world'], { type: 'text/plain' });
|
|
19
|
+
* const result = await copyBlobToClipboard(blob);
|
|
20
|
+
* if (result.ok) {
|
|
21
|
+
* console.log('Copied blob!');
|
|
22
|
+
* } else {
|
|
23
|
+
* console.error('Copy failed:', result.error);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
async function copyBlobToClipboard(blob, options) {
|
|
28
|
+
if (!navigator.clipboard?.write) {
|
|
29
|
+
return {
|
|
30
|
+
error: new Error('Clipboard.write is not supported in this browser.'),
|
|
31
|
+
ok: false,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const item = new ClipboardItem({ [blob.type]: blob }, options);
|
|
36
|
+
await navigator.clipboard.write([item]);
|
|
37
|
+
return { ok: true };
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
return {
|
|
41
|
+
error,
|
|
42
|
+
ok: false,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Attempts to copy the given text to the user's clipboard using the modern Clipboard API.
|
|
48
|
+
*
|
|
49
|
+
* ⚠️ Usage Notes:
|
|
50
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
51
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
52
|
+
* - Not supported in some older browsers (especially legacy Safari).
|
|
53
|
+
*
|
|
54
|
+
* @param {string} text - The string to be copied to the clipboard.
|
|
55
|
+
*
|
|
56
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
57
|
+
* - `{ ok: true }` if the copy succeeded
|
|
58
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const result = await copyTextToClipboard('Hello!');
|
|
63
|
+
* if (result.ok) {
|
|
64
|
+
* console.log('Copied!');
|
|
65
|
+
* } else {
|
|
66
|
+
* console.error('Copy failed:', result.error);
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
async function copyTextToClipboard(text) {
|
|
71
|
+
try {
|
|
72
|
+
await navigator.clipboard.writeText(text);
|
|
73
|
+
return { ok: true };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return {
|
|
77
|
+
error,
|
|
78
|
+
ok: false,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { copyBlobToClipboard, copyTextToClipboard };
|
|
84
|
+
//# sourceMappingURL=clipboard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.mjs","sources":["../src/clipboard.ts"],"sourcesContent":["type CopyResult =\n | { error: unknown; ok: false }\n | { ok: true };\n\n/**\n * Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.\n *\n * ⚠️ Usage Notes:\n * - Must be called in a **secure context** (HTTPS or localhost).\n * - Must be called **in response to a user interaction** (e.g. click, input).\n * - Not supported in Safari and some older browsers.\n *\n * @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content).\n * @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor.\n *\n * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:\n * - `{ ok: true }` if the copy succeeded\n * - `{ ok: false, error }` if the copy failed, with the error included\n *\n * @example\n * ```typescript\n * const blob = new Blob(['Hello world'], { type: 'text/plain' });\n * const result = await copyBlobToClipboard(blob);\n * if (result.ok) {\n * console.log('Copied blob!');\n * } else {\n * console.error('Copy failed:', result.error);\n * }\n * ```\n */\nexport async function copyBlobToClipboard(blob: Blob, options?: ClipboardItemOptions): Promise<CopyResult> {\n if (!navigator.clipboard?.write) {\n return {\n error: new Error('Clipboard.write is not supported in this browser.'),\n ok: false,\n };\n }\n\n try {\n const item = new ClipboardItem({ [blob.type]: blob }, options);\n await navigator.clipboard.write([item]);\n return { ok: true };\n } catch (error) {\n return {\n error,\n ok: false,\n };\n }\n}\n\n/**\n * Attempts to copy the given text to the user's clipboard using the modern Clipboard API.\n *\n * ⚠️ Usage Notes:\n * - Must be called in a **secure context** (HTTPS or localhost).\n * - Must be called **in response to a user interaction** (e.g. click, input).\n * - Not supported in some older browsers (especially legacy Safari).\n *\n * @param {string} text - The string to be copied to the clipboard.\n *\n * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:\n * - `{ ok: true }` if the copy succeeded\n * - `{ ok: false, error }` if the copy failed, with the error included\n *\n * @example\n * ```typescript\n * const result = await copyTextToClipboard('Hello!');\n * if (result.ok) {\n * console.log('Copied!');\n * } else {\n * console.error('Copy failed:', result.error);\n * }\n * ```\n */\nexport async function copyTextToClipboard(text: string): Promise<CopyResult> {\n try {\n await navigator.clipboard.writeText(text);\n return { ok: true };\n } catch (error) {\n return {\n error,\n ok: false,\n };\n }\n}\n"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACI,eAAe,mBAAmB,CAAC,IAAU,EAAE,OAA8B,EAAA;AAChF,IAAA,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE;QAC7B,OAAO;AACH,YAAA,KAAK,EAAE,IAAI,KAAK,CAAC,mDAAmD,CAAC;AACrE,YAAA,EAAE,EAAE,KAAK;SACZ;;AAGL,IAAA,IAAI;AACA,QAAA,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,EAAE,OAAO,CAAC;QAC9D,MAAM,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;AACvC,QAAA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE;;IACrB,OAAO,KAAK,EAAE;QACZ,OAAO;YACH,KAAK;AACL,YAAA,EAAE,EAAE,KAAK;SACZ;;AAET;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACI,eAAe,mBAAmB,CAAC,IAAY,EAAA;AAClD,IAAA,IAAI;QACA,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC;AACzC,QAAA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE;;IACrB,OAAO,KAAK,EAAE;QACZ,OAAO;YACH,KAAK;AACL,YAAA,EAAE,EAAE,KAAK;SACZ;;AAET;;;;"}
|
package/dist/consola.cjs
CHANGED
package/dist/consola.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consola.cjs","sources":["../src/consola.ts"],"sourcesContent":["import { createConsola } from 'consola';\n\n/**\n * A consola logger instance.\n *\n * The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `0`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).\n *\n * @example\n * ```typescript\n * import logger from '@kikiutils/shared/consola';\n *\n * logger.info('test'); // ℹ test 3:56:30 AM\n *\n * // Manually change the level\n * logger.level = 3;\n * ```\n */\nexport const consolaLogger = createConsola();\nexport const logger = consolaLogger;\nif (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;\nelse consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;\n"],"names":["createConsola"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACU,MAAA,aAAa,GAAGA,qBAAa;AACnC,MAAM,MAAM,GAAG;AACtB,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,SAAS;IAAE,aAAa,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB;;IACtG,aAAa,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,CAAC,GAAG,aAAa,CAAC,KAAK;;;;;"}
|
|
1
|
+
{"version":3,"file":"consola.cjs","sources":["../src/consola.ts"],"sourcesContent":["import { createConsola } from 'consola';\n\n/**\n * A consola logger instance.\n *\n * The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `0`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).\n *\n * @example\n * ```typescript\n * import { logger } from '@kikiutils/shared/consola';\n *\n * logger.info('test'); // ℹ test 3:56:30 AM\n *\n * // Manually change the level\n * logger.level = 3;\n * ```\n */\nexport const consolaLogger = createConsola();\nexport const logger = consolaLogger;\nif (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;\nelse consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;\n"],"names":["createConsola"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACU,MAAA,aAAa,GAAGA,qBAAa;AACnC,MAAM,MAAM,GAAG;AACtB,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,SAAS;IAAE,aAAa,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB;;IACtG,aAAa,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,CAAC,GAAG,aAAa,CAAC,KAAK;;;;;"}
|
package/dist/consola.d.ts
CHANGED
package/dist/consola.mjs
CHANGED
package/dist/consola.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consola.mjs","sources":["../src/consola.ts"],"sourcesContent":["import { createConsola } from 'consola';\n\n/**\n * A consola logger instance.\n *\n * The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `0`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).\n *\n * @example\n * ```typescript\n * import logger from '@kikiutils/shared/consola';\n *\n * logger.info('test'); // ℹ test 3:56:30 AM\n *\n * // Manually change the level\n * logger.level = 3;\n * ```\n */\nexport const consolaLogger = createConsola();\nexport const logger = consolaLogger;\nif (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;\nelse consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACU,MAAA,aAAa,GAAG,aAAa;AACnC,MAAM,MAAM,GAAG;AACtB,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,SAAS;IAAE,aAAa,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB;;IACtG,aAAa,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,CAAC,GAAG,aAAa,CAAC,KAAK;;;;"}
|
|
1
|
+
{"version":3,"file":"consola.mjs","sources":["../src/consola.ts"],"sourcesContent":["import { createConsola } from 'consola';\n\n/**\n * A consola logger instance.\n *\n * The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `0`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).\n *\n * @example\n * ```typescript\n * import { logger } from '@kikiutils/shared/consola';\n *\n * logger.info('test'); // ℹ test 3:56:30 AM\n *\n * // Manually change the level\n * logger.level = 3;\n * ```\n */\nexport const consolaLogger = createConsola();\nexport const logger = consolaLogger;\nif (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;\nelse consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACU,MAAA,aAAa,GAAG,aAAa;AACnC,MAAM,MAAM,GAAG;AACtB,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,SAAS;IAAE,aAAa,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB;;IACtG,aAAa,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,CAAC,GAAG,aAAa,CAAC,KAAK;;;;"}
|
package/dist/crypto-hash.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const node_crypto = require('node:crypto');
|
|
|
6
6
|
* This file provides a set of functions for creating hash digests using different algorithms and bit lengths.
|
|
7
7
|
* It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,
|
|
8
8
|
* as well as a function for generating MD5 hash digests.
|
|
9
|
+
*
|
|
9
10
|
* These functions use the Node.js crypto module to generate the hashes.
|
|
10
11
|
* Can only be used in Node.js/Deno/Bun runtimes.
|
|
11
12
|
*
|
package/dist/crypto-hash.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.cjs","sources":["../src/crypto-hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating hash digests using different algorithms and bit lengths.\n * It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,\n * as well as a function for generating MD5 hash digests.\n * These functions use the Node.js crypto module to generate the hashes.\n * Can only be used in Node.js/Deno/Bun runtimes.\n *\n * @example\n * ```typescript\n * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\n\nimport { createHash } from 'node:crypto';\nimport type {\n BinaryLike,\n BinaryToTextEncoding,\n} from 'node:crypto';\n\nexport function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('md5').update(data).digest(outputEncoding);\n}\n\nexport function cryptoMd5ToBuffer(data: BinaryLike) {\n return createHash('md5').update(data).digest();\n}\n\nexport function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-224').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3224ToBuffer(data: BinaryLike) {\n return createHash('sha3-224').update(data).digest();\n}\n\nexport function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-256').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3256ToBuffer(data: BinaryLike) {\n return createHash('sha3-256').update(data).digest();\n}\n\nexport function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-384').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3384ToBuffer(data: BinaryLike) {\n return createHash('sha3-384').update(data).digest();\n}\n\nexport function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-512').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3512ToBuffer(data: BinaryLike) {\n return createHash('sha3-512').update(data).digest();\n}\n"],"names":["createHash"],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"crypto-hash.cjs","sources":["../src/crypto-hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating hash digests using different algorithms and bit lengths.\n * It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,\n * as well as a function for generating MD5 hash digests.\n *\n * These functions use the Node.js crypto module to generate the hashes.\n * Can only be used in Node.js/Deno/Bun runtimes.\n *\n * @example\n * ```typescript\n * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\n\nimport { createHash } from 'node:crypto';\nimport type {\n BinaryLike,\n BinaryToTextEncoding,\n} from 'node:crypto';\n\nexport function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('md5').update(data).digest(outputEncoding);\n}\n\nexport function cryptoMd5ToBuffer(data: BinaryLike) {\n return createHash('md5').update(data).digest();\n}\n\nexport function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-224').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3224ToBuffer(data: BinaryLike) {\n return createHash('sha3-224').update(data).digest();\n}\n\nexport function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-256').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3256ToBuffer(data: BinaryLike) {\n return createHash('sha3-256').update(data).digest();\n}\n\nexport function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-384').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3384ToBuffer(data: BinaryLike) {\n return createHash('sha3-384').update(data).digest();\n}\n\nexport function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-512').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3512ToBuffer(data: BinaryLike) {\n return createHash('sha3-512').update(data).digest();\n}\n"],"names":["createHash"],"mappings":";;;;AAAA;;;;;;;;;;;;;;AAcG;SAQa,SAAS,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACpF,IAAA,OAAOA,sBAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AAChE;AAEM,SAAU,iBAAiB,CAAC,IAAgB,EAAA;AAC9C,IAAA,OAAOA,sBAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AAClD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;;;;;;;;;;;;;"}
|
package/dist/crypto-hash.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* This file provides a set of functions for creating hash digests using different algorithms and bit lengths.
|
|
3
3
|
* It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,
|
|
4
4
|
* as well as a function for generating MD5 hash digests.
|
|
5
|
+
*
|
|
5
6
|
* These functions use the Node.js crypto module to generate the hashes.
|
|
6
7
|
* Can only be used in Node.js/Deno/Bun runtimes.
|
|
7
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.d.ts","sourceRoot":"","sources":["../src/crypto-hash.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"crypto-hash.d.ts","sourceRoot":"","sources":["../src/crypto-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EACR,UAAU,EACV,oBAAoB,EACvB,MAAM,aAAa,CAAC;AAErB,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,GAAE,oBAA4B,UAEvF;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,2BAEjD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,GAAE,oBAA4B,UAE3F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,2BAErD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,GAAE,oBAA4B,UAE3F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,2BAErD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,GAAE,oBAA4B,UAE3F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,2BAErD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,GAAE,oBAA4B,UAE3F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,2BAErD"}
|
package/dist/crypto-hash.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
* This file provides a set of functions for creating hash digests using different algorithms and bit lengths.
|
|
5
5
|
* It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,
|
|
6
6
|
* as well as a function for generating MD5 hash digests.
|
|
7
|
+
*
|
|
7
8
|
* These functions use the Node.js crypto module to generate the hashes.
|
|
8
9
|
* Can only be used in Node.js/Deno/Bun runtimes.
|
|
9
10
|
*
|
package/dist/crypto-hash.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.mjs","sources":["../src/crypto-hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating hash digests using different algorithms and bit lengths.\n * It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,\n * as well as a function for generating MD5 hash digests.\n * These functions use the Node.js crypto module to generate the hashes.\n * Can only be used in Node.js/Deno/Bun runtimes.\n *\n * @example\n * ```typescript\n * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\n\nimport { createHash } from 'node:crypto';\nimport type {\n BinaryLike,\n BinaryToTextEncoding,\n} from 'node:crypto';\n\nexport function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('md5').update(data).digest(outputEncoding);\n}\n\nexport function cryptoMd5ToBuffer(data: BinaryLike) {\n return createHash('md5').update(data).digest();\n}\n\nexport function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-224').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3224ToBuffer(data: BinaryLike) {\n return createHash('sha3-224').update(data).digest();\n}\n\nexport function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-256').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3256ToBuffer(data: BinaryLike) {\n return createHash('sha3-256').update(data).digest();\n}\n\nexport function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-384').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3384ToBuffer(data: BinaryLike) {\n return createHash('sha3-384').update(data).digest();\n}\n\nexport function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-512').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3512ToBuffer(data: BinaryLike) {\n return createHash('sha3-512').update(data).digest();\n}\n"],"names":[],"mappings":";;AAAA
|
|
1
|
+
{"version":3,"file":"crypto-hash.mjs","sources":["../src/crypto-hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating hash digests using different algorithms and bit lengths.\n * It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,\n * as well as a function for generating MD5 hash digests.\n *\n * These functions use the Node.js crypto module to generate the hashes.\n * Can only be used in Node.js/Deno/Bun runtimes.\n *\n * @example\n * ```typescript\n * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\n\nimport { createHash } from 'node:crypto';\nimport type {\n BinaryLike,\n BinaryToTextEncoding,\n} from 'node:crypto';\n\nexport function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('md5').update(data).digest(outputEncoding);\n}\n\nexport function cryptoMd5ToBuffer(data: BinaryLike) {\n return createHash('md5').update(data).digest();\n}\n\nexport function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-224').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3224ToBuffer(data: BinaryLike) {\n return createHash('sha3-224').update(data).digest();\n}\n\nexport function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-256').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3256ToBuffer(data: BinaryLike) {\n return createHash('sha3-256').update(data).digest();\n}\n\nexport function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-384').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3384ToBuffer(data: BinaryLike) {\n return createHash('sha3-384').update(data).digest();\n}\n\nexport function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-512').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3512ToBuffer(data: BinaryLike) {\n return createHash('sha3-512').update(data).digest();\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;AAcG;SAQa,SAAS,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACpF,IAAA,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AAChE;AAEM,SAAU,iBAAiB,CAAC,IAAgB,EAAA;AAC9C,IAAA,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AAClD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;;;;"}
|
package/dist/datetime.cjs
CHANGED
|
@@ -10,6 +10,7 @@ const dateFns = require('date-fns');
|
|
|
10
10
|
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string.
|
|
11
11
|
* @param {string} [format] - The target format string.
|
|
12
12
|
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`.
|
|
13
|
+
*
|
|
13
14
|
* @returns {string} The formatted date string.
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
@@ -41,6 +42,7 @@ function formatDate(date, format = 'yyyy-MM-dd HH:mm:ss', options) {
|
|
|
41
42
|
* @param {object} [options] - Optional settings.
|
|
42
43
|
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day.
|
|
43
44
|
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).
|
|
45
|
+
*
|
|
44
46
|
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`.
|
|
45
47
|
*
|
|
46
48
|
* @example
|
|
@@ -107,6 +109,7 @@ function getDateRangeFromDate(date, type, options) {
|
|
|
107
109
|
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
108
110
|
*
|
|
109
111
|
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative.
|
|
112
|
+
*
|
|
110
113
|
* @returns {Date} A `Date` object at 00:00:00 of the offset day.
|
|
111
114
|
*
|
|
112
115
|
* @example
|
package/dist/datetime.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.cjs","sources":["../src/datetime.ts"],"sourcesContent":["import {\n format as dateFnsFormat,\n endOfDay,\n endOfMonth,\n endOfWeek,\n startOfDay,\n startOfMonth,\n startOfWeek,\n subDays,\n subMonths,\n subWeeks,\n} from 'date-fns';\nimport type {\n DateArg,\n Day,\n FormatOptions,\n} from 'date-fns';\n\nexport type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';\n\n/**\n * Formats a given date, timestamp, or date string into a specified format.\n *\n * This function is a wrapper around `date-fns/format`.\n *\n * @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string.\n * @param {string} [format] - The target format string.\n * @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`.\n * @returns {string} The formatted date string.\n *\n * @example\n * ```typescript\n * import { formatDate } from '@kikiutils/shared/datetime';\n *\n * // Format a Date object\n * console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10\n *\n * // Format a timestamp\n * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15\n *\n * // Format a date string\n * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10\n * ```\n *\n * @see https://date-fns.org/docs/format\n */\nexport function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-dd HH:mm:ss', options?: FormatOptions) {\n return dateFnsFormat(date, format, options);\n}\n\n/**\n * Get the date range (start and end) based on a given date and range type.\n *\n * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.\n *\n * @param {Date} date - The reference date.\n * @param {DateRangeType} type - The range type to compute.\n * @param {object} [options] - Optional settings.\n * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day.\n * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).\n * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`.\n *\n * @example\n * ```typescript\n * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';\n *\n * // Get the date range for last month\n * const date = new Date('2023-07-01');\n * console.log(getDateRangeFromDate(date, 'lastMonth'));\n * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }\n *\n * // Get this week's range with Sunday as the first day\n * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));\n * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }\n * ```\n */\nexport function getDateRangeFromDate(\n date: Date,\n type: DateRangeType,\n options?: {\n setEndDateToNextDayStart?: boolean;\n weekStartsOn?: Day;\n },\n) {\n let endDate: Date;\n let startDate: Date;\n switch (type) {\n case 'lastMonth':\n {\n const lastMonth = subMonths(date, 1);\n endDate = endOfMonth(lastMonth);\n startDate = startOfMonth(lastMonth);\n }\n\n break;\n case 'lastWeek':\n {\n const lastWeek = subWeeks(date, 1);\n endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n }\n\n break;\n case 'thisMonth':\n endDate = endOfMonth(date);\n startDate = startOfMonth(date);\n break;\n case 'thisWeek':\n endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n break;\n case 'today':\n endDate = endOfDay(date);\n startDate = startOfDay(date);\n break;\n case 'yesterday':\n {\n const yesterday = subDays(date, 1);\n endDate = endOfDay(yesterday);\n startDate = startOfDay(yesterday);\n }\n\n break;\n default: throw new Error(`Unsupported date range type: ${type}.`);\n }\n\n if (options?.setEndDateToNextDayStart) endDate.setHours(24, 0, 0, 0);\n return {\n endDate,\n startDate,\n };\n}\n\n/**\n * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.\n *\n * @param {number} [offsetDays] - Number of days to offset from today. Can be negative.\n * @returns {Date} A `Date` object at 00:00:00 of the offset day.\n *\n * @example\n * ```typescript\n * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';\n *\n * console.log(getMidnightDateFromToday()); // today at 00:00:00\n * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00\n * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00\n * ```\n */\nexport function getMidnightDateFromToday(offsetDays: number = 0) {\n const date = new Date();\n date.setDate(date.getDate() + offsetDays);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n"],"names":["dateFnsFormat","subMonths","endOfMonth","startOfMonth","subWeeks","endOfWeek","startOfWeek","endOfDay","startOfDay","subDays"],"mappings":";;;;AAoBA
|
|
1
|
+
{"version":3,"file":"datetime.cjs","sources":["../src/datetime.ts"],"sourcesContent":["import {\n format as dateFnsFormat,\n endOfDay,\n endOfMonth,\n endOfWeek,\n startOfDay,\n startOfMonth,\n startOfWeek,\n subDays,\n subMonths,\n subWeeks,\n} from 'date-fns';\nimport type {\n DateArg,\n Day,\n FormatOptions,\n} from 'date-fns';\n\nexport type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';\n\n/**\n * Formats a given date, timestamp, or date string into a specified format.\n *\n * This function is a wrapper around `date-fns/format`.\n *\n * @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string.\n * @param {string} [format] - The target format string.\n * @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`.\n *\n * @returns {string} The formatted date string.\n *\n * @example\n * ```typescript\n * import { formatDate } from '@kikiutils/shared/datetime';\n *\n * // Format a Date object\n * console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10\n *\n * // Format a timestamp\n * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15\n *\n * // Format a date string\n * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10\n * ```\n *\n * @see https://date-fns.org/docs/format\n */\nexport function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-dd HH:mm:ss', options?: FormatOptions) {\n return dateFnsFormat(date, format, options);\n}\n\n/**\n * Get the date range (start and end) based on a given date and range type.\n *\n * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.\n *\n * @param {Date} date - The reference date.\n * @param {DateRangeType} type - The range type to compute.\n * @param {object} [options] - Optional settings.\n * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day.\n * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).\n *\n * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`.\n *\n * @example\n * ```typescript\n * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';\n *\n * // Get the date range for last month\n * const date = new Date('2023-07-01');\n * console.log(getDateRangeFromDate(date, 'lastMonth'));\n * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }\n *\n * // Get this week's range with Sunday as the first day\n * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));\n * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }\n * ```\n */\nexport function getDateRangeFromDate(\n date: Date,\n type: DateRangeType,\n options?: {\n setEndDateToNextDayStart?: boolean;\n weekStartsOn?: Day;\n },\n) {\n let endDate: Date;\n let startDate: Date;\n switch (type) {\n case 'lastMonth':\n {\n const lastMonth = subMonths(date, 1);\n endDate = endOfMonth(lastMonth);\n startDate = startOfMonth(lastMonth);\n }\n\n break;\n case 'lastWeek':\n {\n const lastWeek = subWeeks(date, 1);\n endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n }\n\n break;\n case 'thisMonth':\n endDate = endOfMonth(date);\n startDate = startOfMonth(date);\n break;\n case 'thisWeek':\n endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n break;\n case 'today':\n endDate = endOfDay(date);\n startDate = startOfDay(date);\n break;\n case 'yesterday':\n {\n const yesterday = subDays(date, 1);\n endDate = endOfDay(yesterday);\n startDate = startOfDay(yesterday);\n }\n\n break;\n default: throw new Error(`Unsupported date range type: ${type}.`);\n }\n\n if (options?.setEndDateToNextDayStart) endDate.setHours(24, 0, 0, 0);\n return {\n endDate,\n startDate,\n };\n}\n\n/**\n * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.\n *\n * @param {number} [offsetDays] - Number of days to offset from today. Can be negative.\n *\n * @returns {Date} A `Date` object at 00:00:00 of the offset day.\n *\n * @example\n * ```typescript\n * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';\n *\n * console.log(getMidnightDateFromToday()); // today at 00:00:00\n * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00\n * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00\n * ```\n */\nexport function getMidnightDateFromToday(offsetDays: number = 0) {\n const date = new Date();\n date.setDate(date.getDate() + offsetDays);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n"],"names":["dateFnsFormat","subMonths","endOfMonth","startOfMonth","subWeeks","endOfWeek","startOfWeek","endOfDay","startOfDay","subDays"],"mappings":";;;;AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,UAAU,CAAC,IAAwB,EAAE,MAAiB,GAAA,qBAAqB,EAAE,OAAuB,EAAA;IAChH,OAAOA,cAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC;AAC/C;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;SACa,oBAAoB,CAChC,IAAU,EACV,IAAmB,EACnB,OAGC,EAAA;AAED,IAAA,IAAI,OAAa;AACjB,IAAA,IAAI,SAAe;IACnB,QAAQ,IAAI;AACR,QAAA,KAAK,WAAW;YACZ;gBACI,MAAM,SAAS,GAAGC,iBAAS,CAAC,IAAI,EAAE,CAAC,CAAC;AACpC,gBAAA,OAAO,GAAGC,kBAAU,CAAC,SAAS,CAAC;AAC/B,gBAAA,SAAS,GAAGC,oBAAY,CAAC,SAAS,CAAC;;YAGvC;AACJ,QAAA,KAAK,UAAU;YACX;gBACI,MAAM,QAAQ,GAAGC,gBAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAGC,iBAAS,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;AAC3E,gBAAA,SAAS,GAAGC,mBAAW,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;;YAGnF;AACJ,QAAA,KAAK,WAAW;AACZ,YAAA,OAAO,GAAGJ,kBAAU,CAAC,IAAI,CAAC;AAC1B,YAAA,SAAS,GAAGC,oBAAY,CAAC,IAAI,CAAC;YAC9B;AACJ,QAAA,KAAK,UAAU;AACX,YAAA,OAAO,GAAGE,iBAAS,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;AACvE,YAAA,SAAS,GAAGC,mBAAW,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;YAC3E;AACJ,QAAA,KAAK,OAAO;AACR,YAAA,OAAO,GAAGC,gBAAQ,CAAC,IAAI,CAAC;AACxB,YAAA,SAAS,GAAGC,kBAAU,CAAC,IAAI,CAAC;YAC5B;AACJ,QAAA,KAAK,WAAW;YACZ;gBACI,MAAM,SAAS,GAAGC,eAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAGF,gBAAQ,CAAC,SAAS,CAAC;AAC7B,gBAAA,SAAS,GAAGC,kBAAU,CAAC,SAAS,CAAC;;YAGrC;QACJ,SAAS,MAAM,IAAI,KAAK,CAAC,CAAgC,6BAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAC;;IAGrE,IAAI,OAAO,EAAE,wBAAwB;QAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACpE,OAAO;QACH,OAAO;QACP,SAAS;KACZ;AACL;AAEA;;;;;;;;;;;;;;;AAeG;AACa,SAAA,wBAAwB,CAAC,UAAA,GAAqB,CAAC,EAAA;AAC3D,IAAA,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE;IACvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC;IACzC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACzB,IAAA,OAAO,IAAI;AACf;;;;;;"}
|
package/dist/datetime.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek'
|
|
|
8
8
|
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string.
|
|
9
9
|
* @param {string} [format] - The target format string.
|
|
10
10
|
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`.
|
|
11
|
+
*
|
|
11
12
|
* @returns {string} The formatted date string.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
@@ -37,6 +38,7 @@ export declare function formatDate(date: DateArg<Date> & {}, format?: string, op
|
|
|
37
38
|
* @param {object} [options] - Optional settings.
|
|
38
39
|
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day.
|
|
39
40
|
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).
|
|
41
|
+
*
|
|
40
42
|
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`.
|
|
41
43
|
*
|
|
42
44
|
* @example
|
|
@@ -64,6 +66,7 @@ export declare function getDateRangeFromDate(date: Date, type: DateRangeType, op
|
|
|
64
66
|
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
65
67
|
*
|
|
66
68
|
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative.
|
|
69
|
+
*
|
|
67
70
|
* @returns {Date} A `Date` object at 00:00:00 of the offset day.
|
|
68
71
|
*
|
|
69
72
|
* @example
|
package/dist/datetime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../src/datetime.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACR,OAAO,EACP,GAAG,EACH,aAAa,EAChB,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,GAAG,WAAW,CAAC;AAExG
|
|
1
|
+
{"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../src/datetime.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACR,OAAO,EACP,GAAG,EACH,aAAa,EAChB,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,GAAG,WAAW,CAAC;AAExG;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,MAAM,GAAE,MAA8B,EAAE,OAAO,CAAC,EAAE,aAAa,UAEnH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,aAAa,EACnB,OAAO,CAAC,EAAE;IACN,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,YAAY,CAAC,EAAE,GAAG,CAAC;CACtB;;;EAiDJ;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,GAAE,MAAU,QAK9D"}
|
package/dist/datetime.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { format, subDays, endOfDay, startOfDay, endOfWeek, startOfWeek, endOfMon
|
|
|
8
8
|
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string.
|
|
9
9
|
* @param {string} [format] - The target format string.
|
|
10
10
|
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`.
|
|
11
|
+
*
|
|
11
12
|
* @returns {string} The formatted date string.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
@@ -39,6 +40,7 @@ function formatDate(date, format$1 = 'yyyy-MM-dd HH:mm:ss', options) {
|
|
|
39
40
|
* @param {object} [options] - Optional settings.
|
|
40
41
|
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day.
|
|
41
42
|
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).
|
|
43
|
+
*
|
|
42
44
|
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`.
|
|
43
45
|
*
|
|
44
46
|
* @example
|
|
@@ -105,6 +107,7 @@ function getDateRangeFromDate(date, type, options) {
|
|
|
105
107
|
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
106
108
|
*
|
|
107
109
|
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative.
|
|
110
|
+
*
|
|
108
111
|
* @returns {Date} A `Date` object at 00:00:00 of the offset day.
|
|
109
112
|
*
|
|
110
113
|
* @example
|
package/dist/datetime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.mjs","sources":["../src/datetime.ts"],"sourcesContent":["import {\n format as dateFnsFormat,\n endOfDay,\n endOfMonth,\n endOfWeek,\n startOfDay,\n startOfMonth,\n startOfWeek,\n subDays,\n subMonths,\n subWeeks,\n} from 'date-fns';\nimport type {\n DateArg,\n Day,\n FormatOptions,\n} from 'date-fns';\n\nexport type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';\n\n/**\n * Formats a given date, timestamp, or date string into a specified format.\n *\n * This function is a wrapper around `date-fns/format`.\n *\n * @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string.\n * @param {string} [format] - The target format string.\n * @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`.\n * @returns {string} The formatted date string.\n *\n * @example\n * ```typescript\n * import { formatDate } from '@kikiutils/shared/datetime';\n *\n * // Format a Date object\n * console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10\n *\n * // Format a timestamp\n * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15\n *\n * // Format a date string\n * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10\n * ```\n *\n * @see https://date-fns.org/docs/format\n */\nexport function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-dd HH:mm:ss', options?: FormatOptions) {\n return dateFnsFormat(date, format, options);\n}\n\n/**\n * Get the date range (start and end) based on a given date and range type.\n *\n * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.\n *\n * @param {Date} date - The reference date.\n * @param {DateRangeType} type - The range type to compute.\n * @param {object} [options] - Optional settings.\n * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day.\n * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).\n * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`.\n *\n * @example\n * ```typescript\n * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';\n *\n * // Get the date range for last month\n * const date = new Date('2023-07-01');\n * console.log(getDateRangeFromDate(date, 'lastMonth'));\n * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }\n *\n * // Get this week's range with Sunday as the first day\n * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));\n * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }\n * ```\n */\nexport function getDateRangeFromDate(\n date: Date,\n type: DateRangeType,\n options?: {\n setEndDateToNextDayStart?: boolean;\n weekStartsOn?: Day;\n },\n) {\n let endDate: Date;\n let startDate: Date;\n switch (type) {\n case 'lastMonth':\n {\n const lastMonth = subMonths(date, 1);\n endDate = endOfMonth(lastMonth);\n startDate = startOfMonth(lastMonth);\n }\n\n break;\n case 'lastWeek':\n {\n const lastWeek = subWeeks(date, 1);\n endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n }\n\n break;\n case 'thisMonth':\n endDate = endOfMonth(date);\n startDate = startOfMonth(date);\n break;\n case 'thisWeek':\n endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n break;\n case 'today':\n endDate = endOfDay(date);\n startDate = startOfDay(date);\n break;\n case 'yesterday':\n {\n const yesterday = subDays(date, 1);\n endDate = endOfDay(yesterday);\n startDate = startOfDay(yesterday);\n }\n\n break;\n default: throw new Error(`Unsupported date range type: ${type}.`);\n }\n\n if (options?.setEndDateToNextDayStart) endDate.setHours(24, 0, 0, 0);\n return {\n endDate,\n startDate,\n };\n}\n\n/**\n * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.\n *\n * @param {number} [offsetDays] - Number of days to offset from today. Can be negative.\n * @returns {Date} A `Date` object at 00:00:00 of the offset day.\n *\n * @example\n * ```typescript\n * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';\n *\n * console.log(getMidnightDateFromToday()); // today at 00:00:00\n * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00\n * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00\n * ```\n */\nexport function getMidnightDateFromToday(offsetDays: number = 0) {\n const date = new Date();\n date.setDate(date.getDate() + offsetDays);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n"],"names":["format","dateFnsFormat"],"mappings":";;AAoBA
|
|
1
|
+
{"version":3,"file":"datetime.mjs","sources":["../src/datetime.ts"],"sourcesContent":["import {\n format as dateFnsFormat,\n endOfDay,\n endOfMonth,\n endOfWeek,\n startOfDay,\n startOfMonth,\n startOfWeek,\n subDays,\n subMonths,\n subWeeks,\n} from 'date-fns';\nimport type {\n DateArg,\n Day,\n FormatOptions,\n} from 'date-fns';\n\nexport type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';\n\n/**\n * Formats a given date, timestamp, or date string into a specified format.\n *\n * This function is a wrapper around `date-fns/format`.\n *\n * @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string.\n * @param {string} [format] - The target format string.\n * @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`.\n *\n * @returns {string} The formatted date string.\n *\n * @example\n * ```typescript\n * import { formatDate } from '@kikiutils/shared/datetime';\n *\n * // Format a Date object\n * console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10\n *\n * // Format a timestamp\n * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15\n *\n * // Format a date string\n * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10\n * ```\n *\n * @see https://date-fns.org/docs/format\n */\nexport function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-dd HH:mm:ss', options?: FormatOptions) {\n return dateFnsFormat(date, format, options);\n}\n\n/**\n * Get the date range (start and end) based on a given date and range type.\n *\n * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.\n *\n * @param {Date} date - The reference date.\n * @param {DateRangeType} type - The range type to compute.\n * @param {object} [options] - Optional settings.\n * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day.\n * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).\n *\n * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`.\n *\n * @example\n * ```typescript\n * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';\n *\n * // Get the date range for last month\n * const date = new Date('2023-07-01');\n * console.log(getDateRangeFromDate(date, 'lastMonth'));\n * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }\n *\n * // Get this week's range with Sunday as the first day\n * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));\n * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }\n * ```\n */\nexport function getDateRangeFromDate(\n date: Date,\n type: DateRangeType,\n options?: {\n setEndDateToNextDayStart?: boolean;\n weekStartsOn?: Day;\n },\n) {\n let endDate: Date;\n let startDate: Date;\n switch (type) {\n case 'lastMonth':\n {\n const lastMonth = subMonths(date, 1);\n endDate = endOfMonth(lastMonth);\n startDate = startOfMonth(lastMonth);\n }\n\n break;\n case 'lastWeek':\n {\n const lastWeek = subWeeks(date, 1);\n endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n }\n\n break;\n case 'thisMonth':\n endDate = endOfMonth(date);\n startDate = startOfMonth(date);\n break;\n case 'thisWeek':\n endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n break;\n case 'today':\n endDate = endOfDay(date);\n startDate = startOfDay(date);\n break;\n case 'yesterday':\n {\n const yesterday = subDays(date, 1);\n endDate = endOfDay(yesterday);\n startDate = startOfDay(yesterday);\n }\n\n break;\n default: throw new Error(`Unsupported date range type: ${type}.`);\n }\n\n if (options?.setEndDateToNextDayStart) endDate.setHours(24, 0, 0, 0);\n return {\n endDate,\n startDate,\n };\n}\n\n/**\n * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.\n *\n * @param {number} [offsetDays] - Number of days to offset from today. Can be negative.\n *\n * @returns {Date} A `Date` object at 00:00:00 of the offset day.\n *\n * @example\n * ```typescript\n * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';\n *\n * console.log(getMidnightDateFromToday()); // today at 00:00:00\n * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00\n * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00\n * ```\n */\nexport function getMidnightDateFromToday(offsetDays: number = 0) {\n const date = new Date();\n date.setDate(date.getDate() + offsetDays);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n"],"names":["format","dateFnsFormat"],"mappings":";;AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,UAAU,CAAC,IAAwB,EAAEA,QAAiB,GAAA,qBAAqB,EAAE,OAAuB,EAAA;IAChH,OAAOC,MAAa,CAAC,IAAI,EAAED,QAAM,EAAE,OAAO,CAAC;AAC/C;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;SACa,oBAAoB,CAChC,IAAU,EACV,IAAmB,EACnB,OAGC,EAAA;AAED,IAAA,IAAI,OAAa;AACjB,IAAA,IAAI,SAAe;IACnB,QAAQ,IAAI;AACR,QAAA,KAAK,WAAW;YACZ;gBACI,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;AACpC,gBAAA,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC;AAC/B,gBAAA,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;;YAGvC;AACJ,QAAA,KAAK,UAAU;YACX;gBACI,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;AAC3E,gBAAA,SAAS,GAAG,WAAW,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;;YAGnF;AACJ,QAAA,KAAK,WAAW;AACZ,YAAA,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC;AAC1B,YAAA,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC;YAC9B;AACJ,QAAA,KAAK,UAAU;AACX,YAAA,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;AACvE,YAAA,SAAS,GAAG,WAAW,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;YAC3E;AACJ,QAAA,KAAK,OAAO;AACR,YAAA,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC;AACxB,YAAA,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC;YAC5B;AACJ,QAAA,KAAK,WAAW;YACZ;gBACI,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC;AAC7B,gBAAA,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;;YAGrC;QACJ,SAAS,MAAM,IAAI,KAAK,CAAC,CAAgC,6BAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAC;;IAGrE,IAAI,OAAO,EAAE,wBAAwB;QAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACpE,OAAO;QACH,OAAO;QACP,SAAS;KACZ;AACL;AAEA;;;;;;;;;;;;;;;AAeG;AACa,SAAA,wBAAwB,CAAC,UAAA,GAAqB,CAAC,EAAA;AAC3D,IAAA,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE;IACvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC;IACzC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACzB,IAAA,OAAO,IAAI;AACf;;;;"}
|
package/dist/enum.cjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param {Record<number | string, number | string>} data - The enumeration-like object to extract numeric values from.
|
|
7
7
|
* The keys can be numbers or strings, and the values can be numbers or strings.
|
|
8
|
+
*
|
|
8
9
|
* @returns {number[]} An array of numeric values extracted from the object.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
@@ -28,6 +29,7 @@ function getEnumNumberValues(data) {
|
|
|
28
29
|
*
|
|
29
30
|
* @param {Record<number | string, number | string>} data - The enumeration-like object to extract string values from.
|
|
30
31
|
* The keys can be numbers or strings, and the values can be numbers or strings.
|
|
32
|
+
*
|
|
31
33
|
* @returns {string[]} An array of string values extracted from the object.
|
|
32
34
|
*
|
|
33
35
|
* @example
|