@kikiutils/shared 18.0.1 → 18.1.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/dist/buffer.d.ts +19 -21
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +18 -19
- package/dist/buffer.js.map +1 -1
- package/dist/classes/enhanced-date.d.ts +425 -0
- package/dist/classes/enhanced-date.d.ts.map +1 -0
- package/dist/classes/enhanced-date.js +591 -0
- package/dist/classes/enhanced-date.js.map +1 -0
- package/dist/classes/path.d.ts +211 -48
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js +181 -52
- package/dist/classes/path.js.map +1 -1
- package/dist/classes/precision-number.d.ts +44 -39
- package/dist/classes/precision-number.d.ts.map +1 -1
- package/dist/classes/precision-number.js +51 -45
- package/dist/classes/precision-number.js.map +1 -1
- package/dist/classes/ssh-client.d.ts +3 -4
- package/dist/classes/ssh-client.d.ts.map +1 -1
- package/dist/classes/ssh-client.js +2 -2
- package/dist/classes/ssh-client.js.map +1 -1
- package/dist/clipboard.d.ts +25 -26
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +23 -23
- package/dist/clipboard.js.map +1 -1
- package/dist/consola.d.ts +12 -15
- package/dist/consola.d.ts.map +1 -1
- package/dist/consola.js +10 -12
- package/dist/consola.js.map +1 -1
- package/dist/crypto-hash.d.ts +65 -56
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +55 -45
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.d.ts +41 -53
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +53 -66
- package/dist/datetime.js.map +1 -1
- package/dist/element-plus.d.ts +13 -14
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/element-plus.js +11 -11
- package/dist/element-plus.js.map +1 -1
- package/dist/enum.d.ts +39 -36
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js +36 -32
- package/dist/enum.js.map +1 -1
- package/dist/env.d.ts +22 -15
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +20 -12
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.d.ts +47 -52
- package/dist/event-awaiter.d.ts.map +1 -1
- package/dist/event-awaiter.js +46 -50
- package/dist/event-awaiter.js.map +1 -1
- package/dist/general.d.ts +22 -17
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js.map +1 -1
- package/dist/hash.d.ts +24 -21
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +20 -16
- package/dist/hash.js.map +1 -1
- package/dist/math.d.ts +20 -19
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +14 -12
- package/dist/math.js.map +1 -1
- package/dist/number.d.ts +10 -9
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +9 -7
- package/dist/number.js.map +1 -1
- package/dist/object.d.ts +22 -10
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +21 -8
- package/dist/object.js.map +1 -1
- package/dist/pino.d.ts +12 -15
- package/dist/pino.d.ts.map +1 -1
- package/dist/pino.js +10 -15
- package/dist/pino.js.map +1 -1
- package/dist/random.d.ts +17 -15
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +16 -13
- package/dist/random.js.map +1 -1
- package/dist/redis/script-runner.d.ts +57 -0
- package/dist/redis/script-runner.d.ts.map +1 -0
- package/dist/redis/script-runner.js +46 -0
- package/dist/redis/script-runner.js.map +1 -0
- package/dist/storages/lru/keyed-store.d.ts +18 -14
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js +17 -12
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +11 -21
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.js +10 -19
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.d.ts +33 -13
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js +32 -11
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/storages/redis/types.d.ts +34 -17
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/string.d.ts +12 -11
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +20 -15
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts +26 -21
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +24 -18
- package/dist/time.js.map +1 -1
- package/dist/types/filtered-key-path.d.ts +4 -15
- package/dist/types/filtered-key-path.d.ts.map +1 -1
- package/dist/types/index.d.ts +10 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/vue.d.ts +7 -7
- package/dist/types/vue.d.ts.map +1 -1
- package/dist/url.d.ts +15 -14
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +12 -10
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +19 -21
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +15 -16
- package/dist/vue.js.map +1 -1
- package/dist/web.d.ts +14 -11
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +12 -8
- package/dist/web.js.map +1 -1
- package/package.json +20 -20
- package/src/buffer.ts +18 -19
- package/src/classes/enhanced-date.ts +665 -0
- package/src/classes/path.ts +232 -91
- package/src/classes/precision-number.ts +61 -53
- package/src/classes/ssh-client.ts +8 -5
- package/src/clipboard.ts +23 -23
- package/src/consola.ts +10 -12
- package/src/crypto-hash.ts +55 -45
- package/src/datetime.ts +65 -85
- package/src/element-plus.ts +11 -11
- package/src/enum.ts +36 -32
- package/src/env.ts +20 -12
- package/src/event-awaiter.ts +49 -50
- package/src/general.ts +20 -14
- package/src/hash.ts +20 -16
- package/src/math.ts +18 -16
- package/src/number.ts +9 -7
- package/src/object.ts +21 -8
- package/src/pino.ts +11 -15
- package/src/random.ts +16 -13
- package/src/redis/script-runner.ts +107 -0
- package/src/storages/lru/keyed-store.ts +17 -12
- package/src/storages/redis/keyed-store.ts +10 -19
- package/src/storages/redis/msgpack.ts +32 -11
- package/src/storages/redis/types.ts +32 -14
- package/src/string.ts +10 -8
- package/src/time.ts +24 -18
- package/src/types/filtered-key-path.ts +9 -14
- package/src/types/vue.ts +6 -5
- package/src/url.ts +12 -10
- package/src/vue.ts +15 -16
- package/src/web.ts +12 -8
|
@@ -6,36 +6,41 @@ import { Decimal } from 'decimal.js';
|
|
|
6
6
|
export type PrecisionNumberValue = Decimal.Value | PrecisionNumber | { toString: () => string };
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* A fixed-decimal number with mutable and immutable arithmetic operations.
|
|
10
10
|
*
|
|
11
|
+
* @remarks
|
|
11
12
|
* `PrecisionNumber` stores values as `Decimal`, rounds every mutating operation to
|
|
12
13
|
* the configured decimal places, and exposes both mutable and immutable arithmetic
|
|
13
14
|
* methods. Mutable methods (`plus`, `minus`, `times`, `dividedBy`, `modulo`,
|
|
14
15
|
* `pow`, `clamp`, `ceil`, `floor`, `negate`, `absoluteValue`) update the current
|
|
15
16
|
* instance and return `this`; immutable methods prefixed with `to` return a new
|
|
16
|
-
* `PrecisionNumber` with the same precision settings.
|
|
17
|
+
* `PrecisionNumber` with the same precision settings, leaving this instance unchanged.
|
|
18
|
+
* Decimal.js exceptions propagate unchanged; non-finite arithmetic results are not converted into exceptions.
|
|
17
19
|
*
|
|
18
20
|
* @example
|
|
19
|
-
*
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
20
23
|
* import { PrecisionNumber } from '@kikiutils/shared/classes/precision-number';
|
|
21
24
|
*
|
|
22
25
|
* const value = new PrecisionNumber('1.239', 2).plus('2.111');
|
|
23
|
-
* value.toString(); // '3.35'
|
|
24
|
-
* value.toMinus('1').toString(); // '2.35' (original value remains '3.35')
|
|
26
|
+
* value.toString(); // => '3.35'
|
|
27
|
+
* value.toMinus('1').toString(); // => '2.35' (original value remains '3.35')
|
|
25
28
|
* ```
|
|
26
29
|
*/
|
|
27
30
|
export class PrecisionNumber {
|
|
28
|
-
// Private properties
|
|
31
|
+
// Private instance properties
|
|
29
32
|
readonly #decimalPlaces: number;
|
|
30
33
|
readonly #rounding: Decimal.Rounding;
|
|
31
34
|
#decimal: Decimal;
|
|
32
35
|
|
|
36
|
+
// Constructor
|
|
37
|
+
|
|
33
38
|
/**
|
|
34
39
|
* Creates a fixed-decimal number.
|
|
35
40
|
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
41
|
+
* @param value - Initial value (default: `'0'`).
|
|
42
|
+
* @param decimalPlaces - Decimal places retained after operations (default: `2`).
|
|
43
|
+
* @param rounding - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`).
|
|
39
44
|
*/
|
|
40
45
|
constructor(
|
|
41
46
|
value: PrecisionNumberValue = '0',
|
|
@@ -47,26 +52,7 @@ export class PrecisionNumber {
|
|
|
47
52
|
this.#decimal = this.#decimalToFixedDecimal(new Decimal(value.toString().trim()));
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Returns the formatted value when inspected by Node.js utilities.
|
|
54
|
-
*/
|
|
55
|
-
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
56
|
-
return this.value;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Converts to a number for numeric coercion and to the fixed string otherwise.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} hint - JavaScript primitive-conversion hint
|
|
63
|
-
*/
|
|
64
|
-
[Symbol.toPrimitive](hint: string) {
|
|
65
|
-
if (hint === 'number') return this.#decimal.toNumber();
|
|
66
|
-
return this.value;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Private methods
|
|
55
|
+
// Private instance methods
|
|
70
56
|
#decimalToFixedDecimal(decimal: Decimal) {
|
|
71
57
|
return decimal.toDecimalPlaces(this.#decimalPlaces, this.#rounding);
|
|
72
58
|
}
|
|
@@ -75,7 +61,7 @@ export class PrecisionNumber {
|
|
|
75
61
|
return value.toString().trim();
|
|
76
62
|
}
|
|
77
63
|
|
|
78
|
-
// Public
|
|
64
|
+
// Public instance accessors
|
|
79
65
|
|
|
80
66
|
/**
|
|
81
67
|
* Decimal places retained by mutating operations and default formatting.
|
|
@@ -98,14 +84,16 @@ export class PrecisionNumber {
|
|
|
98
84
|
return this.#decimal.toFixed(this.#decimalPlaces, this.#rounding);
|
|
99
85
|
}
|
|
100
86
|
|
|
87
|
+
// Public static methods
|
|
88
|
+
|
|
101
89
|
/**
|
|
102
90
|
* Formats a value with decimal.js without creating a reusable instance.
|
|
103
91
|
*
|
|
104
|
-
* @param
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
92
|
+
* @param value - Value to format.
|
|
93
|
+
* @param decimalPlaces - Decimal places to output (default: `2`).
|
|
94
|
+
* @param rounding - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`).
|
|
107
95
|
*
|
|
108
|
-
* @returns
|
|
96
|
+
* @returns Fixed-decimal string.
|
|
109
97
|
*/
|
|
110
98
|
static toFixed(
|
|
111
99
|
value: PrecisionNumberValue,
|
|
@@ -115,12 +103,29 @@ export class PrecisionNumber {
|
|
|
115
103
|
return new Decimal(value.toString().trim()).toFixed(decimalPlaces, rounding);
|
|
116
104
|
}
|
|
117
105
|
|
|
118
|
-
// Public methods
|
|
106
|
+
// Public instance methods
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Returns the formatted value when inspected by Node.js utilities.
|
|
110
|
+
*/
|
|
111
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
112
|
+
return this.value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Converts to a number for numeric coercion and to the fixed string otherwise.
|
|
117
|
+
*
|
|
118
|
+
* @param hint - JavaScript primitive-conversion hint.
|
|
119
|
+
*/
|
|
120
|
+
[Symbol.toPrimitive](hint: string) {
|
|
121
|
+
if (hint === 'number') return this.#decimal.toNumber();
|
|
122
|
+
return this.value;
|
|
123
|
+
}
|
|
119
124
|
|
|
120
125
|
/**
|
|
121
126
|
* Replaces the current value with its absolute value.
|
|
122
127
|
*
|
|
123
|
-
* @returns
|
|
128
|
+
* @returns This instance for chaining.
|
|
124
129
|
*/
|
|
125
130
|
absoluteValue() {
|
|
126
131
|
this.#decimal = this.#decimalToFixedDecimal(this.#decimal.absoluteValue());
|
|
@@ -130,9 +135,10 @@ export class PrecisionNumber {
|
|
|
130
135
|
/**
|
|
131
136
|
* Rounds the current value up to the nearest integer in place.
|
|
132
137
|
*
|
|
138
|
+
* @remarks
|
|
133
139
|
* The stored value still uses this instance's configured decimal places for output.
|
|
134
140
|
*
|
|
135
|
-
* @returns
|
|
141
|
+
* @returns This instance for chaining.
|
|
136
142
|
*/
|
|
137
143
|
ceil() {
|
|
138
144
|
this.#decimal = this.#decimalToFixedDecimal(this.#decimal.ceil());
|
|
@@ -142,12 +148,12 @@ export class PrecisionNumber {
|
|
|
142
148
|
/**
|
|
143
149
|
* Restricts the current value to the inclusive range `[min, max]` in place.
|
|
144
150
|
*
|
|
145
|
-
* @param
|
|
146
|
-
* @param
|
|
151
|
+
* @param min - Lower bound.
|
|
152
|
+
* @param max - Upper bound.
|
|
147
153
|
*
|
|
148
|
-
* @returns
|
|
154
|
+
* @returns This instance for chaining.
|
|
149
155
|
*
|
|
150
|
-
* @throws
|
|
156
|
+
* @throws Error if `min` is greater than `max`.
|
|
151
157
|
*/
|
|
152
158
|
clamp(min: PrecisionNumberValue, max: PrecisionNumberValue) {
|
|
153
159
|
const minDecimal = new Decimal(this.#valueToString(min));
|
|
@@ -167,9 +173,9 @@ export class PrecisionNumber {
|
|
|
167
173
|
/**
|
|
168
174
|
* Divides the current value by another value in place.
|
|
169
175
|
*
|
|
170
|
-
* @param
|
|
176
|
+
* @param value - Divisor.
|
|
171
177
|
*
|
|
172
|
-
* @returns
|
|
178
|
+
* @returns This instance for chaining.
|
|
173
179
|
*/
|
|
174
180
|
dividedBy(value: PrecisionNumberValue) {
|
|
175
181
|
this.#decimal = this.#decimalToFixedDecimal(this.#decimal.dividedBy(this.#valueToString(value)));
|
|
@@ -179,9 +185,9 @@ export class PrecisionNumber {
|
|
|
179
185
|
/**
|
|
180
186
|
* Checks whether the current value equals another value.
|
|
181
187
|
*
|
|
182
|
-
* @param
|
|
188
|
+
* @param value - Value to compare.
|
|
183
189
|
*
|
|
184
|
-
* @returns
|
|
190
|
+
* @returns Whether both numeric values are equal.
|
|
185
191
|
*/
|
|
186
192
|
equals(value: PrecisionNumberValue) {
|
|
187
193
|
return this.#decimal.equals(this.#valueToString(value));
|
|
@@ -190,9 +196,10 @@ export class PrecisionNumber {
|
|
|
190
196
|
/**
|
|
191
197
|
* Rounds the current value down to the nearest integer in place.
|
|
192
198
|
*
|
|
199
|
+
* @remarks
|
|
193
200
|
* The stored value still uses this instance's configured decimal places for output.
|
|
194
201
|
*
|
|
195
|
-
* @returns
|
|
202
|
+
* @returns This instance for chaining.
|
|
196
203
|
*/
|
|
197
204
|
floor() {
|
|
198
205
|
this.#decimal = this.#decimalToFixedDecimal(this.#decimal.floor());
|
|
@@ -280,9 +287,9 @@ export class PrecisionNumber {
|
|
|
280
287
|
/**
|
|
281
288
|
* Replaces the current value with the remainder after division by another value.
|
|
282
289
|
*
|
|
283
|
-
* @param
|
|
290
|
+
* @param value - Divisor used to compute the remainder.
|
|
284
291
|
*
|
|
285
|
-
* @returns
|
|
292
|
+
* @returns This instance for chaining.
|
|
286
293
|
*/
|
|
287
294
|
modulo(value: PrecisionNumberValue) {
|
|
288
295
|
this.#decimal = this.#decimalToFixedDecimal(this.#decimal.modulo(this.#valueToString(value)));
|
|
@@ -308,9 +315,9 @@ export class PrecisionNumber {
|
|
|
308
315
|
/**
|
|
309
316
|
* Raises the current value to an exponent in place.
|
|
310
317
|
*
|
|
311
|
-
* @param
|
|
318
|
+
* @param value - Exponent.
|
|
312
319
|
*
|
|
313
|
-
* @returns
|
|
320
|
+
* @returns This instance for chaining.
|
|
314
321
|
*/
|
|
315
322
|
pow(value: PrecisionNumberValue) {
|
|
316
323
|
this.#decimal = this.#decimalToFixedDecimal(this.#decimal.pow(this.#valueToString(value)));
|
|
@@ -342,10 +349,10 @@ export class PrecisionNumber {
|
|
|
342
349
|
/**
|
|
343
350
|
* Returns a new instance restricted to the inclusive range `[min, max]`.
|
|
344
351
|
*
|
|
345
|
-
* @param
|
|
346
|
-
* @param
|
|
352
|
+
* @param min - Lower bound.
|
|
353
|
+
* @param max - Upper bound.
|
|
347
354
|
*
|
|
348
|
-
* @throws
|
|
355
|
+
* @throws Error if `min` is greater than `max`.
|
|
349
356
|
*/
|
|
350
357
|
toClamped(min: PrecisionNumberValue, max: PrecisionNumberValue) {
|
|
351
358
|
return this.clone().clamp(min, max);
|
|
@@ -422,6 +429,7 @@ export class PrecisionNumber {
|
|
|
422
429
|
/**
|
|
423
430
|
* Converts the current value to a JavaScript number.
|
|
424
431
|
*
|
|
432
|
+
* @remarks
|
|
425
433
|
* Use `toString`/`value` when preserving decimal precision is more important than native-number ergonomics.
|
|
426
434
|
*/
|
|
427
435
|
toNumber() {
|
|
@@ -27,11 +27,16 @@ const loggerLevelStringToConsolaLogLevelMap = {
|
|
|
27
27
|
} as const;
|
|
28
28
|
|
|
29
29
|
export class SshClient {
|
|
30
|
+
// Private instance properties
|
|
30
31
|
readonly #connectConfig: Config;
|
|
31
32
|
readonly #logger: ConsolaInstance;
|
|
32
|
-
|
|
33
33
|
#nodeSsh: NodeSSH;
|
|
34
34
|
|
|
35
|
+
// Public instance properties
|
|
36
|
+
getDir = this.getDirectory;
|
|
37
|
+
putDir = this.putDirectory;
|
|
38
|
+
|
|
39
|
+
// Constructor
|
|
35
40
|
constructor(host: string, username: string, password: string, port: number = 22, connectConfig?: Config) {
|
|
36
41
|
this.#connectConfig = {
|
|
37
42
|
...connectConfig,
|
|
@@ -46,10 +51,12 @@ export class SshClient {
|
|
|
46
51
|
if (process.env.NODE_ENV === 'production') this.setLoggerLevel('error');
|
|
47
52
|
}
|
|
48
53
|
|
|
54
|
+
// Public instance accessors
|
|
49
55
|
get nodeSsh() {
|
|
50
56
|
return this.#nodeSsh;
|
|
51
57
|
}
|
|
52
58
|
|
|
59
|
+
// Public instance methods
|
|
53
60
|
async connect() {
|
|
54
61
|
try {
|
|
55
62
|
this.#nodeSsh = await this.#nodeSsh.connect(this.#connectConfig);
|
|
@@ -85,8 +92,6 @@ export class SshClient {
|
|
|
85
92
|
);
|
|
86
93
|
}
|
|
87
94
|
|
|
88
|
-
getDir = this.getDirectory;
|
|
89
|
-
|
|
90
95
|
async getDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) {
|
|
91
96
|
try {
|
|
92
97
|
return await this.#nodeSsh.getDirectory(localDirectory.toString(), remoteDirectory.toString(), options);
|
|
@@ -125,8 +130,6 @@ export class SshClient {
|
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
|
|
128
|
-
putDir = this.putDirectory;
|
|
129
|
-
|
|
130
133
|
async putDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) {
|
|
131
134
|
try {
|
|
132
135
|
return await this.#nodeSsh.putDirectory(localDirectory.toString(), remoteDirectory.toString(), options);
|
package/src/clipboard.ts
CHANGED
|
@@ -3,28 +3,28 @@ type CopyResult =
|
|
|
3
3
|
| { ok: true };
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Attempts to copy a
|
|
6
|
+
* Attempts to copy a blob to the browser clipboard.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* - Not supported in Safari and some older browsers.
|
|
8
|
+
* @remarks
|
|
9
|
+
* Requires a browser environment with clipboard support, a secure context, and any user activation required
|
|
10
|
+
* by the browser. Clipboard API failures are returned as results rather than rethrown.
|
|
12
11
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
12
|
+
* @param blob - The blob whose MIME type identifies the clipboard format.
|
|
13
|
+
* @param options - Options passed to the `ClipboardItem` constructor.
|
|
15
14
|
*
|
|
16
|
-
* @returns
|
|
17
|
-
*
|
|
18
|
-
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
15
|
+
* @returns A promise resolving after the copy attempt to `{ ok: true }` on success, or
|
|
16
|
+
* `{ ok: false, error }` with the failure reason.
|
|
19
17
|
*
|
|
20
18
|
* @example
|
|
21
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
22
21
|
* import { copyBlobToClipboard } from '@kikiutils/shared/clipboard';
|
|
23
22
|
*
|
|
23
|
+
* // Call from a user interaction in a supported browser.
|
|
24
24
|
* const blob = new Blob(['Hello world'], { type: 'text/plain' });
|
|
25
25
|
* const result = await copyBlobToClipboard(blob);
|
|
26
26
|
* if (result.ok) {
|
|
27
|
-
* console.log('Copied
|
|
27
|
+
* console.log('Copied!');
|
|
28
28
|
* } else {
|
|
29
29
|
* console.error('Copy failed:', result.error);
|
|
30
30
|
* }
|
|
@@ -51,24 +51,24 @@ export async function copyBlobToClipboard(blob: Blob, options?: ClipboardItemOpt
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Attempts to copy
|
|
54
|
+
* Attempts to copy text to the browser clipboard.
|
|
55
55
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* - Not supported in some older browsers (especially legacy Safari).
|
|
56
|
+
* @remarks
|
|
57
|
+
* Requires a browser environment with clipboard support, a secure context, and any user activation required
|
|
58
|
+
* by the browser. Clipboard API failures are returned as results rather than rethrown.
|
|
60
59
|
*
|
|
61
|
-
* @param
|
|
60
|
+
* @param text - The text to copy.
|
|
62
61
|
*
|
|
63
|
-
* @returns
|
|
64
|
-
*
|
|
65
|
-
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
62
|
+
* @returns A promise resolving after the copy attempt to `{ ok: true }` on success, or
|
|
63
|
+
* `{ ok: false, error }` with the failure reason.
|
|
66
64
|
*
|
|
67
65
|
* @example
|
|
68
|
-
*
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
69
68
|
* import { copyTextToClipboard } from '@kikiutils/shared/clipboard';
|
|
70
69
|
*
|
|
71
|
-
*
|
|
70
|
+
* // Call from a user interaction in a supported browser.
|
|
71
|
+
* const result = await copyTextToClipboard('Hello world');
|
|
72
72
|
* if (result.ok) {
|
|
73
73
|
* console.log('Copied!');
|
|
74
74
|
* } else {
|
package/src/consola.ts
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import { createConsola } from 'consola';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A consola logger
|
|
4
|
+
* A consola logger with environment-controlled verbosity.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* To manually change the level, assign the desired level to `logger.level`.
|
|
11
|
-
*
|
|
12
|
-
* See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).
|
|
6
|
+
* @remarks
|
|
7
|
+
* `CONSOLA_LOGGER_LEVEL` sets the log level when defined at module initialization;
|
|
8
|
+
* otherwise, `NODE_ENV=production` selects `0`, and other environments retain the logger's default level.
|
|
9
|
+
* Assign `logger.level` to change verbosity after initialization.
|
|
13
10
|
*
|
|
14
11
|
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { logger } from '@kikiutils/shared/consola';
|
|
17
12
|
*
|
|
18
|
-
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { logger } from '@kikiutils/shared/consola';
|
|
19
15
|
*
|
|
20
|
-
* // Manually change the level
|
|
21
16
|
* logger.level = 3;
|
|
17
|
+
* logger.info('Application started');
|
|
22
18
|
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://github.com/unjs/consola#log-level | Consola log levels}
|
|
23
21
|
*/
|
|
24
22
|
export const consolaLogger = createConsola();
|
|
25
23
|
export const logger = consolaLogger;
|
package/src/crypto-hash.ts
CHANGED
|
@@ -5,16 +5,17 @@ import type { BinaryLike } from 'node:crypto';
|
|
|
5
5
|
/**
|
|
6
6
|
* Computes the MD5 hash of the given data.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
8
|
+
* @param data - The input data to hash.
|
|
9
|
+
* @param outputEncoding - The output encoding. Defaults to `hex`.
|
|
10
10
|
*
|
|
11
|
-
* @returns
|
|
11
|
+
* @returns The hash digest in the specified encoding.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
15
16
|
* import { cryptoMd5 } from '@kikiutils/shared/crypto-hash';
|
|
16
17
|
*
|
|
17
|
-
* console.log(cryptoMd5('test')); // 098f6bcd4621d373cade4e832627b4f6
|
|
18
|
+
* console.log(cryptoMd5('test')); // => 098f6bcd4621d373cade4e832627b4f6
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
export function cryptoMd5(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
@@ -24,15 +25,16 @@ export function cryptoMd5(data: BinaryLike, outputEncoding: BufferEncoding = 'he
|
|
|
24
25
|
/**
|
|
25
26
|
* Computes the MD5 hash of the given data and returns the raw buffer.
|
|
26
27
|
*
|
|
27
|
-
* @param
|
|
28
|
+
* @param data - The input data to hash.
|
|
28
29
|
*
|
|
29
|
-
* @returns
|
|
30
|
+
* @returns A new `Buffer` containing the raw hash digest.
|
|
30
31
|
*
|
|
31
32
|
* @example
|
|
32
|
-
*
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
33
35
|
* import { cryptoMd5ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
34
36
|
*
|
|
35
|
-
* console.log(cryptoMd5ToBuffer('test')); // <Buffer
|
|
37
|
+
* console.log(cryptoMd5ToBuffer('test')); // => <Buffer 09 8f 6b cd ...>
|
|
36
38
|
* ```
|
|
37
39
|
*/
|
|
38
40
|
export function cryptoMd5ToBuffer(data: BinaryLike) {
|
|
@@ -42,16 +44,17 @@ export function cryptoMd5ToBuffer(data: BinaryLike) {
|
|
|
42
44
|
/**
|
|
43
45
|
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
44
46
|
*
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
+
* @param data - The input data to hash.
|
|
48
|
+
* @param outputEncoding - The output encoding. Defaults to `hex`.
|
|
47
49
|
*
|
|
48
|
-
* @returns
|
|
50
|
+
* @returns The hash digest in the specified encoding.
|
|
49
51
|
*
|
|
50
52
|
* @example
|
|
51
|
-
*
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
52
55
|
* import { cryptoSha3224 } from '@kikiutils/shared/crypto-hash';
|
|
53
56
|
*
|
|
54
|
-
* console.log(cryptoSha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
|
57
|
+
* console.log(cryptoSha3224('test')); // => 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
|
55
58
|
* ```
|
|
56
59
|
*/
|
|
57
60
|
export function cryptoSha3224(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
@@ -61,15 +64,16 @@ export function cryptoSha3224(data: BinaryLike, outputEncoding: BufferEncoding =
|
|
|
61
64
|
/**
|
|
62
65
|
* Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.
|
|
63
66
|
*
|
|
64
|
-
* @param
|
|
67
|
+
* @param data - The input data to hash.
|
|
65
68
|
*
|
|
66
|
-
* @returns
|
|
69
|
+
* @returns A new `Buffer` containing the raw hash digest.
|
|
67
70
|
*
|
|
68
71
|
* @example
|
|
69
|
-
*
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
70
74
|
* import { cryptoSha3224ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
71
75
|
*
|
|
72
|
-
* console.log(cryptoSha3224ToBuffer('test')); // <Buffer 37 97 bf 0a ...>
|
|
76
|
+
* console.log(cryptoSha3224ToBuffer('test')); // => <Buffer 37 97 bf 0a ...>
|
|
73
77
|
* ```
|
|
74
78
|
*/
|
|
75
79
|
export function cryptoSha3224ToBuffer(data: BinaryLike) {
|
|
@@ -79,16 +83,17 @@ export function cryptoSha3224ToBuffer(data: BinaryLike) {
|
|
|
79
83
|
/**
|
|
80
84
|
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
81
85
|
*
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
86
|
+
* @param data - The input data to hash.
|
|
87
|
+
* @param outputEncoding - The output encoding. Defaults to `hex`.
|
|
84
88
|
*
|
|
85
|
-
* @returns
|
|
89
|
+
* @returns The hash digest in the specified encoding.
|
|
86
90
|
*
|
|
87
91
|
* @example
|
|
88
|
-
*
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
89
94
|
* import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';
|
|
90
95
|
*
|
|
91
|
-
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
96
|
+
* console.log(cryptoSha3256('test')); // => 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
92
97
|
* ```
|
|
93
98
|
*/
|
|
94
99
|
export function cryptoSha3256(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
@@ -98,15 +103,16 @@ export function cryptoSha3256(data: BinaryLike, outputEncoding: BufferEncoding =
|
|
|
98
103
|
/**
|
|
99
104
|
* Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.
|
|
100
105
|
*
|
|
101
|
-
* @param
|
|
106
|
+
* @param data - The input data to hash.
|
|
102
107
|
*
|
|
103
|
-
* @returns
|
|
108
|
+
* @returns A new `Buffer` containing the raw hash digest.
|
|
104
109
|
*
|
|
105
110
|
* @example
|
|
106
|
-
*
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
107
113
|
* import { cryptoSha3256ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
108
114
|
*
|
|
109
|
-
* console.log(cryptoSha3256ToBuffer('test')); // <Buffer 36 f0 28 ...>
|
|
115
|
+
* console.log(cryptoSha3256ToBuffer('test')); // => <Buffer 36 f0 28 ...>
|
|
110
116
|
* ```
|
|
111
117
|
*/
|
|
112
118
|
export function cryptoSha3256ToBuffer(data: BinaryLike) {
|
|
@@ -116,16 +122,17 @@ export function cryptoSha3256ToBuffer(data: BinaryLike) {
|
|
|
116
122
|
/**
|
|
117
123
|
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
118
124
|
*
|
|
119
|
-
* @param
|
|
120
|
-
* @param
|
|
125
|
+
* @param data - The input data to hash.
|
|
126
|
+
* @param outputEncoding - The output encoding. Defaults to `hex`.
|
|
121
127
|
*
|
|
122
|
-
* @returns
|
|
128
|
+
* @returns The hash digest in the specified encoding.
|
|
123
129
|
*
|
|
124
130
|
* @example
|
|
125
|
-
*
|
|
131
|
+
*
|
|
132
|
+
* ```ts
|
|
126
133
|
* import { cryptoSha3384 } from '@kikiutils/shared/crypto-hash';
|
|
127
134
|
*
|
|
128
|
-
* console.log(cryptoSha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
|
|
135
|
+
* console.log(cryptoSha3384('test')); // => e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
|
|
129
136
|
* ```
|
|
130
137
|
*/
|
|
131
138
|
export function cryptoSha3384(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
@@ -135,15 +142,16 @@ export function cryptoSha3384(data: BinaryLike, outputEncoding: BufferEncoding =
|
|
|
135
142
|
/**
|
|
136
143
|
* Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.
|
|
137
144
|
*
|
|
138
|
-
* @param
|
|
145
|
+
* @param data - The input data to hash.
|
|
139
146
|
*
|
|
140
|
-
* @returns
|
|
147
|
+
* @returns A new `Buffer` containing the raw hash digest.
|
|
141
148
|
*
|
|
142
149
|
* @example
|
|
143
|
-
*
|
|
150
|
+
*
|
|
151
|
+
* ```ts
|
|
144
152
|
* import { cryptoSha3384ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
145
153
|
*
|
|
146
|
-
* console.log(cryptoSha3384ToBuffer('test')); // <Buffer e5 16 da bb ...>
|
|
154
|
+
* console.log(cryptoSha3384ToBuffer('test')); // => <Buffer e5 16 da bb ...>
|
|
147
155
|
* ```
|
|
148
156
|
*/
|
|
149
157
|
export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
@@ -153,16 +161,17 @@ export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
|
153
161
|
/**
|
|
154
162
|
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
155
163
|
*
|
|
156
|
-
* @param
|
|
157
|
-
* @param
|
|
164
|
+
* @param data - The input data to hash.
|
|
165
|
+
* @param outputEncoding - The output encoding. Defaults to `hex`.
|
|
158
166
|
*
|
|
159
|
-
* @returns
|
|
167
|
+
* @returns The hash digest in the specified encoding.
|
|
160
168
|
*
|
|
161
169
|
* @example
|
|
162
|
-
*
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
163
172
|
* import { cryptoSha3512 } from '@kikiutils/shared/crypto-hash';
|
|
164
173
|
*
|
|
165
|
-
* console.log(cryptoSha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
|
|
174
|
+
* console.log(cryptoSha3512('test')); // => 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
|
|
166
175
|
* ```
|
|
167
176
|
*/
|
|
168
177
|
export function cryptoSha3512(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
@@ -172,15 +181,16 @@ export function cryptoSha3512(data: BinaryLike, outputEncoding: BufferEncoding =
|
|
|
172
181
|
/**
|
|
173
182
|
* Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.
|
|
174
183
|
*
|
|
175
|
-
* @param
|
|
184
|
+
* @param data - The input data to hash.
|
|
176
185
|
*
|
|
177
|
-
* @returns
|
|
186
|
+
* @returns A new `Buffer` containing the raw hash digest.
|
|
178
187
|
*
|
|
179
188
|
* @example
|
|
180
|
-
*
|
|
189
|
+
*
|
|
190
|
+
* ```ts
|
|
181
191
|
* import { cryptoSha3512ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
182
192
|
*
|
|
183
|
-
* console.log(cryptoSha3512ToBuffer('test')); // <Buffer 9e ce 08 6e ...>
|
|
193
|
+
* console.log(cryptoSha3512ToBuffer('test')); // => <Buffer 9e ce 08 6e ...>
|
|
184
194
|
* ```
|
|
185
195
|
*/
|
|
186
196
|
export function cryptoSha3512ToBuffer(data: BinaryLike) {
|