@kikiutils/shared 10.3.0 → 10.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buffer.cjs +43 -0
- package/dist/buffer.cjs.map +1 -0
- package/dist/buffer.d.ts +35 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.mjs +41 -0
- package/dist/buffer.mjs.map +1 -0
- package/dist/clipboard.cjs +4 -4
- package/dist/clipboard.cjs.map +1 -1
- package/dist/clipboard.d.ts +3 -3
- package/dist/clipboard.mjs +4 -4
- package/dist/clipboard.mjs.map +1 -1
- package/dist/datetime.cjs +13 -13
- package/dist/datetime.cjs.map +1 -1
- package/dist/datetime.d.ts +12 -12
- package/dist/datetime.mjs +13 -13
- package/dist/datetime.mjs.map +1 -1
- package/dist/element-plus.cjs +6 -6
- package/dist/element-plus.cjs.map +1 -1
- package/dist/element-plus.d.ts +6 -6
- package/dist/element-plus.mjs +6 -6
- package/dist/element-plus.mjs.map +1 -1
- package/dist/enum.cjs +12 -12
- package/dist/enum.cjs.map +1 -1
- package/dist/enum.d.ts +12 -12
- package/dist/enum.mjs +12 -12
- package/dist/enum.mjs.map +1 -1
- package/dist/env.cjs +4 -4
- package/dist/env.cjs.map +1 -1
- package/dist/env.d.ts +4 -4
- package/dist/env.mjs +4 -4
- package/dist/env.mjs.map +1 -1
- package/dist/general.cjs.map +1 -1
- package/dist/general.d.ts +5 -5
- package/dist/general.mjs.map +1 -1
- package/dist/math.cjs +4 -4
- package/dist/math.cjs.map +1 -1
- package/dist/math.d.ts +4 -4
- package/dist/math.mjs +4 -4
- package/dist/math.mjs.map +1 -1
- package/dist/number.cjs +3 -3
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.ts +3 -3
- package/dist/number.mjs +3 -3
- package/dist/number.mjs.map +1 -1
- package/dist/object.cjs +4 -4
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.ts +4 -4
- package/dist/object.mjs +4 -4
- package/dist/object.mjs.map +1 -1
- package/dist/random.cjs +7 -7
- package/dist/random.cjs.map +1 -1
- package/dist/random.d.ts +7 -7
- package/dist/random.mjs +7 -7
- package/dist/random.mjs.map +1 -1
- package/dist/storage/enhanced/local/core.cjs +11 -11
- package/dist/storage/enhanced/local/core.cjs.map +1 -1
- package/dist/storage/enhanced/local/core.d.ts +9 -9
- package/dist/storage/enhanced/local/core.mjs +11 -11
- package/dist/storage/enhanced/local/core.mjs.map +1 -1
- package/dist/storage/enhanced/local/keyed-store.cjs +3 -3
- package/dist/storage/enhanced/local/keyed-store.cjs.map +1 -1
- package/dist/storage/enhanced/local/keyed-store.d.ts +3 -3
- package/dist/storage/enhanced/local/keyed-store.mjs +3 -3
- package/dist/storage/enhanced/local/keyed-store.mjs.map +1 -1
- package/dist/storage/enhanced/redis/core.cjs +18 -18
- package/dist/storage/enhanced/redis/core.cjs.map +1 -1
- package/dist/storage/enhanced/redis/core.d.ts +16 -16
- package/dist/storage/enhanced/redis/core.mjs +18 -18
- package/dist/storage/enhanced/redis/core.mjs.map +1 -1
- package/dist/storage/enhanced/redis/keyed-store.cjs +4 -4
- package/dist/storage/enhanced/redis/keyed-store.cjs.map +1 -1
- package/dist/storage/enhanced/redis/keyed-store.d.ts +4 -4
- package/dist/storage/enhanced/redis/keyed-store.mjs +4 -4
- package/dist/storage/enhanced/redis/keyed-store.mjs.map +1 -1
- package/dist/storage/lru/keyed-store.cjs +3 -3
- package/dist/storage/lru/keyed-store.cjs.map +1 -1
- package/dist/storage/lru/keyed-store.d.ts +3 -3
- package/dist/storage/lru/keyed-store.mjs +3 -3
- package/dist/storage/lru/keyed-store.mjs.map +1 -1
- package/dist/string.cjs +5 -5
- package/dist/string.cjs.map +1 -1
- package/dist/string.d.ts +4 -4
- package/dist/string.mjs +5 -5
- package/dist/string.mjs.map +1 -1
- package/dist/url.cjs +3 -3
- package/dist/url.cjs.map +1 -1
- package/dist/url.d.ts +3 -3
- package/dist/url.mjs +3 -3
- package/dist/url.mjs.map +1 -1
- package/dist/vue.cjs +6 -6
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.d.ts +6 -6
- package/dist/vue.mjs +6 -6
- package/dist/vue.mjs.map +1 -1
- package/dist/web.cjs +4 -4
- package/dist/web.cjs.map +1 -1
- package/dist/web.d.ts +4 -4
- package/dist/web.mjs +4 -4
- package/dist/web.mjs.map +1 -1
- package/package.json +2 -2
- package/src/buffer.ts +41 -0
- package/src/clipboard.ts +4 -4
- package/src/datetime.ts +13 -13
- package/src/element-plus.ts +6 -6
- package/src/enum.ts +12 -12
- package/src/env.ts +4 -4
- package/src/general.ts +5 -5
- package/src/math.ts +4 -4
- package/src/number.ts +3 -3
- package/src/object.ts +4 -4
- package/src/random.ts +7 -7
- package/src/storage/enhanced/local/core.ts +11 -11
- package/src/storage/enhanced/local/keyed-store.ts +3 -3
- package/src/storage/enhanced/redis/core.ts +18 -18
- package/src/storage/enhanced/redis/keyed-store.ts +4 -4
- package/src/storage/lru/keyed-store.ts +3 -3
- package/src/string.ts +5 -5
- package/src/url.ts +3 -3
- package/src/vue.ts +6 -6
- package/src/web.ts +4 -4
package/dist/buffer.cjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_buffer = require('node:buffer');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a Blob, Buffer, or File to a Buffer.
|
|
7
|
+
*
|
|
8
|
+
* This function provides a unified way to convert various binary data types
|
|
9
|
+
* to Node.js Buffer. If the input is already a Buffer, it returns it as-is.
|
|
10
|
+
* For Blob or File inputs, it converts them to Buffer via ArrayBuffer.
|
|
11
|
+
*
|
|
12
|
+
* @param {Blob | Buffer | File} input - The input to convert to Buffer
|
|
13
|
+
*
|
|
14
|
+
* @returns {Promise<Buffer>} A Promise that resolves to a Buffer
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { toBuffer } from '@kikiutils/shared/general';
|
|
19
|
+
*
|
|
20
|
+
* // Convert a Buffer (returns as-is)
|
|
21
|
+
* const buffer = Buffer.from('Hello World');
|
|
22
|
+
* const result1 = await toBuffer(buffer);
|
|
23
|
+
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
24
|
+
*
|
|
25
|
+
* // Convert a Blob
|
|
26
|
+
* const blob = new Blob(['Hello from Blob'], { type: 'text/plain' });
|
|
27
|
+
* const result2 = await toBuffer(blob);
|
|
28
|
+
* console.log(result2.toString()); // 'Hello from Blob'
|
|
29
|
+
*
|
|
30
|
+
* // Convert a File
|
|
31
|
+
* const file = new File(['File content'], 'test.txt', { type: 'text/plain' });
|
|
32
|
+
* const result3 = await toBuffer(file);
|
|
33
|
+
* console.log(result3.toString()); // 'File content'
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
async function toBuffer(input) {
|
|
37
|
+
if (node_buffer.Buffer.isBuffer(input))
|
|
38
|
+
return input;
|
|
39
|
+
return node_buffer.Buffer.from(await input.arrayBuffer());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.toBuffer = toBuffer;
|
|
43
|
+
//# sourceMappingURL=buffer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.cjs","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"],"names":["Buffer"],"mappings":";;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;AACI,eAAe,QAAQ,CAAC,KAAiD,EAAA;AAC5E,IAAA,IAAIA,kBAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,KAAK;IACxC,OAAOA,kBAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;AACjD;;;;"}
|
package/dist/buffer.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import type { Blob as NodeBlob, File as NodeFile } from 'node:buffer';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a Blob, Buffer, or File to a Buffer.
|
|
5
|
+
*
|
|
6
|
+
* This function provides a unified way to convert various binary data types
|
|
7
|
+
* to Node.js Buffer. If the input is already a Buffer, it returns it as-is.
|
|
8
|
+
* For Blob or File inputs, it converts them to Buffer via ArrayBuffer.
|
|
9
|
+
*
|
|
10
|
+
* @param {Blob | Buffer | File} input - The input to convert to Buffer
|
|
11
|
+
*
|
|
12
|
+
* @returns {Promise<Buffer>} A Promise that resolves to a Buffer
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { toBuffer } from '@kikiutils/shared/general';
|
|
17
|
+
*
|
|
18
|
+
* // Convert a Buffer (returns as-is)
|
|
19
|
+
* const buffer = Buffer.from('Hello World');
|
|
20
|
+
* const result1 = await toBuffer(buffer);
|
|
21
|
+
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
22
|
+
*
|
|
23
|
+
* // Convert a Blob
|
|
24
|
+
* const blob = new Blob(['Hello from Blob'], { type: 'text/plain' });
|
|
25
|
+
* const result2 = await toBuffer(blob);
|
|
26
|
+
* console.log(result2.toString()); // 'Hello from Blob'
|
|
27
|
+
*
|
|
28
|
+
* // Convert a File
|
|
29
|
+
* const file = new File(['File content'], 'test.txt', { type: 'text/plain' });
|
|
30
|
+
* const result3 = await toBuffer(file);
|
|
31
|
+
* console.log(result3.toString()); // 'File content'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function toBuffer(input: Blob | Buffer | File | NodeBlob | NodeFile): Promise<Buffer<ArrayBufferLike>>;
|
|
35
|
+
//# sourceMappingURL=buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EACR,IAAI,IAAI,QAAQ,EAChB,IAAI,IAAI,QAAQ,EACnB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,QAAQ,oCAG/E"}
|
package/dist/buffer.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts a Blob, Buffer, or File to a Buffer.
|
|
5
|
+
*
|
|
6
|
+
* This function provides a unified way to convert various binary data types
|
|
7
|
+
* to Node.js Buffer. If the input is already a Buffer, it returns it as-is.
|
|
8
|
+
* For Blob or File inputs, it converts them to Buffer via ArrayBuffer.
|
|
9
|
+
*
|
|
10
|
+
* @param {Blob | Buffer | File} input - The input to convert to Buffer
|
|
11
|
+
*
|
|
12
|
+
* @returns {Promise<Buffer>} A Promise that resolves to a Buffer
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { toBuffer } from '@kikiutils/shared/general';
|
|
17
|
+
*
|
|
18
|
+
* // Convert a Buffer (returns as-is)
|
|
19
|
+
* const buffer = Buffer.from('Hello World');
|
|
20
|
+
* const result1 = await toBuffer(buffer);
|
|
21
|
+
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
22
|
+
*
|
|
23
|
+
* // Convert a Blob
|
|
24
|
+
* const blob = new Blob(['Hello from Blob'], { type: 'text/plain' });
|
|
25
|
+
* const result2 = await toBuffer(blob);
|
|
26
|
+
* console.log(result2.toString()); // 'Hello from Blob'
|
|
27
|
+
*
|
|
28
|
+
* // Convert a File
|
|
29
|
+
* const file = new File(['File content'], 'test.txt', { type: 'text/plain' });
|
|
30
|
+
* const result3 = await toBuffer(file);
|
|
31
|
+
* console.log(result3.toString()); // 'File content'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
async function toBuffer(input) {
|
|
35
|
+
if (Buffer.isBuffer(input))
|
|
36
|
+
return input;
|
|
37
|
+
return Buffer.from(await input.arrayBuffer());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { toBuffer };
|
|
41
|
+
//# sourceMappingURL=buffer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.mjs","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"],"names":[],"mappings":";;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;AACI,eAAe,QAAQ,CAAC,KAAiD,EAAA;AAC5E,IAAA,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,KAAK;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;AACjD;;;;"}
|
package/dist/clipboard.cjs
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
9
9
|
* - Not supported in Safari and some older browsers.
|
|
10
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
|
|
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
13
|
*
|
|
14
14
|
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
15
15
|
* - `{ ok: true }` if the copy succeeded
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
async function copyBlobToClipboard(blob, options) {
|
|
32
32
|
if (!navigator.clipboard?.write) {
|
|
33
33
|
return {
|
|
34
|
-
error: new Error('Clipboard.write is not supported in this browser
|
|
34
|
+
error: new Error('Clipboard.write is not supported in this browser'),
|
|
35
35
|
ok: false,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
@@ -55,7 +55,7 @@ async function copyBlobToClipboard(blob, options) {
|
|
|
55
55
|
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
56
56
|
* - Not supported in some older browsers (especially legacy Safari).
|
|
57
57
|
*
|
|
58
|
-
* @param {string} text - The string to be copied to the clipboard
|
|
58
|
+
* @param {string} text - The string to be copied to the clipboard
|
|
59
59
|
*
|
|
60
60
|
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
61
61
|
* - `{ ok: true }` if the copy succeeded
|
package/dist/clipboard.cjs.map
CHANGED
|
@@ -1 +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)
|
|
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 * 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"],"names":[],"mappings":";;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;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,kDAAkD,CAAC;AACpE,YAAA,EAAE,EAAE,KAAK;SACZ;IACL;AAEA,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;IACvB;IAAE,OAAO,KAAK,EAAE;QACZ,OAAO;YACH,KAAK;AACL,YAAA,EAAE,EAAE,KAAK;SACZ;IACL;AACJ;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;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;IACvB;IAAE,OAAO,KAAK,EAAE;QACZ,OAAO;YACH,KAAK;AACL,YAAA,EAAE,EAAE,KAAK;SACZ;IACL;AACJ;;;;;"}
|
package/dist/clipboard.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ type CopyResult = {
|
|
|
12
12
|
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
13
13
|
* - Not supported in Safari and some older browsers.
|
|
14
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
|
|
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
17
|
*
|
|
18
18
|
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
19
19
|
* - `{ ok: true }` if the copy succeeded
|
|
@@ -41,7 +41,7 @@ export declare function copyBlobToClipboard(blob: Blob, options?: ClipboardItemO
|
|
|
41
41
|
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
42
42
|
* - Not supported in some older browsers (especially legacy Safari).
|
|
43
43
|
*
|
|
44
|
-
* @param {string} text - The string to be copied to the clipboard
|
|
44
|
+
* @param {string} text - The string to be copied to the clipboard
|
|
45
45
|
*
|
|
46
46
|
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
47
47
|
* - `{ ok: true }` if the copy succeeded
|
package/dist/clipboard.mjs
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
7
7
|
* - Not supported in Safari and some older browsers.
|
|
8
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
|
|
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
11
|
*
|
|
12
12
|
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
13
13
|
* - `{ ok: true }` if the copy succeeded
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
async function copyBlobToClipboard(blob, options) {
|
|
30
30
|
if (!navigator.clipboard?.write) {
|
|
31
31
|
return {
|
|
32
|
-
error: new Error('Clipboard.write is not supported in this browser
|
|
32
|
+
error: new Error('Clipboard.write is not supported in this browser'),
|
|
33
33
|
ok: false,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
@@ -53,7 +53,7 @@ async function copyBlobToClipboard(blob, options) {
|
|
|
53
53
|
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
54
54
|
* - Not supported in some older browsers (especially legacy Safari).
|
|
55
55
|
*
|
|
56
|
-
* @param {string} text - The string to be copied to the clipboard
|
|
56
|
+
* @param {string} text - The string to be copied to the clipboard
|
|
57
57
|
*
|
|
58
58
|
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
59
59
|
* - `{ ok: true }` if the copy succeeded
|
package/dist/clipboard.mjs.map
CHANGED
|
@@ -1 +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)
|
|
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 * 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"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;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,kDAAkD,CAAC;AACpE,YAAA,EAAE,EAAE,KAAK;SACZ;IACL;AAEA,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;IACvB;IAAE,OAAO,KAAK,EAAE;QACZ,OAAO;YACH,KAAK;AACL,YAAA,EAAE,EAAE,KAAK;SACZ;IACL;AACJ;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;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;IACvB;IAAE,OAAO,KAAK,EAAE;QACZ,OAAO;YACH,KAAK;AACL,YAAA,EAAE,EAAE,KAAK;SACZ;IACL;AACJ;;;;"}
|
package/dist/datetime.cjs
CHANGED
|
@@ -7,11 +7,11 @@ const dateFns = require('date-fns');
|
|
|
7
7
|
*
|
|
8
8
|
* This function is a wrapper around `date-fns/format`.
|
|
9
9
|
*
|
|
10
|
-
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
|
|
11
|
-
* @param {string} [format] - The target format string
|
|
12
|
-
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format
|
|
10
|
+
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
|
|
11
|
+
* @param {string} [format] - The target format string
|
|
12
|
+
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`
|
|
13
13
|
*
|
|
14
|
-
* @returns {string} The formatted date string
|
|
14
|
+
* @returns {string} The formatted date string
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
@@ -37,13 +37,13 @@ function formatDate(date, format = 'yyyy-MM-dd HH:mm:ss', options) {
|
|
|
37
37
|
*
|
|
38
38
|
* Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
|
|
39
39
|
*
|
|
40
|
-
* @param {Date} date - The reference date
|
|
41
|
-
* @param {DateRangeType} type - The range type to compute
|
|
42
|
-
* @param {object} [options] - Optional settings
|
|
43
|
-
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
|
|
44
|
-
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
40
|
+
* @param {Date} date - The reference date
|
|
41
|
+
* @param {DateRangeType} type - The range type to compute
|
|
42
|
+
* @param {object} [options] - Optional settings
|
|
43
|
+
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
|
|
44
|
+
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
45
45
|
*
|
|
46
|
-
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate
|
|
46
|
+
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
49
|
* ```typescript
|
|
@@ -96,7 +96,7 @@ function getDateRangeFromDate(date, type, options) {
|
|
|
96
96
|
startDate = dateFns.startOfDay(yesterday);
|
|
97
97
|
}
|
|
98
98
|
break;
|
|
99
|
-
default: throw new Error(`Unsupported date range type: ${type}
|
|
99
|
+
default: throw new Error(`Unsupported date range type: ${type}`);
|
|
100
100
|
}
|
|
101
101
|
if (options?.setEndDateToNextDayStart)
|
|
102
102
|
endDate.setHours(24, 0, 0, 0);
|
|
@@ -108,9 +108,9 @@ function getDateRangeFromDate(date, type, options) {
|
|
|
108
108
|
/**
|
|
109
109
|
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
110
110
|
*
|
|
111
|
-
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative
|
|
111
|
+
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative
|
|
112
112
|
*
|
|
113
|
-
* @returns {Date} A `Date` object at 00:00:00 of the offset day
|
|
113
|
+
* @returns {Date} A `Date` object at 00:00:00 of the offset day
|
|
114
114
|
*
|
|
115
115
|
* @example
|
|
116
116
|
* ```typescript
|
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
|
|
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,MAAA,GAAiB,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;YACvC;YAEA;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;YACnF;YAEA;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;YACrC;YAEA;QACJ,SAAS,MAAM,IAAI,KAAK,CAAC,CAAA,6BAAA,EAAgC,IAAI,CAAA,CAAE,CAAC;;IAGpE,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;AACG,SAAU,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
|
@@ -5,11 +5,11 @@ export type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek'
|
|
|
5
5
|
*
|
|
6
6
|
* This function is a wrapper around `date-fns/format`.
|
|
7
7
|
*
|
|
8
|
-
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
|
|
9
|
-
* @param {string} [format] - The target format string
|
|
10
|
-
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format
|
|
8
|
+
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
|
|
9
|
+
* @param {string} [format] - The target format string
|
|
10
|
+
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`
|
|
11
11
|
*
|
|
12
|
-
* @returns {string} The formatted date string
|
|
12
|
+
* @returns {string} The formatted date string
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
@@ -33,13 +33,13 @@ export declare function formatDate(date: DateArg<Date> & {}, format?: string, op
|
|
|
33
33
|
*
|
|
34
34
|
* Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
|
|
35
35
|
*
|
|
36
|
-
* @param {Date} date - The reference date
|
|
37
|
-
* @param {DateRangeType} type - The range type to compute
|
|
38
|
-
* @param {object} [options] - Optional settings
|
|
39
|
-
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
|
|
40
|
-
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
36
|
+
* @param {Date} date - The reference date
|
|
37
|
+
* @param {DateRangeType} type - The range type to compute
|
|
38
|
+
* @param {object} [options] - Optional settings
|
|
39
|
+
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
|
|
40
|
+
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
41
41
|
*
|
|
42
|
-
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate
|
|
42
|
+
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
|
|
43
43
|
*
|
|
44
44
|
* @example
|
|
45
45
|
* ```typescript
|
|
@@ -65,9 +65,9 @@ export declare function getDateRangeFromDate(date: Date, type: DateRangeType, op
|
|
|
65
65
|
/**
|
|
66
66
|
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
67
67
|
*
|
|
68
|
-
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative
|
|
68
|
+
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative
|
|
69
69
|
*
|
|
70
|
-
* @returns {Date} A `Date` object at 00:00:00 of the offset day
|
|
70
|
+
* @returns {Date} A `Date` object at 00:00:00 of the offset day
|
|
71
71
|
*
|
|
72
72
|
* @example
|
|
73
73
|
* ```typescript
|
package/dist/datetime.mjs
CHANGED
|
@@ -5,11 +5,11 @@ import { format, subDays, endOfDay, startOfDay, endOfWeek, startOfWeek, endOfMon
|
|
|
5
5
|
*
|
|
6
6
|
* This function is a wrapper around `date-fns/format`.
|
|
7
7
|
*
|
|
8
|
-
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
|
|
9
|
-
* @param {string} [format] - The target format string
|
|
10
|
-
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format
|
|
8
|
+
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
|
|
9
|
+
* @param {string} [format] - The target format string
|
|
10
|
+
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`
|
|
11
11
|
*
|
|
12
|
-
* @returns {string} The formatted date string
|
|
12
|
+
* @returns {string} The formatted date string
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
@@ -35,13 +35,13 @@ function formatDate(date, format$1 = 'yyyy-MM-dd HH:mm:ss', options) {
|
|
|
35
35
|
*
|
|
36
36
|
* Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
|
|
37
37
|
*
|
|
38
|
-
* @param {Date} date - The reference date
|
|
39
|
-
* @param {DateRangeType} type - The range type to compute
|
|
40
|
-
* @param {object} [options] - Optional settings
|
|
41
|
-
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
|
|
42
|
-
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
38
|
+
* @param {Date} date - The reference date
|
|
39
|
+
* @param {DateRangeType} type - The range type to compute
|
|
40
|
+
* @param {object} [options] - Optional settings
|
|
41
|
+
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
|
|
42
|
+
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
43
43
|
*
|
|
44
|
-
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate
|
|
44
|
+
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
|
|
45
45
|
*
|
|
46
46
|
* @example
|
|
47
47
|
* ```typescript
|
|
@@ -94,7 +94,7 @@ function getDateRangeFromDate(date, type, options) {
|
|
|
94
94
|
startDate = startOfDay(yesterday);
|
|
95
95
|
}
|
|
96
96
|
break;
|
|
97
|
-
default: throw new Error(`Unsupported date range type: ${type}
|
|
97
|
+
default: throw new Error(`Unsupported date range type: ${type}`);
|
|
98
98
|
}
|
|
99
99
|
if (options?.setEndDateToNextDayStart)
|
|
100
100
|
endDate.setHours(24, 0, 0, 0);
|
|
@@ -106,9 +106,9 @@ function getDateRangeFromDate(date, type, options) {
|
|
|
106
106
|
/**
|
|
107
107
|
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
108
108
|
*
|
|
109
|
-
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative
|
|
109
|
+
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative
|
|
110
110
|
*
|
|
111
|
-
* @returns {Date} A `Date` object at 00:00:00 of the offset day
|
|
111
|
+
* @returns {Date} A `Date` object at 00:00:00 of the offset day
|
|
112
112
|
*
|
|
113
113
|
* @example
|
|
114
114
|
* ```typescript
|
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
|
|
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,QAAA,GAAiB,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;YACvC;YAEA;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;YACnF;YAEA;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;YACrC;YAEA;QACJ,SAAS,MAAM,IAAI,KAAK,CAAC,CAAA,6BAAA,EAAgC,IAAI,CAAA,CAAE,CAAC;;IAGpE,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;AACG,SAAU,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/element-plus.cjs
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* while allowing overrides via the `options` parameter. It simplifies common
|
|
8
8
|
* form validation rule creation and ensures consistency across forms.
|
|
9
9
|
*
|
|
10
|
-
* @param {string} message - The validation message to display when the rule fails
|
|
11
|
-
* @param {FormItemRule} [options] - Optional overrides for the rule fields
|
|
12
|
-
* @param {boolean} [options.required] - Whether the field is required (default: `true`)
|
|
13
|
-
* @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
|
|
14
|
-
* @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
|
|
10
|
+
* @param {string} message - The validation message to display when the rule fails
|
|
11
|
+
* @param {FormItemRule} [options] - Optional overrides for the rule fields
|
|
12
|
+
* @param {boolean} [options.required] - Whether the field is required (default: `true`)
|
|
13
|
+
* @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
|
|
14
|
+
* @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
|
|
15
15
|
*
|
|
16
|
-
* @returns A `FormItemRule` object that can be used in Element Plus form validation
|
|
16
|
+
* @returns A `FormItemRule` object that can be used in Element Plus form validation
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-plus.cjs","sources":["../src/element-plus.ts"],"sourcesContent":["import type { RuleType } from 'async-validator';\nimport type { FormItemRule } from 'element-plus';\n\nexport type DoNotRemoveOrUseThisType = RuleType;\n\n/**\n * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.\n *\n * This utility provides default values for `required`, `trigger`, and `type`,\n * while allowing overrides via the `options` parameter. It simplifies common\n * form validation rule creation and ensures consistency across forms.\n *\n * @param {string} message - The validation message to display when the rule fails
|
|
1
|
+
{"version":3,"file":"element-plus.cjs","sources":["../src/element-plus.ts"],"sourcesContent":["import type { RuleType } from 'async-validator';\nimport type { FormItemRule } from 'element-plus';\n\nexport type DoNotRemoveOrUseThisType = RuleType;\n\n/**\n * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.\n *\n * This utility provides default values for `required`, `trigger`, and `type`,\n * while allowing overrides via the `options` parameter. It simplifies common\n * form validation rule creation and ensures consistency across forms.\n *\n * @param {string} message - The validation message to display when the rule fails\n * @param {FormItemRule} [options] - Optional overrides for the rule fields\n * @param {boolean} [options.required] - Whether the field is required (default: `true`)\n * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)\n * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)\n *\n * @returns A `FormItemRule` object that can be used in Element Plus form validation\n *\n * @example\n * ```typescript\n * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';\n *\n * const rule = createElFormItemRuleWithDefaults('This field is required');\n * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });\n * ```\n */\nexport function createElFormItemRuleWithDefaults(message: string, options: FormItemRule = {}): FormItemRule {\n return {\n ...options,\n message,\n required: options.required ?? true,\n trigger: options.trigger ?? 'blur',\n type: options.type ?? 'string',\n };\n}\n"],"names":[],"mappings":";;AAKA;;;;;;;;;;;;;;;;;;;;;;AAsBG;SACa,gCAAgC,CAAC,OAAe,EAAE,UAAwB,EAAE,EAAA;IACxF,OAAO;AACH,QAAA,GAAG,OAAO;QACV,OAAO;AACP,QAAA,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;AAClC,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM;AAClC,QAAA,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,QAAQ;KACjC;AACL;;;;"}
|
package/dist/element-plus.d.ts
CHANGED
|
@@ -8,13 +8,13 @@ export type DoNotRemoveOrUseThisType = RuleType;
|
|
|
8
8
|
* while allowing overrides via the `options` parameter. It simplifies common
|
|
9
9
|
* form validation rule creation and ensures consistency across forms.
|
|
10
10
|
*
|
|
11
|
-
* @param {string} message - The validation message to display when the rule fails
|
|
12
|
-
* @param {FormItemRule} [options] - Optional overrides for the rule fields
|
|
13
|
-
* @param {boolean} [options.required] - Whether the field is required (default: `true`)
|
|
14
|
-
* @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
|
|
15
|
-
* @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
|
|
11
|
+
* @param {string} message - The validation message to display when the rule fails
|
|
12
|
+
* @param {FormItemRule} [options] - Optional overrides for the rule fields
|
|
13
|
+
* @param {boolean} [options.required] - Whether the field is required (default: `true`)
|
|
14
|
+
* @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
|
|
15
|
+
* @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
|
|
16
16
|
*
|
|
17
|
-
* @returns A `FormItemRule` object that can be used in Element Plus form validation
|
|
17
|
+
* @returns A `FormItemRule` object that can be used in Element Plus form validation
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```typescript
|
package/dist/element-plus.mjs
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* while allowing overrides via the `options` parameter. It simplifies common
|
|
6
6
|
* form validation rule creation and ensures consistency across forms.
|
|
7
7
|
*
|
|
8
|
-
* @param {string} message - The validation message to display when the rule fails
|
|
9
|
-
* @param {FormItemRule} [options] - Optional overrides for the rule fields
|
|
10
|
-
* @param {boolean} [options.required] - Whether the field is required (default: `true`)
|
|
11
|
-
* @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
|
|
12
|
-
* @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
|
|
8
|
+
* @param {string} message - The validation message to display when the rule fails
|
|
9
|
+
* @param {FormItemRule} [options] - Optional overrides for the rule fields
|
|
10
|
+
* @param {boolean} [options.required] - Whether the field is required (default: `true`)
|
|
11
|
+
* @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
|
|
12
|
+
* @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
|
|
13
13
|
*
|
|
14
|
-
* @returns A `FormItemRule` object that can be used in Element Plus form validation
|
|
14
|
+
* @returns A `FormItemRule` object that can be used in Element Plus form validation
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-plus.mjs","sources":["../src/element-plus.ts"],"sourcesContent":["import type { RuleType } from 'async-validator';\nimport type { FormItemRule } from 'element-plus';\n\nexport type DoNotRemoveOrUseThisType = RuleType;\n\n/**\n * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.\n *\n * This utility provides default values for `required`, `trigger`, and `type`,\n * while allowing overrides via the `options` parameter. It simplifies common\n * form validation rule creation and ensures consistency across forms.\n *\n * @param {string} message - The validation message to display when the rule fails
|
|
1
|
+
{"version":3,"file":"element-plus.mjs","sources":["../src/element-plus.ts"],"sourcesContent":["import type { RuleType } from 'async-validator';\nimport type { FormItemRule } from 'element-plus';\n\nexport type DoNotRemoveOrUseThisType = RuleType;\n\n/**\n * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.\n *\n * This utility provides default values for `required`, `trigger`, and `type`,\n * while allowing overrides via the `options` parameter. It simplifies common\n * form validation rule creation and ensures consistency across forms.\n *\n * @param {string} message - The validation message to display when the rule fails\n * @param {FormItemRule} [options] - Optional overrides for the rule fields\n * @param {boolean} [options.required] - Whether the field is required (default: `true`)\n * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)\n * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)\n *\n * @returns A `FormItemRule` object that can be used in Element Plus form validation\n *\n * @example\n * ```typescript\n * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';\n *\n * const rule = createElFormItemRuleWithDefaults('This field is required');\n * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });\n * ```\n */\nexport function createElFormItemRuleWithDefaults(message: string, options: FormItemRule = {}): FormItemRule {\n return {\n ...options,\n message,\n required: options.required ?? true,\n trigger: options.trigger ?? 'blur',\n type: options.type ?? 'string',\n };\n}\n"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;AAsBG;SACa,gCAAgC,CAAC,OAAe,EAAE,UAAwB,EAAE,EAAA;IACxF,OAAO;AACH,QAAA,GAAG,OAAO;QACV,OAAO;AACP,QAAA,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;AAClC,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM;AAClC,QAAA,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,QAAQ;KACjC;AACL;;;;"}
|