@kikiutils/shared 11.0.0 → 13.0.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 +10 -1
- package/dist/buffer.d.ts +7 -3
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +42 -0
- package/dist/buffer.js.map +1 -0
- package/dist/clipboard.d.ts +8 -6
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +86 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/consola.d.ts +8 -2
- package/dist/consola.d.ts.map +1 -1
- package/dist/consola.js +32 -0
- package/dist/consola.js.map +1 -0
- package/dist/crypto-hash.d.ts +16 -26
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +37 -0
- package/dist/crypto-hash.js.map +1 -0
- package/dist/datetime.d.ts +13 -9
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +131 -0
- package/dist/datetime.js.map +1 -0
- package/dist/element-plus.d.ts +8 -4
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/element-plus.js +37 -0
- package/dist/element-plus.js.map +1 -0
- package/dist/enum.d.ts +6 -3
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js +108 -0
- package/dist/enum.js.map +1 -0
- package/dist/env.d.ts +12 -9
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +51 -0
- package/dist/env.js.map +1 -0
- package/dist/general.d.ts +5 -2
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js +8 -0
- package/dist/general.js.map +1 -0
- package/dist/hash.d.ts +7 -4
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +20 -0
- package/dist/hash.js.map +1 -0
- package/dist/math.d.ts +20 -17
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +36 -0
- package/dist/math.js.map +1 -0
- package/dist/number.d.ts +7 -2
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +32 -0
- package/dist/number.js.map +1 -0
- package/dist/object.d.ts +4 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +42 -0
- package/dist/object.js.map +1 -0
- package/dist/pino.d.ts +8 -2
- package/dist/pino.d.ts.map +1 -1
- package/dist/pino.js +40 -0
- package/dist/pino.js.map +1 -0
- package/dist/random.d.ts +4 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +31 -0
- package/dist/random.js.map +1 -0
- package/dist/storage/enhanced/local/core.d.ts +45 -42
- package/dist/storage/enhanced/local/core.d.ts.map +1 -1
- package/dist/storage/enhanced/local/core.js +63 -0
- package/dist/storage/enhanced/local/core.js.map +1 -0
- package/dist/storage/enhanced/local/index.d.ts +3 -3
- package/dist/storage/enhanced/local/index.js +4 -0
- package/dist/storage/enhanced/local/keyed-store.d.ts +14 -11
- package/dist/storage/enhanced/local/keyed-store.d.ts.map +1 -1
- package/dist/storage/enhanced/local/keyed-store.js +36 -0
- package/dist/storage/enhanced/local/keyed-store.js.map +1 -0
- package/dist/storage/enhanced/redis/core.d.ts +64 -59
- package/dist/storage/enhanced/redis/core.d.ts.map +1 -1
- package/dist/storage/enhanced/redis/core.js +85 -0
- package/dist/storage/enhanced/redis/core.js.map +1 -0
- package/dist/storage/enhanced/redis/index.d.ts +3 -3
- package/dist/storage/enhanced/redis/index.js +4 -0
- package/dist/storage/enhanced/redis/keyed-store.d.ts +19 -14
- package/dist/storage/enhanced/redis/keyed-store.d.ts.map +1 -1
- package/dist/storage/enhanced/redis/keyed-store.js +41 -0
- package/dist/storage/enhanced/redis/keyed-store.js.map +1 -0
- package/dist/storage/lru/keyed-store.d.ts +21 -16
- package/dist/storage/lru/keyed-store.d.ts.map +1 -1
- package/dist/storage/lru/keyed-store.js +40 -0
- package/dist/storage/lru/keyed-store.js.map +1 -0
- package/dist/string.d.ts +5 -2
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +42 -0
- package/dist/string.js.map +1 -0
- package/dist/url.d.ts +4 -1
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +21 -0
- package/dist/url.js.map +1 -0
- package/dist/vue.d.ts +10 -5
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +58 -0
- package/dist/vue.js.map +1 -0
- package/dist/web.d.ts +5 -2
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +32 -0
- package/dist/web.js.map +1 -0
- package/package.json +108 -32
- package/src/hash.ts +19 -5
- package/src/vue.ts +1 -1
- package/src/web.ts +1 -1
- package/dist/buffer.cjs +0 -43
- package/dist/buffer.cjs.map +0 -1
- package/dist/buffer.mjs +0 -41
- package/dist/buffer.mjs.map +0 -1
- package/dist/clipboard.cjs +0 -91
- package/dist/clipboard.cjs.map +0 -1
- package/dist/clipboard.mjs +0 -88
- package/dist/clipboard.mjs.map +0 -1
- package/dist/consola.cjs +0 -35
- package/dist/consola.cjs.map +0 -1
- package/dist/consola.mjs +0 -32
- package/dist/consola.mjs.map +0 -1
- package/dist/crypto-hash.cjs +0 -61
- package/dist/crypto-hash.cjs.map +0 -1
- package/dist/crypto-hash.mjs +0 -50
- package/dist/crypto-hash.mjs.map +0 -1
- package/dist/datetime.cjs +0 -134
- package/dist/datetime.cjs.map +0 -1
- package/dist/datetime.mjs +0 -130
- package/dist/datetime.mjs.map +0 -1
- package/dist/element-plus.cjs +0 -37
- package/dist/element-plus.cjs.map +0 -1
- package/dist/element-plus.mjs +0 -35
- package/dist/element-plus.mjs.map +0 -1
- package/dist/enum.cjs +0 -112
- package/dist/enum.cjs.map +0 -1
- package/dist/enum.mjs +0 -108
- package/dist/enum.mjs.map +0 -1
- package/dist/env.cjs +0 -53
- package/dist/env.cjs.map +0 -1
- package/dist/env.mjs +0 -50
- package/dist/env.mjs.map +0 -1
- package/dist/general.cjs +0 -10
- package/dist/general.cjs.map +0 -1
- package/dist/general.mjs +0 -8
- package/dist/general.mjs.map +0 -1
- package/dist/hash.cjs +0 -28
- package/dist/hash.cjs.map +0 -1
- package/dist/hash.mjs +0 -23
- package/dist/hash.mjs.map +0 -1
- package/dist/math.cjs +0 -38
- package/dist/math.cjs.map +0 -1
- package/dist/math.mjs +0 -36
- package/dist/math.mjs.map +0 -1
- package/dist/number.cjs +0 -32
- package/dist/number.cjs.map +0 -1
- package/dist/number.mjs +0 -30
- package/dist/number.mjs.map +0 -1
- package/dist/object.cjs +0 -55
- package/dist/object.cjs.map +0 -1
- package/dist/object.mjs +0 -53
- package/dist/object.mjs.map +0 -1
- package/dist/pino.cjs +0 -42
- package/dist/pino.cjs.map +0 -1
- package/dist/pino.mjs +0 -39
- package/dist/pino.mjs.map +0 -1
- package/dist/random.cjs +0 -31
- package/dist/random.cjs.map +0 -1
- package/dist/random.mjs +0 -29
- package/dist/random.mjs.map +0 -1
- package/dist/storage/enhanced/local/core.cjs +0 -105
- package/dist/storage/enhanced/local/core.cjs.map +0 -1
- package/dist/storage/enhanced/local/core.mjs +0 -103
- package/dist/storage/enhanced/local/core.mjs.map +0 -1
- package/dist/storage/enhanced/local/index.cjs +0 -10
- package/dist/storage/enhanced/local/index.cjs.map +0 -1
- package/dist/storage/enhanced/local/index.d.ts.map +0 -1
- package/dist/storage/enhanced/local/index.mjs +0 -3
- package/dist/storage/enhanced/local/index.mjs.map +0 -1
- package/dist/storage/enhanced/local/keyed-store.cjs +0 -41
- package/dist/storage/enhanced/local/keyed-store.cjs.map +0 -1
- package/dist/storage/enhanced/local/keyed-store.mjs +0 -39
- package/dist/storage/enhanced/local/keyed-store.mjs.map +0 -1
- package/dist/storage/enhanced/redis/core.cjs +0 -144
- package/dist/storage/enhanced/redis/core.cjs.map +0 -1
- package/dist/storage/enhanced/redis/core.mjs +0 -142
- package/dist/storage/enhanced/redis/core.mjs.map +0 -1
- package/dist/storage/enhanced/redis/index.cjs +0 -10
- package/dist/storage/enhanced/redis/index.cjs.map +0 -1
- package/dist/storage/enhanced/redis/index.d.ts.map +0 -1
- package/dist/storage/enhanced/redis/index.mjs +0 -3
- package/dist/storage/enhanced/redis/index.mjs.map +0 -1
- package/dist/storage/enhanced/redis/keyed-store.cjs +0 -46
- package/dist/storage/enhanced/redis/keyed-store.cjs.map +0 -1
- package/dist/storage/enhanced/redis/keyed-store.mjs +0 -44
- package/dist/storage/enhanced/redis/keyed-store.mjs.map +0 -1
- package/dist/storage/lru/keyed-store.cjs +0 -49
- package/dist/storage/lru/keyed-store.cjs.map +0 -1
- package/dist/storage/lru/keyed-store.mjs +0 -47
- package/dist/storage/lru/keyed-store.mjs.map +0 -1
- package/dist/string.cjs +0 -45
- package/dist/string.cjs.map +0 -1
- package/dist/string.mjs +0 -43
- package/dist/string.mjs.map +0 -1
- package/dist/url.cjs +0 -21
- package/dist/url.cjs.map +0 -1
- package/dist/url.mjs +0 -19
- package/dist/url.mjs.map +0 -1
- package/dist/vue.cjs +0 -64
- package/dist/vue.cjs.map +0 -1
- package/dist/vue.mjs +0 -59
- package/dist/vue.mjs.map +0 -1
- package/dist/web.cjs +0 -35
- package/dist/web.cjs.map +0 -1
- package/dist/web.mjs +0 -32
- package/dist/web.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ A lightweight and modular utility library for modern JavaScript and TypeScript
|
|
|
28
28
|
|
|
29
29
|
## Requirements
|
|
30
30
|
|
|
31
|
-
- **Node.js** `>=
|
|
31
|
+
- **Node.js** `>= 22.0.0`
|
|
32
32
|
|
|
33
33
|
## Installation
|
|
34
34
|
|
|
@@ -67,6 +67,10 @@ logger.info(value);
|
|
|
67
67
|
|
|
68
68
|
Each module file includes function-level comments and usage examples.
|
|
69
69
|
|
|
70
|
+
### [buffer](./src/buffer.ts)
|
|
71
|
+
|
|
72
|
+
- `toBuffer`
|
|
73
|
+
|
|
70
74
|
### [clipboard](./src/clipboard.ts)
|
|
71
75
|
|
|
72
76
|
- `copyBlobToClipboard`
|
|
@@ -98,6 +102,7 @@ Console logger integration.
|
|
|
98
102
|
|
|
99
103
|
- `getEnumStringValues`
|
|
100
104
|
- `getEnumNumberValues`
|
|
105
|
+
- `getEnumValues`
|
|
101
106
|
|
|
102
107
|
### [env](./src/env.ts)
|
|
103
108
|
|
|
@@ -122,6 +127,10 @@ Console logger integration.
|
|
|
122
127
|
|
|
123
128
|
- `toCompactNumberString`
|
|
124
129
|
|
|
130
|
+
### [object](./src/object.ts)
|
|
131
|
+
|
|
132
|
+
- `stringifyObjectDeterministically`
|
|
133
|
+
|
|
125
134
|
### [pino](./src/pino.ts)
|
|
126
135
|
|
|
127
136
|
Pino logger integration.
|
package/dist/buffer.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Buffer } from
|
|
2
|
-
|
|
1
|
+
import { Blob as Blob$1, Buffer, File as File$1 } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
//#region src/buffer.d.ts
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Converts a Blob, Buffer, or File to a Buffer.
|
|
5
7
|
*
|
|
@@ -31,5 +33,7 @@ import type { Blob as NodeBlob, File as NodeFile } from 'node:buffer';
|
|
|
31
33
|
* console.log(result3.toString()); // 'File content'
|
|
32
34
|
* ```
|
|
33
35
|
*/
|
|
34
|
-
|
|
36
|
+
declare function toBuffer(input: Blob | Buffer | File | Blob$1 | File$1): Promise<Buffer<ArrayBufferLike>>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { toBuffer };
|
|
35
39
|
//# sourceMappingURL=buffer.d.ts.map
|
package/dist/buffer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"sourcesContent":[],"mappings":";;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAsB,QAAA,QAAgB,OAAO,SAAS,OAAO,SAAW,SAAQ,QAAA,OAAA"}
|
package/dist/buffer.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
//#region src/buffer.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a Blob, Buffer, or File to a Buffer.
|
|
6
|
+
*
|
|
7
|
+
* This function provides a unified way to convert various binary data types
|
|
8
|
+
* to Node.js Buffer. If the input is already a Buffer, it returns it as-is.
|
|
9
|
+
* For Blob or File inputs, it converts them to Buffer via ArrayBuffer.
|
|
10
|
+
*
|
|
11
|
+
* @param {Blob | Buffer | File} input - The input to convert to Buffer
|
|
12
|
+
*
|
|
13
|
+
* @returns {Promise<Buffer>} A Promise that resolves to a Buffer
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { toBuffer } from '@kikiutils/shared/general';
|
|
18
|
+
*
|
|
19
|
+
* // Convert a Buffer (returns as-is)
|
|
20
|
+
* const buffer = Buffer.from('Hello World');
|
|
21
|
+
* const result1 = await toBuffer(buffer);
|
|
22
|
+
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
23
|
+
*
|
|
24
|
+
* // Convert a Blob
|
|
25
|
+
* const blob = new Blob(['Hello from Blob'], { type: 'text/plain' });
|
|
26
|
+
* const result2 = await toBuffer(blob);
|
|
27
|
+
* console.log(result2.toString()); // 'Hello from Blob'
|
|
28
|
+
*
|
|
29
|
+
* // Convert a File
|
|
30
|
+
* const file = new File(['File content'], 'test.txt', { type: 'text/plain' });
|
|
31
|
+
* const result3 = await toBuffer(file);
|
|
32
|
+
* console.log(result3.toString()); // 'File content'
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
async function toBuffer(input) {
|
|
36
|
+
if (Buffer.isBuffer(input)) return input;
|
|
37
|
+
return Buffer.from(await input.arrayBuffer());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { toBuffer };
|
|
42
|
+
//# sourceMappingURL=buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\nimport type {\n Blob as NodeBlob,\n File as NodeFile,\n} from 'node:buffer';\n\n/**\n * Converts a Blob, Buffer, or File to a Buffer.\n *\n * This function provides a unified way to convert various binary data types\n * to Node.js Buffer. If the input is already a Buffer, it returns it as-is.\n * For Blob or File inputs, it converts them to Buffer via ArrayBuffer.\n *\n * @param {Blob | Buffer | File} input - The input to convert to Buffer\n *\n * @returns {Promise<Buffer>} A Promise that resolves to a Buffer\n *\n * @example\n * ```typescript\n * import { toBuffer } from '@kikiutils/shared/general';\n *\n * // Convert a Buffer (returns as-is)\n * const buffer = Buffer.from('Hello World');\n * const result1 = await toBuffer(buffer);\n * console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>\n *\n * // Convert a Blob\n * const blob = new Blob(['Hello from Blob'], { type: 'text/plain' });\n * const result2 = await toBuffer(blob);\n * console.log(result2.toString()); // 'Hello from Blob'\n *\n * // Convert a File\n * const file = new File(['File content'], 'test.txt', { type: 'text/plain' });\n * const result3 = await toBuffer(file);\n * console.log(result3.toString()); // 'File content'\n * ```\n */\nexport async function toBuffer(input: Blob | Buffer | File | NodeBlob | NodeFile) {\n if (Buffer.isBuffer(input)) return input;\n return Buffer.from(await input.arrayBuffer());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,eAAsB,SAAS,OAAmD;AAC9E,KAAI,OAAO,SAAS,MAAM,CAAE,QAAO;AACnC,QAAO,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC"}
|
package/dist/clipboard.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
//#region src/clipboard.d.ts
|
|
1
2
|
type CopyResult = {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
error: unknown;
|
|
4
|
+
ok: false;
|
|
4
5
|
} | {
|
|
5
|
-
|
|
6
|
+
ok: true;
|
|
6
7
|
};
|
|
7
8
|
/**
|
|
8
9
|
* Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.
|
|
@@ -32,7 +33,7 @@ type CopyResult = {
|
|
|
32
33
|
* }
|
|
33
34
|
* ```
|
|
34
35
|
*/
|
|
35
|
-
|
|
36
|
+
declare function copyBlobToClipboard(blob: Blob, options?: ClipboardItemOptions): Promise<CopyResult>;
|
|
36
37
|
/**
|
|
37
38
|
* Attempts to copy the given text to the user's clipboard using the modern Clipboard API.
|
|
38
39
|
*
|
|
@@ -59,6 +60,7 @@ export declare function copyBlobToClipboard(blob: Blob, options?: ClipboardItemO
|
|
|
59
60
|
* }
|
|
60
61
|
* ```
|
|
61
62
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
declare function copyTextToClipboard(text: string): Promise<CopyResult>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { copyBlobToClipboard, copyTextToClipboard };
|
|
64
66
|
//# sourceMappingURL=clipboard.d.ts.map
|
package/dist/clipboard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.d.ts","
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","names":[],"sources":["../src/clipboard.ts"],"sourcesContent":[],"mappings":";KAAK,UAAA;EAAA,KAAA,EAAA,OAAU;EAgCO,EAAA,EAAA,KAAA;CAAmB,GAAA;MAAO,IAAA;;;;;AA8ChD;;;;;;;;;;;;;;;;;;;;;;;;;iBA9CsB,mBAAA,OAA0B,gBAAgB,uBAAuB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8CzE,mBAAA,gBAAmC,QAAQ"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//#region src/clipboard.ts
|
|
2
|
+
/**
|
|
3
|
+
* Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ Usage Notes:
|
|
6
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
7
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
8
|
+
* - Not supported in Safari and some older browsers.
|
|
9
|
+
*
|
|
10
|
+
* @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content)
|
|
11
|
+
* @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor
|
|
12
|
+
*
|
|
13
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
14
|
+
* - `{ ok: true }` if the copy succeeded
|
|
15
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { copyBlobToClipboard } from '@kikiutils/shared/clipboard';
|
|
20
|
+
*
|
|
21
|
+
* const blob = new Blob(['Hello world'], { type: 'text/plain' });
|
|
22
|
+
* const result = await copyBlobToClipboard(blob);
|
|
23
|
+
* if (result.ok) {
|
|
24
|
+
* console.log('Copied blob!');
|
|
25
|
+
* } else {
|
|
26
|
+
* console.error('Copy failed:', result.error);
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
async function copyBlobToClipboard(blob, options) {
|
|
31
|
+
if (!navigator.clipboard?.write) return {
|
|
32
|
+
error: /* @__PURE__ */ new Error("Clipboard.write is not supported in this browser"),
|
|
33
|
+
ok: false
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
const item = new ClipboardItem({ [blob.type]: blob }, options);
|
|
37
|
+
await navigator.clipboard.write([item]);
|
|
38
|
+
return { ok: true };
|
|
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
|
+
* import { copyTextToClipboard } from '@kikiutils/shared/clipboard';
|
|
63
|
+
*
|
|
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
|
+
} catch (error) {
|
|
77
|
+
return {
|
|
78
|
+
error,
|
|
79
|
+
ok: false
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
export { copyBlobToClipboard, copyTextToClipboard };
|
|
86
|
+
//# sourceMappingURL=clipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.js","names":[],"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 * import { copyBlobToClipboard } from '@kikiutils/shared/clipboard';\n *\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 * import { copyTextToClipboard } from '@kikiutils/shared/clipboard';\n *\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAsB,oBAAoB,MAAY,SAAqD;AACvG,KAAI,CAAC,UAAU,WAAW,MACtB,QAAO;EACH,uBAAO,IAAI,MAAM,mDAAmD;EACpE,IAAI;EACP;AAGL,KAAI;EACA,MAAM,OAAO,IAAI,cAAc,GAAG,KAAK,OAAO,MAAM,EAAE,QAAQ;AAC9D,QAAM,UAAU,UAAU,MAAM,CAAC,KAAK,CAAC;AACvC,SAAO,EAAE,IAAI,MAAM;UACd,OAAO;AACZ,SAAO;GACH;GACA,IAAI;GACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BT,eAAsB,oBAAoB,MAAmC;AACzE,KAAI;AACA,QAAM,UAAU,UAAU,UAAU,KAAK;AACzC,SAAO,EAAE,IAAI,MAAM;UACd,OAAO;AACZ,SAAO;GACH;GACA,IAAI;GACP"}
|
package/dist/consola.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import * as consola0 from "consola";
|
|
2
|
+
|
|
3
|
+
//#region src/consola.d.ts
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* A consola logger instance.
|
|
3
7
|
*
|
|
@@ -19,6 +23,8 @@
|
|
|
19
23
|
* logger.level = 3;
|
|
20
24
|
* ```
|
|
21
25
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
declare const consolaLogger: consola0.ConsolaInstance;
|
|
27
|
+
declare const logger: consola0.ConsolaInstance;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { consolaLogger, logger };
|
|
24
30
|
//# sourceMappingURL=consola.d.ts.map
|
package/dist/consola.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consola.d.ts","
|
|
1
|
+
{"version":3,"file":"consola.d.ts","names":[],"sources":["../src/consola.ts"],"sourcesContent":[],"mappings":";;;;;;;AAuBA;AACA;;;;;;;;;;;;;;;;;cADa,eAA+B,QAAA,CAAlB;cACb,QAAsB,QAAA,CAAhB"}
|
package/dist/consola.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createConsola } from "consola";
|
|
2
|
+
|
|
3
|
+
//#region src/consola.ts
|
|
4
|
+
/**
|
|
5
|
+
* A consola logger instance.
|
|
6
|
+
*
|
|
7
|
+
* The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables.
|
|
8
|
+
* If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,
|
|
9
|
+
* the level will be set to `0`.
|
|
10
|
+
*
|
|
11
|
+
* To manually change the level, assign the desired level to `logger.level`.
|
|
12
|
+
*
|
|
13
|
+
* See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { logger } from '@kikiutils/shared/consola';
|
|
18
|
+
*
|
|
19
|
+
* logger.info('test'); // ℹ test 3:56:30 AM
|
|
20
|
+
*
|
|
21
|
+
* // Manually change the level
|
|
22
|
+
* logger.level = 3;
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const consolaLogger = createConsola();
|
|
26
|
+
const logger = consolaLogger;
|
|
27
|
+
if (process.env.CONSOLA_LOGGER_LEVEL !== void 0) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;
|
|
28
|
+
else consolaLogger.level = process.env.NODE_ENV === "production" ? 0 : consolaLogger.level;
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { consolaLogger, logger };
|
|
32
|
+
//# sourceMappingURL=consola.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consola.js","names":[],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB,eAAe;AAC5C,MAAa,SAAS;AACtB,IAAI,QAAQ,IAAI,yBAAyB,OAAW,eAAc,QAAQ,CAAC,QAAQ,IAAI;IAClF,eAAc,QAAQ,QAAQ,IAAI,aAAa,eAAe,IAAI,cAAc"}
|
package/dist/crypto-hash.d.ts
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export declare function cryptoMd5(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
18
|
-
export declare function cryptoMd5ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
19
|
-
export declare function cryptoSha3224(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
20
|
-
export declare function cryptoSha3224ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
21
|
-
export declare function cryptoSha3256(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
22
|
-
export declare function cryptoSha3256ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
23
|
-
export declare function cryptoSha3384(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
24
|
-
export declare function cryptoSha3384ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
25
|
-
export declare function cryptoSha3512(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
26
|
-
export declare function cryptoSha3512ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
1
|
+
import { BinaryLike, BinaryToTextEncoding } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
//#region src/crypto-hash.d.ts
|
|
4
|
+
|
|
5
|
+
declare function cryptoMd5(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
6
|
+
declare function cryptoMd5ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
7
|
+
declare function cryptoSha3224(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
8
|
+
declare function cryptoSha3224ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
9
|
+
declare function cryptoSha3256(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
10
|
+
declare function cryptoSha3256ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
11
|
+
declare function cryptoSha3384(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
12
|
+
declare function cryptoSha3384ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
13
|
+
declare function cryptoSha3512(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
14
|
+
declare function cryptoSha3512ToBuffer(data: BinaryLike): Buffer<ArrayBufferLike>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { cryptoMd5, cryptoMd5ToBuffer, cryptoSha3224, cryptoSha3224ToBuffer, cryptoSha3256, cryptoSha3256ToBuffer, cryptoSha3384, cryptoSha3384ToBuffer, cryptoSha3512, cryptoSha3512ToBuffer };
|
|
27
17
|
//# sourceMappingURL=crypto-hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.d.ts","
|
|
1
|
+
{"version":3,"file":"crypto-hash.d.ts","names":[],"sources":["../src/crypto-hash.ts"],"sourcesContent":[],"mappings":";;;;AA8BoC,iBARpB,SAAA,CAQoB,IAAA,EARJ,UAQI,EAAA,cAAA,CAAA,EARwB,oBAQxB,CAAA,EAAA,MAAA;AAA4B,iBAJhD,iBAAA,CAIgD,IAAA,EAJxB,UAIwB,CAAA,EAJd,MAIc,CAJd,eAIc,CAAA;AAA4B,iBAA5E,aAAA,CAA4E,IAAA,EAAxD,UAAwD,EAAA,cAAA,CAAA,EAA5B,oBAA4B,CAAA,EAAA,MAAA;AAI5E,iBAAA,qBAAA,CAAqB,IAAA,EAAO,UAAP,CAAA,EAAiB,MAAjB,CAAiB,eAAjB,CAAA;AAAA,iBAIrB,aAAA,CAJqB,IAAA,EAID,UAJC,EAAA,cAAA,CAAA,EAI2B,oBAJ3B,CAAA,EAAA,MAAA;AAAO,iBAQ5B,qBAAA,CAR4B,IAAA,EAQA,UARA,CAAA,EAQU,MARV,CAQU,eARV,CAAA;AAAU,iBAYtC,aAAA,CAZsC,IAAA,EAYlB,UAZkB,EAAA,cAAA,CAAA,EAYU,oBAZV,CAAA,EAAA,MAAA;AAAA,iBAgBtC,qBAAA,CAhBsC,IAAA,EAgBV,UAhBU,CAAA,EAgBA,MAhBA,CAgBA,eAhBA,CAAA;AAAA,iBAoBtC,aAAA,CApBsC,IAAA,EAoBlB,UApBkB,EAAA,cAAA,CAAA,EAoBU,oBApBV,CAAA,EAAA,MAAA;AAItC,iBAoBA,qBAAA,CApBa,IAAA,EAoBe,UApBf,CAAA,EAoByB,MApBzB,CAoByB,eApBzB,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
//#region src/crypto-hash.ts
|
|
4
|
+
function cryptoMd5(data, outputEncoding = "hex") {
|
|
5
|
+
return createHash("md5").update(data).digest(outputEncoding);
|
|
6
|
+
}
|
|
7
|
+
function cryptoMd5ToBuffer(data) {
|
|
8
|
+
return createHash("md5").update(data).digest();
|
|
9
|
+
}
|
|
10
|
+
function cryptoSha3224(data, outputEncoding = "hex") {
|
|
11
|
+
return createHash("sha3-224").update(data).digest(outputEncoding);
|
|
12
|
+
}
|
|
13
|
+
function cryptoSha3224ToBuffer(data) {
|
|
14
|
+
return createHash("sha3-224").update(data).digest();
|
|
15
|
+
}
|
|
16
|
+
function cryptoSha3256(data, outputEncoding = "hex") {
|
|
17
|
+
return createHash("sha3-256").update(data).digest(outputEncoding);
|
|
18
|
+
}
|
|
19
|
+
function cryptoSha3256ToBuffer(data) {
|
|
20
|
+
return createHash("sha3-256").update(data).digest();
|
|
21
|
+
}
|
|
22
|
+
function cryptoSha3384(data, outputEncoding = "hex") {
|
|
23
|
+
return createHash("sha3-384").update(data).digest(outputEncoding);
|
|
24
|
+
}
|
|
25
|
+
function cryptoSha3384ToBuffer(data) {
|
|
26
|
+
return createHash("sha3-384").update(data).digest();
|
|
27
|
+
}
|
|
28
|
+
function cryptoSha3512(data, outputEncoding = "hex") {
|
|
29
|
+
return createHash("sha3-512").update(data).digest(outputEncoding);
|
|
30
|
+
}
|
|
31
|
+
function cryptoSha3512ToBuffer(data) {
|
|
32
|
+
return createHash("sha3-512").update(data).digest();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { cryptoMd5, cryptoMd5ToBuffer, cryptoSha3224, cryptoSha3224ToBuffer, cryptoSha3256, cryptoSha3256ToBuffer, cryptoSha3384, cryptoSha3384ToBuffer, cryptoSha3512, cryptoSha3512ToBuffer };
|
|
37
|
+
//# sourceMappingURL=crypto-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-hash.js","names":[],"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"],"mappings":";;;AAsBA,SAAgB,UAAU,MAAkB,iBAAuC,OAAO;AACtF,QAAO,WAAW,MAAM,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;AAGhE,SAAgB,kBAAkB,MAAkB;AAChD,QAAO,WAAW,MAAM,CAAC,OAAO,KAAK,CAAC,QAAQ;;AAGlD,SAAgB,cAAc,MAAkB,iBAAuC,OAAO;AAC1F,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;AAGrE,SAAgB,sBAAsB,MAAkB;AACpD,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,QAAQ;;AAGvD,SAAgB,cAAc,MAAkB,iBAAuC,OAAO;AAC1F,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;AAGrE,SAAgB,sBAAsB,MAAkB;AACpD,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,QAAQ;;AAGvD,SAAgB,cAAc,MAAkB,iBAAuC,OAAO;AAC1F,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;AAGrE,SAAgB,sBAAsB,MAAkB;AACpD,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,QAAQ;;AAGvD,SAAgB,cAAc,MAAkB,iBAAuC,OAAO;AAC1F,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;AAGrE,SAAgB,sBAAsB,MAAkB;AACpD,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,QAAQ"}
|
package/dist/datetime.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { DateArg, Day, FormatOptions } from "date-fns";
|
|
2
|
+
|
|
3
|
+
//#region src/datetime.d.ts
|
|
4
|
+
type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';
|
|
3
5
|
/**
|
|
4
6
|
* Formats a given date, timestamp, or date string into a specified format.
|
|
5
7
|
*
|
|
@@ -27,7 +29,7 @@ export type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek'
|
|
|
27
29
|
*
|
|
28
30
|
* @see https://date-fns.org/docs/format
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
declare function formatDate(date: DateArg<Date> & {}, format?: string, options?: FormatOptions): string;
|
|
31
33
|
/**
|
|
32
34
|
* Get the date range (start and end) based on a given date and range type.
|
|
33
35
|
*
|
|
@@ -55,12 +57,12 @@ export declare function formatDate(date: DateArg<Date> & {}, format?: string, op
|
|
|
55
57
|
* // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }
|
|
56
58
|
* ```
|
|
57
59
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
declare function getDateRangeFromDate(date: Date, type: DateRangeType, options?: {
|
|
61
|
+
setEndDateToNextDayStart?: boolean;
|
|
62
|
+
weekStartsOn?: Day;
|
|
61
63
|
}): {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
endDate: Date;
|
|
65
|
+
startDate: Date;
|
|
64
66
|
};
|
|
65
67
|
/**
|
|
66
68
|
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
@@ -78,5 +80,7 @@ export declare function getDateRangeFromDate(date: Date, type: DateRangeType, op
|
|
|
78
80
|
* console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00
|
|
79
81
|
* ```
|
|
80
82
|
*/
|
|
81
|
-
|
|
83
|
+
declare function getMidnightDateFromToday(offsetDays?: number): Date;
|
|
84
|
+
//#endregion
|
|
85
|
+
export { DateRangeType, formatDate, getDateRangeFromDate, getMidnightDateFromToday };
|
|
82
86
|
//# sourceMappingURL=datetime.d.ts.map
|
package/dist/datetime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.d.ts","
|
|
1
|
+
{"version":3,"file":"datetime.d.ts","names":[],"sources":["../src/datetime.ts"],"sourcesContent":[],"mappings":";;;KAkBY,aAAA;;AAAZ;AA6BA;;;;;;AA+BA;;;;;;;;AAyEA;;;;;;;;;;;iBAxGgB,UAAA,OAAiB,QAAQ,uCAA8D;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+BvF,oBAAA,OACN,YACA;;iBAGa;;;;;;;;;;;;;;;;;;;;;iBAoEP,wBAAA,uBAA+C"}
|
package/dist/datetime.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { endOfDay, endOfMonth, endOfWeek, format, startOfDay, startOfMonth, startOfWeek, subDays, subMonths, subWeeks } from "date-fns";
|
|
2
|
+
|
|
3
|
+
//#region src/datetime.ts
|
|
4
|
+
/**
|
|
5
|
+
* Formats a given date, timestamp, or date string into a specified format.
|
|
6
|
+
*
|
|
7
|
+
* This function is a wrapper around `date-fns/format`.
|
|
8
|
+
*
|
|
9
|
+
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
|
|
10
|
+
* @param {string} [format] - The target format string
|
|
11
|
+
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`
|
|
12
|
+
*
|
|
13
|
+
* @returns {string} The formatted date string
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { formatDate } from '@kikiutils/shared/datetime';
|
|
18
|
+
*
|
|
19
|
+
* // Format a Date object
|
|
20
|
+
* console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10
|
|
21
|
+
*
|
|
22
|
+
* // Format a timestamp
|
|
23
|
+
* console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15
|
|
24
|
+
*
|
|
25
|
+
* // Format a date string
|
|
26
|
+
* console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see https://date-fns.org/docs/format
|
|
30
|
+
*/
|
|
31
|
+
function formatDate(date, format$1 = "yyyy-MM-dd HH:mm:ss", options) {
|
|
32
|
+
return format(date, format$1, options);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the date range (start and end) based on a given date and range type.
|
|
36
|
+
*
|
|
37
|
+
* Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
|
|
38
|
+
*
|
|
39
|
+
* @param {Date} date - The reference date
|
|
40
|
+
* @param {DateRangeType} type - The range type to compute
|
|
41
|
+
* @param {object} [options] - Optional settings
|
|
42
|
+
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
|
|
43
|
+
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
44
|
+
*
|
|
45
|
+
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
|
|
50
|
+
*
|
|
51
|
+
* // Get the date range for last month
|
|
52
|
+
* const date = new Date('2023-07-01');
|
|
53
|
+
* console.log(getDateRangeFromDate(date, 'lastMonth'));
|
|
54
|
+
* // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }
|
|
55
|
+
*
|
|
56
|
+
* // Get this week's range with Sunday as the first day
|
|
57
|
+
* console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));
|
|
58
|
+
* // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function getDateRangeFromDate(date, type, options) {
|
|
62
|
+
let endDate;
|
|
63
|
+
let startDate;
|
|
64
|
+
switch (type) {
|
|
65
|
+
case "lastMonth":
|
|
66
|
+
{
|
|
67
|
+
const lastMonth = subMonths(date, 1);
|
|
68
|
+
endDate = endOfMonth(lastMonth);
|
|
69
|
+
startDate = startOfMonth(lastMonth);
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
case "lastWeek":
|
|
73
|
+
{
|
|
74
|
+
const lastWeek = subWeeks(date, 1);
|
|
75
|
+
endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
76
|
+
startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "thisMonth":
|
|
80
|
+
endDate = endOfMonth(date);
|
|
81
|
+
startDate = startOfMonth(date);
|
|
82
|
+
break;
|
|
83
|
+
case "thisWeek":
|
|
84
|
+
endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
85
|
+
startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
86
|
+
break;
|
|
87
|
+
case "today":
|
|
88
|
+
endDate = endOfDay(date);
|
|
89
|
+
startDate = startOfDay(date);
|
|
90
|
+
break;
|
|
91
|
+
case "yesterday":
|
|
92
|
+
{
|
|
93
|
+
const yesterday = subDays(date, 1);
|
|
94
|
+
endDate = endOfDay(yesterday);
|
|
95
|
+
startDate = startOfDay(yesterday);
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
default: throw new Error(`Unsupported date range type: ${type}`);
|
|
99
|
+
}
|
|
100
|
+
if (options?.setEndDateToNextDayStart) endDate.setHours(24, 0, 0, 0);
|
|
101
|
+
return {
|
|
102
|
+
endDate,
|
|
103
|
+
startDate
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
108
|
+
*
|
|
109
|
+
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative
|
|
110
|
+
*
|
|
111
|
+
* @returns {Date} A `Date` object at 00:00:00 of the offset day
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';
|
|
116
|
+
*
|
|
117
|
+
* console.log(getMidnightDateFromToday()); // today at 00:00:00
|
|
118
|
+
* console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00
|
|
119
|
+
* console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
function getMidnightDateFromToday(offsetDays = 0) {
|
|
123
|
+
const date = /* @__PURE__ */ new Date();
|
|
124
|
+
date.setDate(date.getDate() + offsetDays);
|
|
125
|
+
date.setHours(0, 0, 0, 0);
|
|
126
|
+
return date;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
export { formatDate, getDateRangeFromDate, getMidnightDateFromToday };
|
|
131
|
+
//# sourceMappingURL=datetime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datetime.js","names":["dateFnsFormat","format","endDate: Date","startDate: Date"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,WAAW,MAA0B,WAAiB,uBAAuB,SAAyB;AAClH,QAAOA,OAAc,MAAMC,UAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B/C,SAAgB,qBACZ,MACA,MACA,SAIF;CACE,IAAIC;CACJ,IAAIC;AACJ,SAAQ,MAAR;EACI,KAAK;GACD;IACI,MAAM,YAAY,UAAU,MAAM,EAAE;AACpC,cAAU,WAAW,UAAU;AAC/B,gBAAY,aAAa,UAAU;;AAGvC;EACJ,KAAK;GACD;IACI,MAAM,WAAW,SAAS,MAAM,EAAE;AAClC,cAAU,UAAU,UAAU,EAAE,cAAc,SAAS,gBAAgB,GAAG,CAAC;AAC3E,gBAAY,YAAY,UAAU,EAAE,cAAc,SAAS,gBAAgB,GAAG,CAAC;;AAGnF;EACJ,KAAK;AACD,aAAU,WAAW,KAAK;AAC1B,eAAY,aAAa,KAAK;AAC9B;EACJ,KAAK;AACD,aAAU,UAAU,MAAM,EAAE,cAAc,SAAS,gBAAgB,GAAG,CAAC;AACvE,eAAY,YAAY,MAAM,EAAE,cAAc,SAAS,gBAAgB,GAAG,CAAC;AAC3E;EACJ,KAAK;AACD,aAAU,SAAS,KAAK;AACxB,eAAY,WAAW,KAAK;AAC5B;EACJ,KAAK;GACD;IACI,MAAM,YAAY,QAAQ,MAAM,EAAE;AAClC,cAAU,SAAS,UAAU;AAC7B,gBAAY,WAAW,UAAU;;AAGrC;EACJ,QAAS,OAAM,IAAI,MAAM,gCAAgC,OAAO;;AAGpE,KAAI,SAAS,yBAA0B,SAAQ,SAAS,IAAI,GAAG,GAAG,EAAE;AACpE,QAAO;EACH;EACA;EACH;;;;;;;;;;;;;;;;;;AAmBL,SAAgB,yBAAyB,aAAqB,GAAG;CAC7D,MAAM,uBAAO,IAAI,MAAM;AACvB,MAAK,QAAQ,KAAK,SAAS,GAAG,WAAW;AACzC,MAAK,SAAS,GAAG,GAAG,GAAG,EAAE;AACzB,QAAO"}
|
package/dist/element-plus.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { RuleType } from "async-validator";
|
|
2
|
+
import { FormItemRule } from "element-plus";
|
|
3
|
+
|
|
4
|
+
//#region src/element-plus.d.ts
|
|
5
|
+
type DoNotRemoveOrUseThisType = RuleType;
|
|
4
6
|
/**
|
|
5
7
|
* Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.
|
|
6
8
|
*
|
|
@@ -24,5 +26,7 @@ export type DoNotRemoveOrUseThisType = RuleType;
|
|
|
24
26
|
* const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });
|
|
25
27
|
* ```
|
|
26
28
|
*/
|
|
27
|
-
|
|
29
|
+
declare function createElFormItemRuleWithDefaults(message: string, options?: FormItemRule): FormItemRule;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { DoNotRemoveOrUseThisType, createElFormItemRuleWithDefaults };
|
|
28
32
|
//# sourceMappingURL=element-plus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-plus.d.ts","
|
|
1
|
+
{"version":3,"file":"element-plus.d.ts","names":[],"sources":["../src/element-plus.ts"],"sourcesContent":[],"mappings":";;;;KAGY,wBAAA,GAA2B;;AAAvC;AAyBA;;;;;;;;;;;;;;;;;;;;;iBAAgB,gCAAA,4BAA2D,eAAoB"}
|