@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.
Files changed (156) hide show
  1. package/dist/buffer.d.ts +19 -21
  2. package/dist/buffer.d.ts.map +1 -1
  3. package/dist/buffer.js +18 -19
  4. package/dist/buffer.js.map +1 -1
  5. package/dist/classes/enhanced-date.d.ts +425 -0
  6. package/dist/classes/enhanced-date.d.ts.map +1 -0
  7. package/dist/classes/enhanced-date.js +591 -0
  8. package/dist/classes/enhanced-date.js.map +1 -0
  9. package/dist/classes/path.d.ts +211 -48
  10. package/dist/classes/path.d.ts.map +1 -1
  11. package/dist/classes/path.js +181 -52
  12. package/dist/classes/path.js.map +1 -1
  13. package/dist/classes/precision-number.d.ts +44 -39
  14. package/dist/classes/precision-number.d.ts.map +1 -1
  15. package/dist/classes/precision-number.js +51 -45
  16. package/dist/classes/precision-number.js.map +1 -1
  17. package/dist/classes/ssh-client.d.ts +3 -4
  18. package/dist/classes/ssh-client.d.ts.map +1 -1
  19. package/dist/classes/ssh-client.js +2 -2
  20. package/dist/classes/ssh-client.js.map +1 -1
  21. package/dist/clipboard.d.ts +25 -26
  22. package/dist/clipboard.d.ts.map +1 -1
  23. package/dist/clipboard.js +23 -23
  24. package/dist/clipboard.js.map +1 -1
  25. package/dist/consola.d.ts +12 -15
  26. package/dist/consola.d.ts.map +1 -1
  27. package/dist/consola.js +10 -12
  28. package/dist/consola.js.map +1 -1
  29. package/dist/crypto-hash.d.ts +65 -56
  30. package/dist/crypto-hash.d.ts.map +1 -1
  31. package/dist/crypto-hash.js +55 -45
  32. package/dist/crypto-hash.js.map +1 -1
  33. package/dist/datetime.d.ts +41 -53
  34. package/dist/datetime.d.ts.map +1 -1
  35. package/dist/datetime.js +53 -66
  36. package/dist/datetime.js.map +1 -1
  37. package/dist/element-plus.d.ts +13 -14
  38. package/dist/element-plus.d.ts.map +1 -1
  39. package/dist/element-plus.js +11 -11
  40. package/dist/element-plus.js.map +1 -1
  41. package/dist/enum.d.ts +39 -36
  42. package/dist/enum.d.ts.map +1 -1
  43. package/dist/enum.js +36 -32
  44. package/dist/enum.js.map +1 -1
  45. package/dist/env.d.ts +22 -15
  46. package/dist/env.d.ts.map +1 -1
  47. package/dist/env.js +20 -12
  48. package/dist/env.js.map +1 -1
  49. package/dist/event-awaiter.d.ts +47 -52
  50. package/dist/event-awaiter.d.ts.map +1 -1
  51. package/dist/event-awaiter.js +46 -50
  52. package/dist/event-awaiter.js.map +1 -1
  53. package/dist/general.d.ts +22 -17
  54. package/dist/general.d.ts.map +1 -1
  55. package/dist/general.js.map +1 -1
  56. package/dist/hash.d.ts +24 -21
  57. package/dist/hash.d.ts.map +1 -1
  58. package/dist/hash.js +20 -16
  59. package/dist/hash.js.map +1 -1
  60. package/dist/math.d.ts +20 -19
  61. package/dist/math.d.ts.map +1 -1
  62. package/dist/math.js +14 -12
  63. package/dist/math.js.map +1 -1
  64. package/dist/number.d.ts +10 -9
  65. package/dist/number.d.ts.map +1 -1
  66. package/dist/number.js +9 -7
  67. package/dist/number.js.map +1 -1
  68. package/dist/object.d.ts +22 -10
  69. package/dist/object.d.ts.map +1 -1
  70. package/dist/object.js +21 -8
  71. package/dist/object.js.map +1 -1
  72. package/dist/pino.d.ts +12 -15
  73. package/dist/pino.d.ts.map +1 -1
  74. package/dist/pino.js +10 -15
  75. package/dist/pino.js.map +1 -1
  76. package/dist/random.d.ts +17 -15
  77. package/dist/random.d.ts.map +1 -1
  78. package/dist/random.js +16 -13
  79. package/dist/random.js.map +1 -1
  80. package/dist/redis/script-runner.d.ts +57 -0
  81. package/dist/redis/script-runner.d.ts.map +1 -0
  82. package/dist/redis/script-runner.js +46 -0
  83. package/dist/redis/script-runner.js.map +1 -0
  84. package/dist/storages/lru/keyed-store.d.ts +18 -14
  85. package/dist/storages/lru/keyed-store.d.ts.map +1 -1
  86. package/dist/storages/lru/keyed-store.js +17 -12
  87. package/dist/storages/lru/keyed-store.js.map +1 -1
  88. package/dist/storages/redis/keyed-store.d.ts +11 -21
  89. package/dist/storages/redis/keyed-store.d.ts.map +1 -1
  90. package/dist/storages/redis/keyed-store.js +10 -19
  91. package/dist/storages/redis/keyed-store.js.map +1 -1
  92. package/dist/storages/redis/msgpack.d.ts +33 -13
  93. package/dist/storages/redis/msgpack.d.ts.map +1 -1
  94. package/dist/storages/redis/msgpack.js +32 -11
  95. package/dist/storages/redis/msgpack.js.map +1 -1
  96. package/dist/storages/redis/types.d.ts +34 -17
  97. package/dist/storages/redis/types.d.ts.map +1 -1
  98. package/dist/string.d.ts +12 -11
  99. package/dist/string.d.ts.map +1 -1
  100. package/dist/string.js +20 -15
  101. package/dist/string.js.map +1 -1
  102. package/dist/time.d.ts +26 -21
  103. package/dist/time.d.ts.map +1 -1
  104. package/dist/time.js +24 -18
  105. package/dist/time.js.map +1 -1
  106. package/dist/types/filtered-key-path.d.ts +4 -15
  107. package/dist/types/filtered-key-path.d.ts.map +1 -1
  108. package/dist/types/index.d.ts +10 -10
  109. package/dist/types/index.d.ts.map +1 -1
  110. package/dist/types/vue.d.ts +7 -7
  111. package/dist/types/vue.d.ts.map +1 -1
  112. package/dist/url.d.ts +15 -14
  113. package/dist/url.d.ts.map +1 -1
  114. package/dist/url.js +12 -10
  115. package/dist/url.js.map +1 -1
  116. package/dist/vue.d.ts +19 -21
  117. package/dist/vue.d.ts.map +1 -1
  118. package/dist/vue.js +15 -16
  119. package/dist/vue.js.map +1 -1
  120. package/dist/web.d.ts +14 -11
  121. package/dist/web.d.ts.map +1 -1
  122. package/dist/web.js +12 -8
  123. package/dist/web.js.map +1 -1
  124. package/package.json +20 -20
  125. package/src/buffer.ts +18 -19
  126. package/src/classes/enhanced-date.ts +665 -0
  127. package/src/classes/path.ts +232 -91
  128. package/src/classes/precision-number.ts +61 -53
  129. package/src/classes/ssh-client.ts +8 -5
  130. package/src/clipboard.ts +23 -23
  131. package/src/consola.ts +10 -12
  132. package/src/crypto-hash.ts +55 -45
  133. package/src/datetime.ts +65 -85
  134. package/src/element-plus.ts +11 -11
  135. package/src/enum.ts +36 -32
  136. package/src/env.ts +20 -12
  137. package/src/event-awaiter.ts +49 -50
  138. package/src/general.ts +20 -14
  139. package/src/hash.ts +20 -16
  140. package/src/math.ts +18 -16
  141. package/src/number.ts +9 -7
  142. package/src/object.ts +21 -8
  143. package/src/pino.ts +11 -15
  144. package/src/random.ts +16 -13
  145. package/src/redis/script-runner.ts +107 -0
  146. package/src/storages/lru/keyed-store.ts +17 -12
  147. package/src/storages/redis/keyed-store.ts +10 -19
  148. package/src/storages/redis/msgpack.ts +32 -11
  149. package/src/storages/redis/types.ts +32 -14
  150. package/src/string.ts +10 -8
  151. package/src/time.ts +24 -18
  152. package/src/types/filtered-key-path.ts +9 -14
  153. package/src/types/vue.ts +6 -5
  154. package/src/url.ts +12 -10
  155. package/src/vue.ts +15 -16
  156. 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
- * Chainable fixed-decimal wrapper around `decimal.js`.
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
- * ```typescript
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 {PrecisionNumberValue} [value] - Initial value (default: `'0'`)
37
- * @param {number} [decimalPlaces] - Decimal places retained after operations (default: `2`)
38
- * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)
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
- // Symbols
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 getters
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 {PrecisionNumberValue} value - Value to format
105
- * @param {number} [decimalPlaces] - Decimal places to output (default: `2`)
106
- * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)
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 {string} Fixed-decimal string
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 {this} The current instance for chaining
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 {this} The current instance for chaining
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 {PrecisionNumberValue} min - Lower bound
146
- * @param {PrecisionNumberValue} max - Upper bound
151
+ * @param min - Lower bound.
152
+ * @param max - Upper bound.
147
153
  *
148
- * @returns {this} The current instance for chaining
154
+ * @returns This instance for chaining.
149
155
  *
150
- * @throws {Error} If `min` is greater than `max`
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 {PrecisionNumberValue} value - Divisor
176
+ * @param value - Divisor.
171
177
  *
172
- * @returns {this} The current instance for chaining
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 {PrecisionNumberValue} value - Value to compare
188
+ * @param value - Value to compare.
183
189
  *
184
- * @returns {boolean} `true` when both numeric values are equal
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 {this} The current instance for chaining
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 {PrecisionNumberValue} value - Divisor used to compute the remainder
290
+ * @param value - Divisor used to compute the remainder.
284
291
  *
285
- * @returns {this} The current instance for chaining
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 {PrecisionNumberValue} value - Exponent
318
+ * @param value - Exponent.
312
319
  *
313
- * @returns {this} The current instance for chaining
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 {PrecisionNumberValue} min - Lower bound
346
- * @param {PrecisionNumberValue} max - Upper bound
352
+ * @param min - Lower bound.
353
+ * @param max - Upper bound.
347
354
  *
348
- * @throws {Error} If `min` is greater than `max`
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 Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.
6
+ * Attempts to copy a blob to the browser clipboard.
7
7
  *
8
- * ⚠️ Usage Notes:
9
- * - Must be called in a **secure context** (HTTPS or localhost).
10
- * - Must be called **in response to a user interaction** (e.g. click, input).
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 {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content)
14
- * @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor
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 {Promise<CopyResult>} A promise resolving to a `CopyResult`:
17
- * - `{ ok: true }` if the copy succeeded
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
- * ```typescript
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 blob!');
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 the given text to the user's clipboard using the modern Clipboard API.
54
+ * Attempts to copy text to the browser clipboard.
55
55
  *
56
- * ⚠️ Usage Notes:
57
- * - Must be called in a **secure context** (HTTPS or localhost).
58
- * - Must be called **in response to a user interaction** (e.g. click, input).
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 {string} text - The string to be copied to the clipboard
60
+ * @param text - The text to copy.
62
61
  *
63
- * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
64
- * - `{ ok: true }` if the copy succeeded
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
- * ```typescript
66
+ *
67
+ * ```ts
69
68
  * import { copyTextToClipboard } from '@kikiutils/shared/clipboard';
70
69
  *
71
- * const result = await copyTextToClipboard('Hello!');
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 instance.
4
+ * A consola logger with environment-controlled verbosity.
5
5
  *
6
- * The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables.
7
- * If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,
8
- * the level will be set to `0`.
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
- * logger.info('test'); // ℹ test 3:56:30 AM
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;
@@ -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 {BinaryLike} data - The input data to hash
9
- * @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
8
+ * @param data - The input data to hash.
9
+ * @param outputEncoding - The output encoding. Defaults to `hex`.
10
10
  *
11
- * @returns {string | Buffer} The hash digest in the specified encoding
11
+ * @returns The hash digest in the specified encoding.
12
12
  *
13
13
  * @example
14
- * ```typescript
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 {BinaryLike} data - The input data to hash
28
+ * @param data - The input data to hash.
28
29
  *
29
- * @returns {Buffer} The raw hash digest as a Buffer
30
+ * @returns A new `Buffer` containing the raw hash digest.
30
31
  *
31
32
  * @example
32
- * ```typescript
33
+ *
34
+ * ```ts
33
35
  * import { cryptoMd5ToBuffer } from '@kikiutils/shared/crypto-hash';
34
36
  *
35
- * console.log(cryptoMd5ToBuffer('test')); // <Buffer 33 ed 9a ...>
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 {BinaryLike} data - The input data to hash
46
- * @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
47
+ * @param data - The input data to hash.
48
+ * @param outputEncoding - The output encoding. Defaults to `hex`.
47
49
  *
48
- * @returns {string | Buffer} The hash digest in the specified encoding
50
+ * @returns The hash digest in the specified encoding.
49
51
  *
50
52
  * @example
51
- * ```typescript
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 {BinaryLike} data - The input data to hash
67
+ * @param data - The input data to hash.
65
68
  *
66
- * @returns {Buffer} The raw hash digest as a Buffer
69
+ * @returns A new `Buffer` containing the raw hash digest.
67
70
  *
68
71
  * @example
69
- * ```typescript
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 {BinaryLike} data - The input data to hash
83
- * @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
86
+ * @param data - The input data to hash.
87
+ * @param outputEncoding - The output encoding. Defaults to `hex`.
84
88
  *
85
- * @returns {string | Buffer} The hash digest in the specified encoding
89
+ * @returns The hash digest in the specified encoding.
86
90
  *
87
91
  * @example
88
- * ```typescript
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 {BinaryLike} data - The input data to hash
106
+ * @param data - The input data to hash.
102
107
  *
103
- * @returns {Buffer} The raw hash digest as a Buffer
108
+ * @returns A new `Buffer` containing the raw hash digest.
104
109
  *
105
110
  * @example
106
- * ```typescript
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 {BinaryLike} data - The input data to hash
120
- * @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
125
+ * @param data - The input data to hash.
126
+ * @param outputEncoding - The output encoding. Defaults to `hex`.
121
127
  *
122
- * @returns {string | Buffer} The hash digest in the specified encoding
128
+ * @returns The hash digest in the specified encoding.
123
129
  *
124
130
  * @example
125
- * ```typescript
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 {BinaryLike} data - The input data to hash
145
+ * @param data - The input data to hash.
139
146
  *
140
- * @returns {Buffer} The raw hash digest as a Buffer
147
+ * @returns A new `Buffer` containing the raw hash digest.
141
148
  *
142
149
  * @example
143
- * ```typescript
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 {BinaryLike} data - The input data to hash
157
- * @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
164
+ * @param data - The input data to hash.
165
+ * @param outputEncoding - The output encoding. Defaults to `hex`.
158
166
  *
159
- * @returns {string | Buffer} The hash digest in the specified encoding
167
+ * @returns The hash digest in the specified encoding.
160
168
  *
161
169
  * @example
162
- * ```typescript
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 {BinaryLike} data - The input data to hash
184
+ * @param data - The input data to hash.
176
185
  *
177
- * @returns {Buffer} The raw hash digest as a Buffer
186
+ * @returns A new `Buffer` containing the raw hash digest.
178
187
  *
179
188
  * @example
180
- * ```typescript
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) {