@kikiutils/shared 15.0.1 → 15.0.3
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 +46 -119
- package/dist/crypto-hash.d.ts +145 -0
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +137 -7
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.d.ts +0 -2
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +0 -2
- package/dist/datetime.js.map +1 -1
- package/dist/enum.js.map +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +2 -0
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.js +1 -1
- package/dist/event-awaiter.js.map +1 -1
- package/dist/hash.d.ts +48 -5
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +49 -6
- package/dist/hash.js.map +1 -1
- package/dist/math.js +1 -1
- package/dist/math.js.map +1 -1
- package/dist/object.d.ts +4 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +4 -0
- package/dist/object.js.map +1 -1
- package/dist/pino.js.map +1 -1
- package/dist/random.js +2 -0
- package/dist/random.js.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +22 -0
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js +30 -0
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +25 -0
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.js +25 -0
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.d.ts +20 -0
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js +20 -0
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/storages/redis/types.d.ts +42 -0
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/time.d.ts +17 -0
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +17 -0
- package/dist/time.js.map +1 -1
- package/dist/url.d.ts +3 -0
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +8 -2
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +6 -0
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +6 -0
- package/dist/vue.js.map +1 -1
- package/dist/web.js.map +1 -1
- package/package.json +11 -11
- package/src/crypto-hash.ts +143 -14
- package/src/datetime.ts +0 -2
- package/src/env.ts +2 -0
- package/src/event-awaiter.ts +1 -1
- package/src/hash.ts +56 -14
- package/src/math.ts +2 -1
- package/src/object.ts +4 -0
- package/src/random.ts +3 -0
- package/src/storages/lru/keyed-store.ts +22 -0
- package/src/storages/redis/keyed-store.ts +25 -0
- package/src/storages/redis/msgpack.ts +20 -0
- package/src/storages/redis/types.ts +52 -0
- package/src/time.ts +17 -0
- package/src/url.ts +13 -2
- package/src/vue.ts +6 -0
package/README.md
CHANGED
|
@@ -9,8 +9,6 @@ A lightweight and modular utility library for modern JavaScript and TypeScript
|
|
|
9
9
|
|
|
10
10
|
- [✨ Release Notes](./CHANGELOG.md)
|
|
11
11
|
|
|
12
|
-
TODO: update README
|
|
13
|
-
|
|
14
12
|
## Features
|
|
15
13
|
|
|
16
14
|
- 📋 Clipboard utilities — copy text and blobs using the modern Clipboard API (Browser only)
|
|
@@ -47,17 +45,58 @@ You can also use `yarn`, `npm`, or `bun`.
|
|
|
47
45
|
>
|
|
48
46
|
> If a utility depends on a third-party package (e.g. `date-fns`), you must install it manually.
|
|
49
47
|
|
|
50
|
-
##
|
|
48
|
+
## Modules
|
|
51
49
|
|
|
52
|
-
|
|
50
|
+
```
|
|
51
|
+
src/
|
|
52
|
+
├── classes/ # Class-based utilities
|
|
53
|
+
│ ├── path.ts # Path manipulation
|
|
54
|
+
│ ├── precision-number.ts # Decimal.js wrapper
|
|
55
|
+
│ └── ssh-client.ts # SSH client
|
|
56
|
+
│
|
|
57
|
+
├── storages/
|
|
58
|
+
│ ├── lru/keyed-store.ts # LRU cache wrapper
|
|
59
|
+
│ └── redis/
|
|
60
|
+
│ ├── keyed-store.ts # Redis keyed store
|
|
61
|
+
│ ├── msgpack.ts # Redis + msgpack
|
|
62
|
+
│ └── types.ts # Storage interfaces
|
|
63
|
+
│
|
|
64
|
+
└── *.ts # Utility functions (see table)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
| File | Description |
|
|
68
|
+
|------|-------------|
|
|
69
|
+
| `buffer.ts` | Binary → Node.js Buffer |
|
|
70
|
+
| `clipboard.ts` | Clipboard API (browser) |
|
|
71
|
+
| `consola.ts` | Consola logger |
|
|
72
|
+
| `crypto-hash.ts` | MD5, SHA3 (Node) |
|
|
73
|
+
| `datetime.ts` | date-fns wrappers |
|
|
74
|
+
| `element-plus.ts` | Element Plus form rules |
|
|
75
|
+
| `enum.ts` | Enum value extractors |
|
|
76
|
+
| `env.ts` | Env var accessor |
|
|
77
|
+
| `event-awaiter.ts` | Async event wait |
|
|
78
|
+
| `general.ts` | extractFirstValue |
|
|
79
|
+
| `hash.ts` | SHA3 (browser) |
|
|
80
|
+
| `math.ts` | toPercentageString |
|
|
81
|
+
| `number.ts` | toCompactNumberString |
|
|
82
|
+
| `object.ts` | deterministic stringify |
|
|
83
|
+
| `pino.ts` | Pino logger |
|
|
84
|
+
| `random.ts` | nested random length |
|
|
85
|
+
| `string.ts` | randomString |
|
|
86
|
+
| `time.ts` | abortableDelay |
|
|
87
|
+
| `url.ts` | redirect param |
|
|
88
|
+
| `vue.ts` | Vue composables |
|
|
89
|
+
| `web.ts` | Web DOM helpers |
|
|
90
|
+
|
|
91
|
+
## Usage
|
|
53
92
|
|
|
54
93
|
```typescript
|
|
55
|
-
import { logger } from '@
|
|
56
|
-
import { extractFirstValue } from '@
|
|
94
|
+
import { logger } from '@kikiutils/shared/consola';
|
|
95
|
+
import { extractFirstValue } from '@kikiutils/shared/general';
|
|
57
96
|
|
|
58
97
|
const data = [
|
|
59
98
|
0,
|
|
60
|
-
1
|
|
99
|
+
1,
|
|
61
100
|
];
|
|
62
101
|
|
|
63
102
|
const value = extractFirstValue(data);
|
|
@@ -65,118 +104,6 @@ console.log(value); // 0
|
|
|
65
104
|
logger.info(value);
|
|
66
105
|
```
|
|
67
106
|
|
|
68
|
-
## Modules & Functions
|
|
69
|
-
|
|
70
|
-
Each module file includes function-level comments and usage examples.
|
|
71
|
-
|
|
72
|
-
### [buffer](./src/buffer.ts)
|
|
73
|
-
|
|
74
|
-
- `toBuffer`
|
|
75
|
-
|
|
76
|
-
### [clipboard](./src/clipboard.ts)
|
|
77
|
-
|
|
78
|
-
- `copyBlobToClipboard`
|
|
79
|
-
- `copyTextToClipboard`
|
|
80
|
-
|
|
81
|
-
### [consola](./src/consola.ts)
|
|
82
|
-
|
|
83
|
-
Console logger integration.
|
|
84
|
-
|
|
85
|
-
### [crypto-hash](./src/crypto-hash.ts)
|
|
86
|
-
|
|
87
|
-
- `cryptoMd5`, `cryptoMd5ToBuffer`
|
|
88
|
-
- `cryptoSha3224`, `cryptoSha3224ToBuffer`
|
|
89
|
-
- `cryptoSha3256`, `cryptoSha3256ToBuffer`
|
|
90
|
-
- `cryptoSha3384`, `cryptoSha3384ToBuffer`
|
|
91
|
-
- `cryptoSha3512`, `cryptoSha3512ToBuffer`
|
|
92
|
-
|
|
93
|
-
### [datetime](./src/datetime.ts)
|
|
94
|
-
|
|
95
|
-
- `formatDate`
|
|
96
|
-
- `getDateRangeFromDate`
|
|
97
|
-
- `getMidnightDateFromToday`
|
|
98
|
-
|
|
99
|
-
### [element-plus](./src/element-plus.ts)
|
|
100
|
-
|
|
101
|
-
- `createElFormItemRuleWithDefaults`
|
|
102
|
-
|
|
103
|
-
### [enum](./src/enum.ts)
|
|
104
|
-
|
|
105
|
-
- `getEnumStringValues`
|
|
106
|
-
- `getEnumNumberValues`
|
|
107
|
-
- `getEnumValues`
|
|
108
|
-
|
|
109
|
-
### [env](./src/env.ts)
|
|
110
|
-
|
|
111
|
-
- `checkAndGetEnvValue`
|
|
112
|
-
|
|
113
|
-
### [general](./src/general.ts)
|
|
114
|
-
|
|
115
|
-
- `extractFirstValue`
|
|
116
|
-
|
|
117
|
-
### [hash](./src/hash.ts)
|
|
118
|
-
|
|
119
|
-
- `sha3224`
|
|
120
|
-
- `sha3256`
|
|
121
|
-
- `sha3384`
|
|
122
|
-
- `sha3512`
|
|
123
|
-
|
|
124
|
-
### [math](./src/math.ts)
|
|
125
|
-
|
|
126
|
-
- `toPercentageString`
|
|
127
|
-
|
|
128
|
-
### [number](./src/number.ts)
|
|
129
|
-
|
|
130
|
-
- `toCompactNumberString`
|
|
131
|
-
|
|
132
|
-
### [object](./src/object.ts)
|
|
133
|
-
|
|
134
|
-
- `stringifyObjectDeterministically`
|
|
135
|
-
|
|
136
|
-
### [pino](./src/pino.ts)
|
|
137
|
-
|
|
138
|
-
Pino logger integration.
|
|
139
|
-
|
|
140
|
-
### [random](./src/random.ts)
|
|
141
|
-
|
|
142
|
-
- `generateWithNestedRandomLength`
|
|
143
|
-
|
|
144
|
-
### storage
|
|
145
|
-
|
|
146
|
-
#### [enhanced-local](./src/storage/enhanced/local/index.ts)
|
|
147
|
-
|
|
148
|
-
- `createKeyedEnhancedLocalStore`
|
|
149
|
-
- `enhancedLocalStorage`
|
|
150
|
-
|
|
151
|
-
#### [enhanced-redis](./src/storage/enhanced/redis/index.ts)
|
|
152
|
-
|
|
153
|
-
- `createEnhancedRedisStorage`
|
|
154
|
-
- `createKeyedEnhancedRedisStore`
|
|
155
|
-
|
|
156
|
-
#### [lru/keyed-store](./src/storage/lru/keyed-store.ts)
|
|
157
|
-
|
|
158
|
-
- `createKeyedLruStore`
|
|
159
|
-
|
|
160
|
-
### [string](./src/string.ts)
|
|
161
|
-
|
|
162
|
-
- `randomString`
|
|
163
|
-
|
|
164
|
-
### [url](./src/url.ts)
|
|
165
|
-
|
|
166
|
-
- `appendRedirectParamToUrl`
|
|
167
|
-
|
|
168
|
-
### [vue](./src/vue.ts)
|
|
169
|
-
|
|
170
|
-
- `appendRedirectParamFromCurrentRouteToUrl`
|
|
171
|
-
- `clearIntervalRef`
|
|
172
|
-
- `clearTimeoutRef`
|
|
173
|
-
- `usePreserveScroll`
|
|
174
|
-
|
|
175
|
-
### [web](./src/web.ts)
|
|
176
|
-
|
|
177
|
-
- `appendRedirectParamFromCurrentLocationToUrl`
|
|
178
|
-
- `assignUrlWithRedirectParamFromCurrentLocation`
|
|
179
|
-
|
|
180
107
|
## License
|
|
181
108
|
|
|
182
109
|
[MIT License](./LICENSE)
|
package/dist/crypto-hash.d.ts
CHANGED
|
@@ -1,15 +1,160 @@
|
|
|
1
1
|
import { BinaryLike, BinaryToTextEncoding } from "node:crypto";
|
|
2
2
|
|
|
3
3
|
//#region src/crypto-hash.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Computes the MD5 hash of the given data.
|
|
6
|
+
*
|
|
7
|
+
* @param {BinaryLike} data - The input data to hash
|
|
8
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
9
|
+
*
|
|
10
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { cryptoMd5 } from '@kikiutils/shared/crypto-hash';
|
|
15
|
+
*
|
|
16
|
+
* console.log(cryptoMd5('test')); // 33ed9a05a10b21f0...
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
4
19
|
declare function cryptoMd5(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
20
|
+
/**
|
|
21
|
+
* Computes the MD5 hash of the given data and returns the raw buffer.
|
|
22
|
+
*
|
|
23
|
+
* @param {BinaryLike} data - The input data to hash
|
|
24
|
+
*
|
|
25
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { cryptoMd5ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
30
|
+
*
|
|
31
|
+
* console.log(cryptoMd5ToBuffer('test')); // <Buffer 33 ed 9a ...>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
5
34
|
declare function cryptoMd5ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
35
|
+
/**
|
|
36
|
+
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
37
|
+
*
|
|
38
|
+
* @param {BinaryLike} data - The input data to hash
|
|
39
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
40
|
+
*
|
|
41
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { cryptoSha3224 } from '@kikiutils/shared/crypto-hash';
|
|
46
|
+
*
|
|
47
|
+
* console.log(cryptoSha3224('test')); // 0qW8FoqDcFmkpuqR9J3uT8YX...
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
6
50
|
declare function cryptoSha3224(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
51
|
+
/**
|
|
52
|
+
* Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.
|
|
53
|
+
*
|
|
54
|
+
* @param {BinaryLike} data - The input data to hash
|
|
55
|
+
*
|
|
56
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { cryptoSha3224ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
61
|
+
*
|
|
62
|
+
* console.log(cryptoSha3224ToBuffer('test')); // <Buffer 0q W8 Fo ...>
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
7
65
|
declare function cryptoSha3224ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
66
|
+
/**
|
|
67
|
+
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
68
|
+
*
|
|
69
|
+
* @param {BinaryLike} data - The input data to hash
|
|
70
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
71
|
+
*
|
|
72
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';
|
|
77
|
+
*
|
|
78
|
+
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
8
81
|
declare function cryptoSha3256(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
82
|
+
/**
|
|
83
|
+
* Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.
|
|
84
|
+
*
|
|
85
|
+
* @param {BinaryLike} data - The input data to hash
|
|
86
|
+
*
|
|
87
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* import { cryptoSha3256ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
92
|
+
*
|
|
93
|
+
* console.log(cryptoSha3256ToBuffer('test')); // <Buffer 36 f0 28 ...>
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
9
96
|
declare function cryptoSha3256ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
97
|
+
/**
|
|
98
|
+
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
99
|
+
*
|
|
100
|
+
* @param {BinaryLike} data - The input data to hash
|
|
101
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
102
|
+
*
|
|
103
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import { cryptoSha3384 } from '@kikiutils/shared/crypto-hash';
|
|
108
|
+
*
|
|
109
|
+
* console.log(cryptoSha3384('test')); // 1Q2wQAYaZ4o8vWX5bEB2n3Y...
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
10
112
|
declare function cryptoSha3384(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
113
|
+
/**
|
|
114
|
+
* Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.
|
|
115
|
+
*
|
|
116
|
+
* @param {BinaryLike} data - The input data to hash
|
|
117
|
+
*
|
|
118
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* import { cryptoSha3384ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
123
|
+
*
|
|
124
|
+
* console.log(cryptoSha3384ToBuffer('test')); // <Buffer 1Q 2w QZ ...>
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
11
127
|
declare function cryptoSha3384ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
128
|
+
/**
|
|
129
|
+
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
130
|
+
*
|
|
131
|
+
* @param {BinaryLike} data - The input data to hash
|
|
132
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
133
|
+
*
|
|
134
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* import { cryptoSha3512 } from '@kikiutils/shared/crypto-hash';
|
|
139
|
+
*
|
|
140
|
+
* console.log(cryptoSha3512('test')); // b_NQJ8FJBY9dIjm1q7...
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
12
143
|
declare function cryptoSha3512(data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string;
|
|
144
|
+
/**
|
|
145
|
+
* Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.
|
|
146
|
+
*
|
|
147
|
+
* @param {BinaryLike} data - The input data to hash
|
|
148
|
+
*
|
|
149
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* import { cryptoSha3512ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
154
|
+
*
|
|
155
|
+
* console.log(cryptoSha3512ToBuffer('test')); // <Buffer b_ NQ ...>
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
13
158
|
declare function cryptoSha3512ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
14
159
|
//#endregion
|
|
15
160
|
export { cryptoMd5, cryptoMd5ToBuffer, cryptoSha3224, cryptoSha3224ToBuffer, cryptoSha3256, cryptoSha3256ToBuffer, cryptoSha3384, cryptoSha3384ToBuffer, cryptoSha3512, cryptoSha3512ToBuffer };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.d.ts","names":[],"sources":["../src/crypto-hash.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"crypto-hash.d.ts","names":[],"sources":["../src/crypto-hash.ts"],"mappings":";;;;;AAqBA;;;;;;;;;;AAkBA;;;iBAlBgB,SAAA,CAAU,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,oBAAA;;;;;;AAqC5D;;;;;;;;;iBAnBgB,iBAAA,CAAkB,IAAA,EAAM,UAAA,GAAU,eAAA;AAqClD;;;;;;;;;AAmBA;;;;;;AAnBA,iBAlBgB,aAAA,CAAc,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,oBAAA;;;;AAuDhE;;;;;;;;;AAmBA;;iBAxDgB,qBAAA,CAAsB,IAAA,EAAM,UAAA,GAAU,eAAA;;;;;;;;AA0EtD;;;;;;;;iBAvDgB,aAAA,CAAc,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,oBAAA;AA0EhE;;;;;;;;;;AAkBA;;;;AAlBA,iBAxDgB,qBAAA,CAAsB,IAAA,EAAM,UAAA,GAAU,eAAA;;;;;;;;;;;;;;;;iBAmBtC,aAAA,CAAc,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,oBAAA;;;;;;;;;;;;;;;iBAkBhD,qBAAA,CAAsB,IAAA,EAAM,UAAA,GAAU,eAAA;;;;;;;;;;;;;;;;iBAmBtC,aAAA,CAAc,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,oBAAA;;;;;;;;;;;;;;;iBAkBhD,qBAAA,CAAsB,IAAA,EAAM,UAAA,GAAU,eAAA"}
|
package/dist/crypto-hash.js
CHANGED
|
@@ -1,47 +1,177 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
//#region src/crypto-hash.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
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.
|
|
4
|
+
* Computes the MD5 hash of the given data.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* @param {BinaryLike} data - The input data to hash
|
|
7
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
8
|
+
*
|
|
9
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
13
|
-
* import {
|
|
13
|
+
* import { cryptoMd5 } from '@kikiutils/shared/crypto-hash';
|
|
14
14
|
*
|
|
15
|
-
* console.log(
|
|
15
|
+
* console.log(cryptoMd5('test')); // 33ed9a05a10b21f0...
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
function cryptoMd5(data, outputEncoding = "hex") {
|
|
19
19
|
return createHash("md5").update(data).digest(outputEncoding);
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Computes the MD5 hash of the given data and returns the raw buffer.
|
|
23
|
+
*
|
|
24
|
+
* @param {BinaryLike} data - The input data to hash
|
|
25
|
+
*
|
|
26
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { cryptoMd5ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
31
|
+
*
|
|
32
|
+
* console.log(cryptoMd5ToBuffer('test')); // <Buffer 33 ed 9a ...>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
21
35
|
function cryptoMd5ToBuffer(data) {
|
|
22
36
|
return createHash("md5").update(data).digest();
|
|
23
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
40
|
+
*
|
|
41
|
+
* @param {BinaryLike} data - The input data to hash
|
|
42
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
43
|
+
*
|
|
44
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { cryptoSha3224 } from '@kikiutils/shared/crypto-hash';
|
|
49
|
+
*
|
|
50
|
+
* console.log(cryptoSha3224('test')); // 0qW8FoqDcFmkpuqR9J3uT8YX...
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
24
53
|
function cryptoSha3224(data, outputEncoding = "hex") {
|
|
25
54
|
return createHash("sha3-224").update(data).digest(outputEncoding);
|
|
26
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.
|
|
58
|
+
*
|
|
59
|
+
* @param {BinaryLike} data - The input data to hash
|
|
60
|
+
*
|
|
61
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { cryptoSha3224ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
66
|
+
*
|
|
67
|
+
* console.log(cryptoSha3224ToBuffer('test')); // <Buffer 0q W8 Fo ...>
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
27
70
|
function cryptoSha3224ToBuffer(data) {
|
|
28
71
|
return createHash("sha3-224").update(data).digest();
|
|
29
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
75
|
+
*
|
|
76
|
+
* @param {BinaryLike} data - The input data to hash
|
|
77
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
78
|
+
*
|
|
79
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';
|
|
84
|
+
*
|
|
85
|
+
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
30
88
|
function cryptoSha3256(data, outputEncoding = "hex") {
|
|
31
89
|
return createHash("sha3-256").update(data).digest(outputEncoding);
|
|
32
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.
|
|
93
|
+
*
|
|
94
|
+
* @param {BinaryLike} data - The input data to hash
|
|
95
|
+
*
|
|
96
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* import { cryptoSha3256ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
101
|
+
*
|
|
102
|
+
* console.log(cryptoSha3256ToBuffer('test')); // <Buffer 36 f0 28 ...>
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
33
105
|
function cryptoSha3256ToBuffer(data) {
|
|
34
106
|
return createHash("sha3-256").update(data).digest();
|
|
35
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
110
|
+
*
|
|
111
|
+
* @param {BinaryLike} data - The input data to hash
|
|
112
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
113
|
+
*
|
|
114
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { cryptoSha3384 } from '@kikiutils/shared/crypto-hash';
|
|
119
|
+
*
|
|
120
|
+
* console.log(cryptoSha3384('test')); // 1Q2wQAYaZ4o8vWX5bEB2n3Y...
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
36
123
|
function cryptoSha3384(data, outputEncoding = "hex") {
|
|
37
124
|
return createHash("sha3-384").update(data).digest(outputEncoding);
|
|
38
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.
|
|
128
|
+
*
|
|
129
|
+
* @param {BinaryLike} data - The input data to hash
|
|
130
|
+
*
|
|
131
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* import { cryptoSha3384ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
136
|
+
*
|
|
137
|
+
* console.log(cryptoSha3384ToBuffer('test')); // <Buffer 1Q 2w QZ ...>
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
39
140
|
function cryptoSha3384ToBuffer(data) {
|
|
40
141
|
return createHash("sha3-384").update(data).digest();
|
|
41
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
145
|
+
*
|
|
146
|
+
* @param {BinaryLike} data - The input data to hash
|
|
147
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
148
|
+
*
|
|
149
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* import { cryptoSha3512 } from '@kikiutils/shared/crypto-hash';
|
|
154
|
+
*
|
|
155
|
+
* console.log(cryptoSha3512('test')); // b_NQJ8FJBY9dIjm1q7...
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
42
158
|
function cryptoSha3512(data, outputEncoding = "hex") {
|
|
43
159
|
return createHash("sha3-512").update(data).digest(outputEncoding);
|
|
44
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.
|
|
163
|
+
*
|
|
164
|
+
* @param {BinaryLike} data - The input data to hash
|
|
165
|
+
*
|
|
166
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* import { cryptoSha3512ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
171
|
+
*
|
|
172
|
+
* console.log(cryptoSha3512ToBuffer('test')); // <Buffer b_ NQ ...>
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
45
175
|
function cryptoSha3512ToBuffer(data) {
|
|
46
176
|
return createHash("sha3-512").update(data).digest();
|
|
47
177
|
}
|
package/dist/crypto-hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.js","names":[],"sources":["../src/crypto-hash.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"crypto-hash.js","names":[],"sources":["../src/crypto-hash.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport type {\n BinaryLike,\n BinaryToTextEncoding,\n} from 'node:crypto';\n\n/**\n * Computes the MD5 hash of the given data.\n *\n * @param {BinaryLike} data - The input data to hash\n * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)\n *\n * @returns {string | Buffer} The hash digest in the specified encoding\n *\n * @example\n * ```typescript\n * import { cryptoMd5 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoMd5('test')); // 33ed9a05a10b21f0...\n * ```\n */\nexport function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('md5').update(data).digest(outputEncoding);\n}\n\n/**\n * Computes the MD5 hash of the given data and returns the raw buffer.\n *\n * @param {BinaryLike} data - The input data to hash\n *\n * @returns {Buffer} The raw hash digest as a Buffer\n *\n * @example\n * ```typescript\n * import { cryptoMd5ToBuffer } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoMd5ToBuffer('test')); // <Buffer 33 ed 9a ...>\n * ```\n */\nexport function cryptoMd5ToBuffer(data: BinaryLike) {\n return createHash('md5').update(data).digest();\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 224-bit digest.\n *\n * @param {BinaryLike} data - The input data to hash\n * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)\n *\n * @returns {string | Buffer} The hash digest in the specified encoding\n *\n * @example\n * ```typescript\n * import { cryptoSha3224 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3224('test')); // 0qW8FoqDcFmkpuqR9J3uT8YX...\n * ```\n */\nexport function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-224').update(data).digest(outputEncoding);\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.\n *\n * @param {BinaryLike} data - The input data to hash\n *\n * @returns {Buffer} The raw hash digest as a Buffer\n *\n * @example\n * ```typescript\n * import { cryptoSha3224ToBuffer } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3224ToBuffer('test')); // <Buffer 0q W8 Fo ...>\n * ```\n */\nexport function cryptoSha3224ToBuffer(data: BinaryLike) {\n return createHash('sha3-224').update(data).digest();\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 256-bit digest.\n *\n * @param {BinaryLike} data - The input data to hash\n * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)\n *\n * @returns {string | Buffer} The hash digest in the specified encoding\n *\n * @example\n * ```typescript\n * import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80\n * ```\n */\nexport function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-256').update(data).digest(outputEncoding);\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.\n *\n * @param {BinaryLike} data - The input data to hash\n *\n * @returns {Buffer} The raw hash digest as a Buffer\n *\n * @example\n * ```typescript\n * import { cryptoSha3256ToBuffer } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3256ToBuffer('test')); // <Buffer 36 f0 28 ...>\n * ```\n */\nexport function cryptoSha3256ToBuffer(data: BinaryLike) {\n return createHash('sha3-256').update(data).digest();\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 384-bit digest.\n *\n * @param {BinaryLike} data - The input data to hash\n * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)\n *\n * @returns {string | Buffer} The hash digest in the specified encoding\n *\n * @example\n * ```typescript\n * import { cryptoSha3384 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3384('test')); // 1Q2wQAYaZ4o8vWX5bEB2n3Y...\n * ```\n */\nexport function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-384').update(data).digest(outputEncoding);\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.\n *\n * @param {BinaryLike} data - The input data to hash\n *\n * @returns {Buffer} The raw hash digest as a Buffer\n *\n * @example\n * ```typescript\n * import { cryptoSha3384ToBuffer } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3384ToBuffer('test')); // <Buffer 1Q 2w QZ ...>\n * ```\n */\nexport function cryptoSha3384ToBuffer(data: BinaryLike) {\n return createHash('sha3-384').update(data).digest();\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 512-bit digest.\n *\n * @param {BinaryLike} data - The input data to hash\n * @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)\n *\n * @returns {string | Buffer} The hash digest in the specified encoding\n *\n * @example\n * ```typescript\n * import { cryptoSha3512 } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3512('test')); // b_NQJ8FJBY9dIjm1q7...\n * ```\n */\nexport function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {\n return createHash('sha3-512').update(data).digest(outputEncoding);\n}\n\n/**\n * Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.\n *\n * @param {BinaryLike} data - The input data to hash\n *\n * @returns {Buffer} The raw hash digest as a Buffer\n *\n * @example\n * ```typescript\n * import { cryptoSha3512ToBuffer } from '@kikiutils/shared/crypto-hash';\n *\n * console.log(cryptoSha3512ToBuffer('test')); // <Buffer b_ NQ ...>\n * ```\n */\nexport function cryptoSha3512ToBuffer(data: BinaryLike) {\n return createHash('sha3-512').update(data).digest();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,SAAgB,UAAU,MAAkB,iBAAuC,OAAO;AACtF,QAAO,WAAW,MAAM,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;;;;;;;;;;;;;;;AAiBhE,SAAgB,kBAAkB,MAAkB;AAChD,QAAO,WAAW,MAAM,CAAC,OAAO,KAAK,CAAC,QAAQ;;;;;;;;;;;;;;;;;AAkBlD,SAAgB,cAAc,MAAkB,iBAAuC,OAAO;AAC1F,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;;;;;;;;;;;;;;;AAiBrE,SAAgB,sBAAsB,MAAkB;AACpD,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,QAAQ;;;;;;;;;;;;;;;;;AAkBvD,SAAgB,cAAc,MAAkB,iBAAuC,OAAO;AAC1F,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;;;;;;;;;;;;;;;AAiBrE,SAAgB,sBAAsB,MAAkB;AACpD,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,QAAQ;;;;;;;;;;;;;;;;;AAkBvD,SAAgB,cAAc,MAAkB,iBAAuC,OAAO;AAC1F,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;;;;;;;;;;;;;;;AAiBrE,SAAgB,sBAAsB,MAAkB;AACpD,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,QAAQ;;;;;;;;;;;;;;;;;AAkBvD,SAAgB,cAAc,MAAkB,iBAAuC,OAAO;AAC1F,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,OAAO,eAAe;;;;;;;;;;;;;;;;AAiBrE,SAAgB,sBAAsB,MAAkB;AACpD,QAAO,WAAW,WAAW,CAAC,OAAO,KAAK,CAAC,QAAQ"}
|
package/dist/datetime.d.ts
CHANGED
|
@@ -26,8 +26,6 @@ type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'toda
|
|
|
26
26
|
* // Format a date string
|
|
27
27
|
* console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
|
|
28
28
|
* ```
|
|
29
|
-
*
|
|
30
|
-
* @see https://date-fns.org/docs/format
|
|
31
29
|
*/
|
|
32
30
|
declare function formatDate(date: DateArg<Date> & {}, format?: string, options?: FormatOptions): string;
|
|
33
31
|
/**
|
package/dist/datetime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.d.ts","names":[],"sources":["../src/datetime.ts"],"mappings":";;;KAkBY,aAAA;;AAAZ;;;;;
|
|
1
|
+
{"version":3,"file":"datetime.d.ts","names":[],"sources":["../src/datetime.ts"],"mappings":";;;KAkBY,aAAA;;AAAZ;;;;;AA2BA;;;;;;;;;;;;;;;;AA+BA;;;iBA/BgB,UAAA,CAAW,IAAA,EAAM,OAAA,CAAQ,IAAA,QAAY,MAAA,WAAwC,OAAA,GAAU,aAAA;;;;;;;;;;;;;;;;;;;;;AAwGvG;;;;;;;iBAzEgB,oBAAA,CACZ,IAAA,EAAM,IAAA,EACN,IAAA,EAAM,aAAA,EACN,OAAA;EACI,wBAAA;EACA,YAAA,GAAe,GAAA;AAAA;;;;;;;;;;;;;;;;;;;;iBAoEP,wBAAA,CAAyB,UAAA,YAAsB,IAAA"}
|
package/dist/datetime.js
CHANGED
|
@@ -24,8 +24,6 @@ import { endOfDay, endOfMonth, endOfWeek, format, startOfDay, startOfMonth, star
|
|
|
24
24
|
* // Format a date string
|
|
25
25
|
* console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
|
|
26
26
|
* ```
|
|
27
|
-
*
|
|
28
|
-
* @see https://date-fns.org/docs/format
|
|
29
27
|
*/
|
|
30
28
|
function formatDate(date, format$1 = "yyyy-MM-dd HH:mm:ss", options) {
|
|
31
29
|
return format(date, format$1, options);
|
package/dist/datetime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.js","names":["dateFnsFormat","format"],"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
|
|
1
|
+
{"version":3,"file":"datetime.js","names":["dateFnsFormat","format"],"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 */\nexport function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-dd HH:mm:ss', options?: FormatOptions) {\n return dateFnsFormat(date, format, options);\n}\n\n/**\n * Get the date range (start and end) based on a given date and range type.\n *\n * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.\n *\n * @param {Date} date - The reference date\n * @param {DateRangeType} type - The range type to compute\n * @param {object} [options] - Optional settings\n * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day\n * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)\n *\n * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`\n *\n * @example\n * ```typescript\n * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';\n *\n * // Get the date range for last month\n * const date = new Date('2023-07-01');\n * console.log(getDateRangeFromDate(date, 'lastMonth'));\n * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }\n *\n * // Get this week's range with Sunday as the first day\n * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));\n * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }\n * ```\n */\nexport function getDateRangeFromDate(\n date: Date,\n type: DateRangeType,\n options?: {\n setEndDateToNextDayStart?: boolean;\n weekStartsOn?: Day;\n },\n) {\n let endDate: Date;\n let startDate: Date;\n switch (type) {\n case 'lastMonth':\n {\n const lastMonth = subMonths(date, 1);\n endDate = endOfMonth(lastMonth);\n startDate = startOfMonth(lastMonth);\n }\n\n break;\n case 'lastWeek':\n {\n const lastWeek = subWeeks(date, 1);\n endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n }\n\n break;\n case 'thisMonth':\n endDate = endOfMonth(date);\n startDate = startOfMonth(date);\n break;\n case 'thisWeek':\n endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n break;\n case 'today':\n endDate = endOfDay(date);\n startDate = startOfDay(date);\n break;\n case 'yesterday':\n {\n const yesterday = subDays(date, 1);\n endDate = endOfDay(yesterday);\n startDate = startOfDay(yesterday);\n }\n\n break;\n default: throw new Error(`Unsupported date range type: ${type}`);\n }\n\n if (options?.setEndDateToNextDayStart) endDate.setHours(24, 0, 0, 0);\n return {\n endDate,\n startDate,\n };\n}\n\n/**\n * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.\n *\n * @param {number} [offsetDays] - Number of days to offset from today. Can be negative\n *\n * @returns {Date} A `Date` object at 00:00:00 of the offset day\n *\n * @example\n * ```typescript\n * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';\n *\n * console.log(getMidnightDateFromToday()); // today at 00:00:00\n * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00\n * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00\n * ```\n */\nexport function getMidnightDateFromToday(offsetDays: number = 0) {\n const date = new Date();\n date.setDate(date.getDate() + offsetDays);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,WAAW,MAA0B,WAAiB,uBAAuB,SAAyB;AAClH,QAAOA,OAAc,MAAMC,UAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B/C,SAAgB,qBACZ,MACA,MACA,SAIF;CACE,IAAI;CACJ,IAAI;AACJ,SAAQ,MAAR;EACI,KAAK;GACD;IACI,MAAM,YAAY,UAAU,MAAM,EAAE;AACpC,cAAU,WAAW,UAAU;AAC/B,gBAAY,aAAa,UAAU;;AAGvC;EACJ,KAAK;GACD;IACI,MAAM,WAAW,SAAS,MAAM,EAAE;AAClC,cAAU,UAAU,UAAU,EAAE,cAAc,SAAS,gBAAgB,GAAG,CAAC;AAC3E,gBAAY,YAAY,UAAU,EAAE,cAAc,SAAS,gBAAgB,GAAG,CAAC;;AAGnF;EACJ,KAAK;AACD,aAAU,WAAW,KAAK;AAC1B,eAAY,aAAa,KAAK;AAC9B;EACJ,KAAK;AACD,aAAU,UAAU,MAAM,EAAE,cAAc,SAAS,gBAAgB,GAAG,CAAC;AACvE,eAAY,YAAY,MAAM,EAAE,cAAc,SAAS,gBAAgB,GAAG,CAAC;AAC3E;EACJ,KAAK;AACD,aAAU,SAAS,KAAK;AACxB,eAAY,WAAW,KAAK;AAC5B;EACJ,KAAK;GACD;IACI,MAAM,YAAY,QAAQ,MAAM,EAAE;AAClC,cAAU,SAAS,UAAU;AAC7B,gBAAY,WAAW,UAAU;;AAGrC;EACJ,QAAS,OAAM,IAAI,MAAM,gCAAgC,OAAO;;AAGpE,KAAI,SAAS,yBAA0B,SAAQ,SAAS,IAAI,GAAG,GAAG,EAAE;AACpE,QAAO;EACH;EACA;EACH;;;;;;;;;;;;;;;;;;AAmBL,SAAgB,yBAAyB,aAAqB,GAAG;CAC7D,MAAM,uBAAO,IAAI,MAAM;AACvB,MAAK,QAAQ,KAAK,SAAS,GAAG,WAAW;AACzC,MAAK,SAAS,GAAG,GAAG,GAAG,EAAE;AACzB,QAAO"}
|
package/dist/enum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","names":[],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAAmD,YAA8C;AAC7G,QAAO,cAAc,WAAW,CAAC,QAAQ,UAAU,OAAO,UAAU,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;AA0BjF,SAAgB,oBAAmD,YAA8C;AAC7G,QAAO,cAAc,WAAW,CAAC,QAAQ,UAAU,OAAO,UAAU,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDjF,SAAgB,cAA6C,YAA+B;CACxF,MAAM,SAAS,OAAO,OAAO,WAAW;AAExC,KAAI,CADoB,OAAO,MAAM,UAAU,OAAO,UAAU,
|
|
1
|
+
{"version":3,"file":"enum.js","names":[],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAAmD,YAA8C;AAC7G,QAAO,cAAc,WAAW,CAAC,QAAQ,UAAU,OAAO,UAAU,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;AA0BjF,SAAgB,oBAAmD,YAA8C;AAC7G,QAAO,cAAc,WAAW,CAAC,QAAQ,UAAU,OAAO,UAAU,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDjF,SAAgB,cAA6C,YAA+B;CACxF,MAAM,SAAS,OAAO,OAAO,WAAW;AAExC,KAAI,CADoB,OAAO,MAAM,UAAU,OAAO,UAAU,SAC5C,CAAE,QAAO;AAC7B,QAAO,OAAO,KAAK,WAAW,CAAC,QAAQ,QAAQ,OAAO,MAAM,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,WAAW,KAAK"}
|
package/dist/env.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ declare class EnvironmentNotFoundError extends Error {
|
|
|
29
29
|
*
|
|
30
30
|
* @example
|
|
31
31
|
* ```typescript
|
|
32
|
+
* import { checkAndGetEnvValue } from '@kikiutils/shared/env';
|
|
33
|
+
*
|
|
32
34
|
* process.env.API_KEY = '';
|
|
33
35
|
* checkAndGetEnvValue('API_KEY'); // ✅ Returns '' (still considered "defined")
|
|
34
36
|
*
|
package/dist/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","names":[],"sources":["../src/env.ts"],"mappings":";;AAOA;;;;;;cAAa,wBAAA,SAAiC,KAAA;EAAA,SACjC,GAAA;EAOc;;
|
|
1
|
+
{"version":3,"file":"env.d.ts","names":[],"sources":["../src/env.ts"],"mappings":";;AAOA;;;;;;cAAa,wBAAA,SAAiC,KAAA;EAAA,SACjC,GAAA;EAOc;;AA+B3B;;;cA/BgB,GAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;iBA+BA,mBAAA,CAAoB,GAAA"}
|