@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/dist/crypto-hash.cjs
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_crypto = require('node:crypto');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This file provides a set of functions for creating hash digests using different algorithms and bit lengths.
|
|
7
|
-
* It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,
|
|
8
|
-
* as well as a function for generating MD5 hash digests.
|
|
9
|
-
*
|
|
10
|
-
* These functions use the Node.js crypto module to generate the hashes.
|
|
11
|
-
* Can only be used in Node.js/Deno/Bun runtimes.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';
|
|
16
|
-
*
|
|
17
|
-
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
function cryptoMd5(data, outputEncoding = 'hex') {
|
|
21
|
-
return node_crypto.createHash('md5').update(data).digest(outputEncoding);
|
|
22
|
-
}
|
|
23
|
-
function cryptoMd5ToBuffer(data) {
|
|
24
|
-
return node_crypto.createHash('md5').update(data).digest();
|
|
25
|
-
}
|
|
26
|
-
function cryptoSha3224(data, outputEncoding = 'hex') {
|
|
27
|
-
return node_crypto.createHash('sha3-224').update(data).digest(outputEncoding);
|
|
28
|
-
}
|
|
29
|
-
function cryptoSha3224ToBuffer(data) {
|
|
30
|
-
return node_crypto.createHash('sha3-224').update(data).digest();
|
|
31
|
-
}
|
|
32
|
-
function cryptoSha3256(data, outputEncoding = 'hex') {
|
|
33
|
-
return node_crypto.createHash('sha3-256').update(data).digest(outputEncoding);
|
|
34
|
-
}
|
|
35
|
-
function cryptoSha3256ToBuffer(data) {
|
|
36
|
-
return node_crypto.createHash('sha3-256').update(data).digest();
|
|
37
|
-
}
|
|
38
|
-
function cryptoSha3384(data, outputEncoding = 'hex') {
|
|
39
|
-
return node_crypto.createHash('sha3-384').update(data).digest(outputEncoding);
|
|
40
|
-
}
|
|
41
|
-
function cryptoSha3384ToBuffer(data) {
|
|
42
|
-
return node_crypto.createHash('sha3-384').update(data).digest();
|
|
43
|
-
}
|
|
44
|
-
function cryptoSha3512(data, outputEncoding = 'hex') {
|
|
45
|
-
return node_crypto.createHash('sha3-512').update(data).digest(outputEncoding);
|
|
46
|
-
}
|
|
47
|
-
function cryptoSha3512ToBuffer(data) {
|
|
48
|
-
return node_crypto.createHash('sha3-512').update(data).digest();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
exports.cryptoMd5 = cryptoMd5;
|
|
52
|
-
exports.cryptoMd5ToBuffer = cryptoMd5ToBuffer;
|
|
53
|
-
exports.cryptoSha3224 = cryptoSha3224;
|
|
54
|
-
exports.cryptoSha3224ToBuffer = cryptoSha3224ToBuffer;
|
|
55
|
-
exports.cryptoSha3256 = cryptoSha3256;
|
|
56
|
-
exports.cryptoSha3256ToBuffer = cryptoSha3256ToBuffer;
|
|
57
|
-
exports.cryptoSha3384 = cryptoSha3384;
|
|
58
|
-
exports.cryptoSha3384ToBuffer = cryptoSha3384ToBuffer;
|
|
59
|
-
exports.cryptoSha3512 = cryptoSha3512;
|
|
60
|
-
exports.cryptoSha3512ToBuffer = cryptoSha3512ToBuffer;
|
|
61
|
-
//# sourceMappingURL=crypto-hash.cjs.map
|
package/dist/crypto-hash.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.cjs","sources":["../src/crypto-hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating hash digests using different algorithms and bit lengths.\n * It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,\n * as well as a function for generating MD5 hash digests.\n *\n * These functions use the Node.js crypto module to generate the hashes.\n * Can only be used in Node.js/Deno/Bun runtimes.\n *\n * @example\n * ```typescript\n * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\n\nimport { createHash } from 'node:crypto';\nimport type {\n BinaryLike,\n BinaryToTextEncoding,\n} from 'node:crypto';\n\nexport function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('md5').update(data).digest(outputEncoding);\n}\n\nexport function cryptoMd5ToBuffer(data: BinaryLike) {\n return createHash('md5').update(data).digest();\n}\n\nexport function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-224').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3224ToBuffer(data: BinaryLike) {\n return createHash('sha3-224').update(data).digest();\n}\n\nexport function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-256').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3256ToBuffer(data: BinaryLike) {\n return createHash('sha3-256').update(data).digest();\n}\n\nexport function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-384').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3384ToBuffer(data: BinaryLike) {\n return createHash('sha3-384').update(data).digest();\n}\n\nexport function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-512').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3512ToBuffer(data: BinaryLike) {\n return createHash('sha3-512').update(data).digest();\n}\n"],"names":["createHash"],"mappings":";;;;AAAA;;;;;;;;;;;;;;AAcG;SAQa,SAAS,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACpF,IAAA,OAAOA,sBAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AAChE;AAEM,SAAU,iBAAiB,CAAC,IAAgB,EAAA;AAC9C,IAAA,OAAOA,sBAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AAClD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAOA,sBAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;;;;;;;;;;;;;"}
|
package/dist/crypto-hash.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This file provides a set of functions for creating hash digests using different algorithms and bit lengths.
|
|
5
|
-
* It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,
|
|
6
|
-
* as well as a function for generating MD5 hash digests.
|
|
7
|
-
*
|
|
8
|
-
* These functions use the Node.js crypto module to generate the hashes.
|
|
9
|
-
* Can only be used in Node.js/Deno/Bun runtimes.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';
|
|
14
|
-
*
|
|
15
|
-
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
function cryptoMd5(data, outputEncoding = 'hex') {
|
|
19
|
-
return createHash('md5').update(data).digest(outputEncoding);
|
|
20
|
-
}
|
|
21
|
-
function cryptoMd5ToBuffer(data) {
|
|
22
|
-
return createHash('md5').update(data).digest();
|
|
23
|
-
}
|
|
24
|
-
function cryptoSha3224(data, outputEncoding = 'hex') {
|
|
25
|
-
return createHash('sha3-224').update(data).digest(outputEncoding);
|
|
26
|
-
}
|
|
27
|
-
function cryptoSha3224ToBuffer(data) {
|
|
28
|
-
return createHash('sha3-224').update(data).digest();
|
|
29
|
-
}
|
|
30
|
-
function cryptoSha3256(data, outputEncoding = 'hex') {
|
|
31
|
-
return createHash('sha3-256').update(data).digest(outputEncoding);
|
|
32
|
-
}
|
|
33
|
-
function cryptoSha3256ToBuffer(data) {
|
|
34
|
-
return createHash('sha3-256').update(data).digest();
|
|
35
|
-
}
|
|
36
|
-
function cryptoSha3384(data, outputEncoding = 'hex') {
|
|
37
|
-
return createHash('sha3-384').update(data).digest(outputEncoding);
|
|
38
|
-
}
|
|
39
|
-
function cryptoSha3384ToBuffer(data) {
|
|
40
|
-
return createHash('sha3-384').update(data).digest();
|
|
41
|
-
}
|
|
42
|
-
function cryptoSha3512(data, outputEncoding = 'hex') {
|
|
43
|
-
return createHash('sha3-512').update(data).digest(outputEncoding);
|
|
44
|
-
}
|
|
45
|
-
function cryptoSha3512ToBuffer(data) {
|
|
46
|
-
return createHash('sha3-512').update(data).digest();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { cryptoMd5, cryptoMd5ToBuffer, cryptoSha3224, cryptoSha3224ToBuffer, cryptoSha3256, cryptoSha3256ToBuffer, cryptoSha3384, cryptoSha3384ToBuffer, cryptoSha3512, cryptoSha3512ToBuffer };
|
|
50
|
-
//# sourceMappingURL=crypto-hash.mjs.map
|
package/dist/crypto-hash.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.mjs","sources":["../src/crypto-hash.ts"],"sourcesContent":["/**\n * This file provides a set of functions for creating hash digests using different algorithms and bit lengths.\n * It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,\n * as well as a function for generating MD5 hash digests.\n *\n * These functions use the Node.js crypto module to generate the hashes.\n * Can only be used in Node.js/Deno/Bun runtimes.\n *\n * @example\n * ```typescript\n * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\n\nimport { createHash } from 'node:crypto';\nimport type {\n BinaryLike,\n BinaryToTextEncoding,\n} from 'node:crypto';\n\nexport function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('md5').update(data).digest(outputEncoding);\n}\n\nexport function cryptoMd5ToBuffer(data: BinaryLike) {\n return createHash('md5').update(data).digest();\n}\n\nexport function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-224').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3224ToBuffer(data: BinaryLike) {\n return createHash('sha3-224').update(data).digest();\n}\n\nexport function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-256').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3256ToBuffer(data: BinaryLike) {\n return createHash('sha3-256').update(data).digest();\n}\n\nexport function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-384').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3384ToBuffer(data: BinaryLike) {\n return createHash('sha3-384').update(data).digest();\n}\n\nexport function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-512').update(data).digest(outputEncoding);\n}\n\nexport function cryptoSha3512ToBuffer(data: BinaryLike) {\n return createHash('sha3-512').update(data).digest();\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;AAcG;SAQa,SAAS,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACpF,IAAA,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AAChE;AAEM,SAAU,iBAAiB,CAAC,IAAgB,EAAA;AAC9C,IAAA,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AAClD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;SAEgB,aAAa,CAAC,IAAgB,EAAE,iBAAuC,KAAK,EAAA;AACxF,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;AACrE;AAEM,SAAU,qBAAqB,CAAC,IAAgB,EAAA;AAClD,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;AACvD;;;;"}
|
package/dist/datetime.cjs
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const dateFns = require('date-fns');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Formats a given date, timestamp, or date string into a specified format.
|
|
7
|
-
*
|
|
8
|
-
* This function is a wrapper around `date-fns/format`.
|
|
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`
|
|
13
|
-
*
|
|
14
|
-
* @returns {string} The formatted date string
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { formatDate } from '@kikiutils/shared/datetime';
|
|
19
|
-
*
|
|
20
|
-
* // Format a Date object
|
|
21
|
-
* console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10
|
|
22
|
-
*
|
|
23
|
-
* // Format a timestamp
|
|
24
|
-
* console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15
|
|
25
|
-
*
|
|
26
|
-
* // Format a date string
|
|
27
|
-
* console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @see https://date-fns.org/docs/format
|
|
31
|
-
*/
|
|
32
|
-
function formatDate(date, format = 'yyyy-MM-dd HH:mm:ss', options) {
|
|
33
|
-
return dateFns.format(date, format, options);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Get the date range (start and end) based on a given date and range type.
|
|
37
|
-
*
|
|
38
|
-
* Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
|
|
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)
|
|
45
|
-
*
|
|
46
|
-
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
|
|
51
|
-
*
|
|
52
|
-
* // Get the date range for last month
|
|
53
|
-
* const date = new Date('2023-07-01');
|
|
54
|
-
* console.log(getDateRangeFromDate(date, 'lastMonth'));
|
|
55
|
-
* // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }
|
|
56
|
-
*
|
|
57
|
-
* // Get this week's range with Sunday as the first day
|
|
58
|
-
* console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));
|
|
59
|
-
* // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
function getDateRangeFromDate(date, type, options) {
|
|
63
|
-
let endDate;
|
|
64
|
-
let startDate;
|
|
65
|
-
switch (type) {
|
|
66
|
-
case 'lastMonth':
|
|
67
|
-
{
|
|
68
|
-
const lastMonth = dateFns.subMonths(date, 1);
|
|
69
|
-
endDate = dateFns.endOfMonth(lastMonth);
|
|
70
|
-
startDate = dateFns.startOfMonth(lastMonth);
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
case 'lastWeek':
|
|
74
|
-
{
|
|
75
|
-
const lastWeek = dateFns.subWeeks(date, 1);
|
|
76
|
-
endDate = dateFns.endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
77
|
-
startDate = dateFns.startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
case 'thisMonth':
|
|
81
|
-
endDate = dateFns.endOfMonth(date);
|
|
82
|
-
startDate = dateFns.startOfMonth(date);
|
|
83
|
-
break;
|
|
84
|
-
case 'thisWeek':
|
|
85
|
-
endDate = dateFns.endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
86
|
-
startDate = dateFns.startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
87
|
-
break;
|
|
88
|
-
case 'today':
|
|
89
|
-
endDate = dateFns.endOfDay(date);
|
|
90
|
-
startDate = dateFns.startOfDay(date);
|
|
91
|
-
break;
|
|
92
|
-
case 'yesterday':
|
|
93
|
-
{
|
|
94
|
-
const yesterday = dateFns.subDays(date, 1);
|
|
95
|
-
endDate = dateFns.endOfDay(yesterday);
|
|
96
|
-
startDate = dateFns.startOfDay(yesterday);
|
|
97
|
-
}
|
|
98
|
-
break;
|
|
99
|
-
default: throw new Error(`Unsupported date range type: ${type}`);
|
|
100
|
-
}
|
|
101
|
-
if (options?.setEndDateToNextDayStart)
|
|
102
|
-
endDate.setHours(24, 0, 0, 0);
|
|
103
|
-
return {
|
|
104
|
-
endDate,
|
|
105
|
-
startDate,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
110
|
-
*
|
|
111
|
-
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative
|
|
112
|
-
*
|
|
113
|
-
* @returns {Date} A `Date` object at 00:00:00 of the offset day
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```typescript
|
|
117
|
-
* import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';
|
|
118
|
-
*
|
|
119
|
-
* console.log(getMidnightDateFromToday()); // today at 00:00:00
|
|
120
|
-
* console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00
|
|
121
|
-
* console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
function getMidnightDateFromToday(offsetDays = 0) {
|
|
125
|
-
const date = new Date();
|
|
126
|
-
date.setDate(date.getDate() + offsetDays);
|
|
127
|
-
date.setHours(0, 0, 0, 0);
|
|
128
|
-
return date;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
exports.formatDate = formatDate;
|
|
132
|
-
exports.getDateRangeFromDate = getDateRangeFromDate;
|
|
133
|
-
exports.getMidnightDateFromToday = getMidnightDateFromToday;
|
|
134
|
-
//# sourceMappingURL=datetime.cjs.map
|
package/dist/datetime.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { format, subDays, endOfDay, startOfDay, endOfWeek, startOfWeek, endOfMonth, startOfMonth, subWeeks, subMonths } from 'date-fns';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Formats a given date, timestamp, or date string into a specified format.
|
|
5
|
-
*
|
|
6
|
-
* This function is a wrapper around `date-fns/format`.
|
|
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`
|
|
11
|
-
*
|
|
12
|
-
* @returns {string} The formatted date string
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { formatDate } from '@kikiutils/shared/datetime';
|
|
17
|
-
*
|
|
18
|
-
* // Format a Date object
|
|
19
|
-
* console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10
|
|
20
|
-
*
|
|
21
|
-
* // Format a timestamp
|
|
22
|
-
* console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15
|
|
23
|
-
*
|
|
24
|
-
* // Format a date string
|
|
25
|
-
* console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @see https://date-fns.org/docs/format
|
|
29
|
-
*/
|
|
30
|
-
function formatDate(date, format$1 = 'yyyy-MM-dd HH:mm:ss', options) {
|
|
31
|
-
return format(date, format$1, options);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Get the date range (start and end) based on a given date and range type.
|
|
35
|
-
*
|
|
36
|
-
* Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
|
|
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)
|
|
43
|
-
*
|
|
44
|
-
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
|
|
49
|
-
*
|
|
50
|
-
* // Get the date range for last month
|
|
51
|
-
* const date = new Date('2023-07-01');
|
|
52
|
-
* console.log(getDateRangeFromDate(date, 'lastMonth'));
|
|
53
|
-
* // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }
|
|
54
|
-
*
|
|
55
|
-
* // Get this week's range with Sunday as the first day
|
|
56
|
-
* console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));
|
|
57
|
-
* // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
function getDateRangeFromDate(date, type, options) {
|
|
61
|
-
let endDate;
|
|
62
|
-
let startDate;
|
|
63
|
-
switch (type) {
|
|
64
|
-
case 'lastMonth':
|
|
65
|
-
{
|
|
66
|
-
const lastMonth = subMonths(date, 1);
|
|
67
|
-
endDate = endOfMonth(lastMonth);
|
|
68
|
-
startDate = startOfMonth(lastMonth);
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
case 'lastWeek':
|
|
72
|
-
{
|
|
73
|
-
const lastWeek = subWeeks(date, 1);
|
|
74
|
-
endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
75
|
-
startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
case 'thisMonth':
|
|
79
|
-
endDate = endOfMonth(date);
|
|
80
|
-
startDate = startOfMonth(date);
|
|
81
|
-
break;
|
|
82
|
-
case 'thisWeek':
|
|
83
|
-
endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
84
|
-
startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
|
|
85
|
-
break;
|
|
86
|
-
case 'today':
|
|
87
|
-
endDate = endOfDay(date);
|
|
88
|
-
startDate = startOfDay(date);
|
|
89
|
-
break;
|
|
90
|
-
case 'yesterday':
|
|
91
|
-
{
|
|
92
|
-
const yesterday = subDays(date, 1);
|
|
93
|
-
endDate = endOfDay(yesterday);
|
|
94
|
-
startDate = startOfDay(yesterday);
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
|
-
default: throw new Error(`Unsupported date range type: ${type}`);
|
|
98
|
-
}
|
|
99
|
-
if (options?.setEndDateToNextDayStart)
|
|
100
|
-
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 = new Date();
|
|
124
|
-
date.setDate(date.getDate() + offsetDays);
|
|
125
|
-
date.setHours(0, 0, 0, 0);
|
|
126
|
-
return date;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export { formatDate, getDateRangeFromDate, getMidnightDateFromToday };
|
|
130
|
-
//# sourceMappingURL=datetime.mjs.map
|
package/dist/datetime.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.
|
|
5
|
-
*
|
|
6
|
-
* This utility provides default values for `required`, `trigger`, and `type`,
|
|
7
|
-
* while allowing overrides via the `options` parameter. It simplifies common
|
|
8
|
-
* form validation rule creation and ensures consistency across forms.
|
|
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'`)
|
|
15
|
-
*
|
|
16
|
-
* @returns A `FormItemRule` object that can be used in Element Plus form validation
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';
|
|
21
|
-
*
|
|
22
|
-
* const rule = createElFormItemRuleWithDefaults('This field is required');
|
|
23
|
-
* const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
function createElFormItemRuleWithDefaults(message, options = {}) {
|
|
27
|
-
return {
|
|
28
|
-
...options,
|
|
29
|
-
message,
|
|
30
|
-
required: options.required ?? true,
|
|
31
|
-
trigger: options.trigger ?? 'blur',
|
|
32
|
-
type: options.type ?? 'string',
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
exports.createElFormItemRuleWithDefaults = createElFormItemRuleWithDefaults;
|
|
37
|
-
//# sourceMappingURL=element-plus.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.
|
|
3
|
-
*
|
|
4
|
-
* This utility provides default values for `required`, `trigger`, and `type`,
|
|
5
|
-
* while allowing overrides via the `options` parameter. It simplifies common
|
|
6
|
-
* form validation rule creation and ensures consistency across forms.
|
|
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'`)
|
|
13
|
-
*
|
|
14
|
-
* @returns A `FormItemRule` object that can be used in Element Plus form validation
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';
|
|
19
|
-
*
|
|
20
|
-
* const rule = createElFormItemRuleWithDefaults('This field is required');
|
|
21
|
-
* const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
function createElFormItemRuleWithDefaults(message, options = {}) {
|
|
25
|
-
return {
|
|
26
|
-
...options,
|
|
27
|
-
message,
|
|
28
|
-
required: options.required ?? true,
|
|
29
|
-
trigger: options.trigger ?? 'blur',
|
|
30
|
-
type: options.type ?? 'string',
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { createElFormItemRuleWithDefaults };
|
|
35
|
-
//# sourceMappingURL=element-plus.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;"}
|
package/dist/enum.cjs
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Extracts only the numeric values from an enumeration-like object.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the enum object
|
|
7
|
-
*
|
|
8
|
-
* @param {T} enumObject - The enumeration-like object to extract numeric values from,
|
|
9
|
-
* the object can contain numeric values, string values, or both.
|
|
10
|
-
*
|
|
11
|
-
* @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { getEnumNumberValues } from '@kikiutils/shared/enum';
|
|
16
|
-
*
|
|
17
|
-
* enum RecordType {
|
|
18
|
-
* Receive = 0,
|
|
19
|
-
* Send = 1,
|
|
20
|
-
* Unknown = 'unknown'
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* console.log(getEnumNumberValues(RecordType)); // [0, 1]
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
function getEnumNumberValues(enumObject) {
|
|
27
|
-
return getEnumValues(enumObject).filter((value) => typeof value === 'number');
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Extracts only the string values from an enumeration-like object.
|
|
31
|
-
*
|
|
32
|
-
* @template T - The type of the enum object
|
|
33
|
-
*
|
|
34
|
-
* @param {T} enumObject - The enumeration-like object to extract string values from,
|
|
35
|
-
* the object can contain numeric values, string values, or both.
|
|
36
|
-
*
|
|
37
|
-
* @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* import { getEnumStringValues } from '@kikiutils/shared/enum';
|
|
42
|
-
*
|
|
43
|
-
* enum RecordType {
|
|
44
|
-
* Receive = 0,
|
|
45
|
-
* Send = 1,
|
|
46
|
-
* Unknown = 'unknown'
|
|
47
|
-
* }
|
|
48
|
-
*
|
|
49
|
-
* console.log(getEnumStringValues(RecordType)); // ['unknown']
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
function getEnumStringValues(enumObject) {
|
|
53
|
-
return getEnumValues(enumObject).filter((value) => typeof value === 'string');
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Extracts all values from an enumeration-like object.
|
|
57
|
-
*
|
|
58
|
-
* This function handles TypeScript enums correctly by accounting for the reverse mapping
|
|
59
|
-
* that occurs with numeric enums. It works with pure numeric enums, pure string enums,
|
|
60
|
-
* and mixed enums.
|
|
61
|
-
*
|
|
62
|
-
* @template T - The type of the enum object
|
|
63
|
-
*
|
|
64
|
-
* @param {T} enumObject - The enumeration-like object to extract values from,
|
|
65
|
-
* the object can contain numeric values, string values, or both.
|
|
66
|
-
*
|
|
67
|
-
* @returns {(T[keyof T])[]} An array containing all the values from the enum object
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* import { getEnumValues } from '@kikiutils/shared/enum';
|
|
72
|
-
*
|
|
73
|
-
* // Numeric enum
|
|
74
|
-
* enum Status {
|
|
75
|
-
* Active = 0,
|
|
76
|
-
* Inactive = 1,
|
|
77
|
-
* Pending = 2
|
|
78
|
-
* }
|
|
79
|
-
*
|
|
80
|
-
* console.log(getEnumValues(Status)); // [0, 1, 2]
|
|
81
|
-
*
|
|
82
|
-
* // String enum
|
|
83
|
-
* enum Color {
|
|
84
|
-
* Red = 'RED',
|
|
85
|
-
* Green = 'GREEN',
|
|
86
|
-
* Blue = 'BLUE'
|
|
87
|
-
* }
|
|
88
|
-
*
|
|
89
|
-
* console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']
|
|
90
|
-
*
|
|
91
|
-
* // Mixed enum
|
|
92
|
-
* enum RecordType {
|
|
93
|
-
* Receive = 0,
|
|
94
|
-
* Send = 1,
|
|
95
|
-
* Unknown = 'unknown'
|
|
96
|
-
* }
|
|
97
|
-
*
|
|
98
|
-
* console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
function getEnumValues(enumObject) {
|
|
102
|
-
const values = Object.values(enumObject);
|
|
103
|
-
const hasNumberValues = values.some((value) => typeof value === 'number');
|
|
104
|
-
if (!hasNumberValues)
|
|
105
|
-
return values;
|
|
106
|
-
return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
exports.getEnumNumberValues = getEnumNumberValues;
|
|
110
|
-
exports.getEnumStringValues = getEnumStringValues;
|
|
111
|
-
exports.getEnumValues = getEnumValues;
|
|
112
|
-
//# sourceMappingURL=enum.cjs.map
|
package/dist/enum.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum.cjs","sources":["../src/enum.ts"],"sourcesContent":["/**\n * Extracts only the numeric values from an enumeration-like object.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract numeric values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumNumberValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumNumberValues(RecordType)); // [0, 1]\n * ```\n */\nexport function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'number');\n}\n\n/**\n * Extracts only the string values from an enumeration-like object.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract string values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumStringValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumStringValues(RecordType)); // ['unknown']\n * ```\n */\nexport function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'string');\n}\n\n/**\n * Extracts all values from an enumeration-like object.\n *\n * This function handles TypeScript enums correctly by accounting for the reverse mapping\n * that occurs with numeric enums. It works with pure numeric enums, pure string enums,\n * and mixed enums.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {(T[keyof T])[]} An array containing all the values from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumValues } from '@kikiutils/shared/enum';\n *\n * // Numeric enum\n * enum Status {\n * Active = 0,\n * Inactive = 1,\n * Pending = 2\n * }\n *\n * console.log(getEnumValues(Status)); // [0, 1, 2]\n *\n * // String enum\n * enum Color {\n * Red = 'RED',\n * Green = 'GREEN',\n * Blue = 'BLUE'\n * }\n *\n * console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']\n *\n * // Mixed enum\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']\n * ```\n */\nexport function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[] {\n const values = Object.values(enumObject);\n const hasNumberValues = values.some((value) => typeof value === 'number');\n if (!hasNumberValues) return values;\n return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,mBAAmB,CAAgC,UAAa,EAAA;AAC5E,IAAA,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACjF;AAEA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,mBAAmB,CAAgC,UAAa,EAAA;AAC5E,IAAA,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACjF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CG;AACG,SAAU,aAAa,CAAgC,UAAa,EAAA;IACtE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;AACxC,IAAA,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACzE,IAAA,IAAI,CAAC,eAAe;AAAE,QAAA,OAAO,MAAM;AACnC,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG,CAAC,CAAC;AAC3G;;;;;;"}
|