@kikiutils/shared 18.0.1 → 18.2.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 +457 -0
  6. package/dist/classes/enhanced-date.d.ts.map +1 -0
  7. package/dist/classes/enhanced-date.js +635 -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 +188 -54
  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 +13 -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 +21 -21
  125. package/src/buffer.ts +18 -19
  126. package/src/classes/enhanced-date.ts +715 -0
  127. package/src/classes/path.ts +248 -96
  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
@@ -1,28 +1,24 @@
1
1
  import * as fsp from "node:fs/promises";
2
- import { basename, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve, toNamespacedPath } from "node:path";
2
+ import * as nodePath from "node:path";
3
3
  //#region src/classes/path.ts
4
4
  /**
5
- * Class representing a file system path with various utility methods for path operations.
5
+ * An immutable file system path with Node.js path and file operations.
6
6
  *
7
- * All methods in the `Path` class are immutable, returning new instances with modified values
8
- * and leaving the original instance unchanged.
7
+ * @remarks
8
+ * Path-composition methods return new instances and leave this instance unchanged.
9
+ * File operations act on the stored path and forward Node.js defaults and promise rejections.
10
+ * They do not update the stored path, including after a successful rename.
11
+ * The constructor joins stringified inputs using the platform-specific Node.js path rules.
9
12
  */
10
13
  var Path = class Path {
11
14
  #value;
12
15
  /**
13
16
  * Creates a normalized path value by joining the provided path segments.
14
17
  *
15
- * @param {PathLike[]} paths - Path segments accepted by Node.js `path.join` or another `Path` instance
18
+ * @param paths - Path segments accepted by Node.js `path.join` or another `Path` instance.
16
19
  */
17
20
  constructor(...paths) {
18
- this.#value = join(...this.#toStrings(paths));
19
- }
20
- [Symbol.for("nodejs.util.inspect.custom")]() {
21
- return this.#value;
22
- }
23
- [Symbol.toPrimitive](hint) {
24
- if (hint === "number") throw new TypeError("Cannot convert a Path to a number");
25
- return this.#value;
21
+ this.#value = nodePath.join(...this.#toStrings(paths));
26
22
  }
27
23
  #newInstance(...paths) {
28
24
  return new Path(...paths);
@@ -31,126 +27,222 @@ var Path = class Path {
31
27
  return paths.map((path) => path.toString());
32
28
  }
33
29
  /**
34
- * @see {@link nodePath.dirname}
30
+ * The parent directory as a new `Path`; this instance is unchanged.
31
+ *
32
+ * @see {@link Path.dirname}
35
33
  */
36
34
  get parent() {
37
35
  return this.dirname();
38
36
  }
39
37
  /**
40
- * Returns the internal path string value.
38
+ * The normalized path string stored by this instance.
41
39
  */
42
40
  get value() {
43
41
  return this.#value;
44
42
  }
45
43
  /**
46
- * @see {@link nodePath.format}
44
+ * Creates a new path from a Node.js path object.
45
+ *
46
+ * @param pathObject - The path components to format.
47
+ *
48
+ * @returns A new normalized `Path`.
49
+ *
50
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.format}
47
51
  */
48
52
  static format(pathObject) {
49
- return new Path(format(pathObject));
53
+ return new Path(nodePath.format(pathObject));
50
54
  }
51
55
  /**
52
- * @see {@link nodePath.resolve}
56
+ * Resolves joined path segments to an absolute path.
57
+ *
58
+ * @remarks
59
+ * Inputs are joined before resolution; unlike Node.js `path.resolve`,
60
+ * later absolute segments do not reset the path.
61
+ *
62
+ * @param paths - The stringified path segments to join.
63
+ *
64
+ * @returns A new absolute `Path`.
65
+ *
66
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}
53
67
  */
54
68
  static resolve(...paths) {
55
69
  return new this(...paths).resolve();
56
70
  }
71
+ [Symbol.for("nodejs.util.inspect.custom")]() {
72
+ return this.#value;
73
+ }
74
+ [Symbol.toPrimitive](hint) {
75
+ if (hint === "number") throw new TypeError("Cannot convert a Path to a number");
76
+ return this.#value;
77
+ }
57
78
  /**
58
- * @see {@link nodePath.basename}
79
+ * Returns the final component of this path.
80
+ *
81
+ * @param suffix - An optional exact suffix to remove.
82
+ *
83
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.basename}
59
84
  */
60
85
  basename(suffix) {
61
- return basename(this.#value, suffix);
86
+ return nodePath.basename(this.#value, suffix);
62
87
  }
63
88
  /**
64
- * @see {@link nodePath.dirname}
89
+ * Returns the parent directory of this path.
90
+ *
91
+ * @returns A new `Path`; this instance is unchanged.
92
+ *
93
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.dirname}
65
94
  */
66
95
  dirname() {
67
- return this.#newInstance(dirname(this.#value));
96
+ return this.#newInstance(nodePath.dirname(this.#value));
68
97
  }
69
98
  /**
70
- * @see {@link nodePath.extname}
99
+ * Returns the extension of the final path component.
100
+ *
101
+ * @returns The extension including its leading dot, or an empty string when absent.
102
+ *
103
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.extname}
71
104
  */
72
105
  extname() {
73
- return extname(this.#value);
106
+ return nodePath.extname(this.#value);
74
107
  }
75
108
  /**
76
- * @see {@link nodePath.isAbsolute}
109
+ * Checks whether this path is absolute on the current platform.
110
+ *
111
+ * @returns Whether this path is absolute.
112
+ *
113
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.isAbsolute}
77
114
  */
78
115
  isAbsolute() {
79
- return isAbsolute(this.#value);
116
+ return nodePath.isAbsolute(this.#value);
80
117
  }
81
118
  /**
82
- * @see {@link nodePath.normalize}
119
+ * Normalizes separators and relative segments in this path.
120
+ *
121
+ * @returns A new `Path`; this instance is unchanged.
122
+ *
123
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.normalize}
83
124
  */
84
125
  normalize() {
85
- return this.#newInstance(normalize(this.#value));
126
+ return this.#newInstance(nodePath.normalize(this.#value));
86
127
  }
87
128
  /**
88
- * @see {@link nodePath.join}
129
+ * Joins additional segments onto this path.
130
+ *
131
+ * @param paths - The stringified path segments to append.
132
+ *
133
+ * @returns A new normalized `Path`; this instance is unchanged.
134
+ *
135
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.join}
89
136
  */
90
137
  join(...paths) {
91
138
  return this.#newInstance(this.#value, ...this.#toStrings(paths));
92
139
  }
93
140
  /**
94
- * @see {@link nodePath.parse}
141
+ * Parses this path into its root, directory, basename, extension, and name.
142
+ *
143
+ * @returns A new object containing the path components.
144
+ *
145
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.parse}
95
146
  */
96
147
  parse() {
97
- return parse(this.#value);
148
+ return nodePath.parse(this.#value);
98
149
  }
99
150
  /**
100
- * @see {@link nodePath.relative}
151
+ * Computes a relative path from this path to the destination.
152
+ *
153
+ * @param to - The destination path.
154
+ *
155
+ * @returns A new `Path`; this instance is unchanged.
156
+ *
157
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.relative}
101
158
  */
102
159
  relative(to) {
103
- return this.#newInstance(relative(this.#value, to.toString()));
160
+ return this.#newInstance(nodePath.relative(this.#value, to.toString()));
104
161
  }
105
162
  /**
106
- * @see {@link nodePath.resolve}
163
+ * Resolves this path to an absolute path using the current working directory.
164
+ *
165
+ * @remarks
166
+ * Relative paths use the current working directory. This instance is unchanged.
167
+ *
168
+ * @returns A new absolute `Path`.
169
+ *
170
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}
107
171
  */
108
172
  resolve() {
109
- return this.#newInstance(resolve(this.#value));
173
+ return this.#newInstance(nodePath.resolve(this.#value));
110
174
  }
111
175
  toJSON() {
112
176
  return this.#value;
113
177
  }
114
178
  /**
115
- * @see {@link nodePath.toNamespacedPath}
179
+ * Converts this path to the Windows namespace form when applicable.
180
+ *
181
+ * @returns The namespace-converted path string; this instance is unchanged.
182
+ * On non-Windows platforms, the path text is unchanged.
183
+ *
184
+ * @see {@link https://nodejs.org/api/path.html | Node.js path.toNamespacedPath}
116
185
  */
117
186
  toNamespacedPath() {
118
- return toNamespacedPath(this.#value);
187
+ return nodePath.toNamespacedPath(this.#value);
119
188
  }
120
189
  /**
121
- * Converts the Path instance to a string.
122
- * This method returns the internal path string value,
123
- * making it useful for implicit and explicit string conversions.
190
+ * Returns the stored path as a string.
124
191
  */
125
192
  toString() {
126
193
  return this.#value;
127
194
  }
128
195
  /**
129
- * @see {@link fsp.access}
196
+ * Checks access permissions for the stored path.
197
+ *
198
+ * @remarks
199
+ * The promise resolves when the access check succeeds and rejects if access is denied or the path is missing.
200
+ *
201
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.access}
130
202
  */
131
203
  access(...args) {
132
204
  return fsp.access(this.#value, ...args);
133
205
  }
134
206
  /**
135
- * @see {@link fsp.appendFile}
207
+ * Appends data to the file at the stored path.
208
+ *
209
+ * @remarks
210
+ * The promise resolves when appending completes; a missing file is created according to the supplied options.
211
+ *
212
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.appendFile}
136
213
  */
137
214
  appendFile(...args) {
138
215
  return fsp.appendFile(this.#value, ...args);
139
216
  }
140
217
  /**
141
- * @see {@link fsp.chmod}
218
+ * Changes the permissions of the stored path.
219
+ *
220
+ * @remarks
221
+ * The promise resolves when the permissions are changed.
222
+ *
223
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chmod}
142
224
  */
143
225
  chmod(...args) {
144
226
  return fsp.chmod(this.#value, ...args);
145
227
  }
146
228
  /**
147
- * @see {@link fsp.chown}
229
+ * Changes the owner and group of the stored path.
230
+ *
231
+ * @remarks
232
+ * The promise resolves when the ownership is changed.
233
+ *
234
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chown}
148
235
  */
149
236
  chown(...args) {
150
237
  return fsp.chown(this.#value, ...args);
151
238
  }
152
239
  /**
153
- * @see {@link fsp.copyFile}
240
+ * Copies the file at the stored path to a destination.
241
+ *
242
+ * @remarks
243
+ * The promise resolves when copying completes. The stored path remains the source path.
244
+ *
245
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.copyFile}
154
246
  */
155
247
  copyFile(...args) {
156
248
  return fsp.copyFile(this.#value, ...args);
@@ -159,7 +251,12 @@ var Path = class Path {
159
251
  return fsp.mkdir(this.#value, ...args);
160
252
  }
161
253
  /**
162
- * @see {@link fsp.open}
254
+ * Opens the file at the stored path.
255
+ *
256
+ * @remarks
257
+ * The promise resolves to a new file handle. The caller must close the handle when it is no longer needed.
258
+ *
259
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.open}
163
260
  */
164
261
  open(...args) {
165
262
  return fsp.open(this.#value, ...args);
@@ -171,40 +268,77 @@ var Path = class Path {
171
268
  return fsp.readFile(this.#value, ...args);
172
269
  }
173
270
  /**
174
- * @see {@link fsp.rename}
271
+ * Renames or moves the file or directory at the stored path.
272
+ *
273
+ * @remarks
274
+ * The promise resolves when the rename completes. This instance retains its original stored path.
275
+ *
276
+ * @param newPath - The destination path; this instance retains its original value.
277
+ *
278
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rename}
175
279
  */
176
280
  rename(newPath) {
177
281
  return fsp.rename(this.#value, newPath.toString());
178
282
  }
179
283
  /**
180
- * @see {@link fsp.rm}
284
+ * Removes the file or directory at the stored path.
285
+ *
286
+ * @remarks
287
+ * The promise resolves after removal according to the supplied options.
288
+ *
289
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rm}
181
290
  */
182
291
  rm(...args) {
183
292
  return fsp.rm(this.#value, ...args);
184
293
  }
185
294
  /**
186
- * @see {@link fsp.rmdir}
295
+ * Removes the directory at the stored path.
296
+ *
297
+ * @remarks
298
+ * The promise resolves after directory removal.
299
+ *
300
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rmdir}
187
301
  */
188
302
  rmdir(...args) {
189
303
  return fsp.rmdir(this.#value, ...args);
190
304
  }
191
- stat(...args) {
192
- return fsp.stat(this.#value, ...args);
305
+ async stat(opts) {
306
+ try {
307
+ return await fsp.stat(this.#value, opts);
308
+ } catch (error) {
309
+ if (opts?.throwIfNoEntry === false && error instanceof Error && "code" in error && error.code === "ENOENT") return void 0;
310
+ throw error;
311
+ }
193
312
  }
194
313
  /**
195
- * @see {@link fsp.truncate}
314
+ * Truncates or extends the file at the stored path.
315
+ *
316
+ * @remarks
317
+ * The promise resolves when the file reaches the requested length in bytes; the default length is `0`.
318
+ *
319
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.truncate}
196
320
  */
197
321
  truncate(...args) {
198
322
  return fsp.truncate(this.#value, ...args);
199
323
  }
200
324
  /**
201
- * @see {@link fsp.unlink}
325
+ * Deletes the file or symbolic link at the stored path.
326
+ *
327
+ * @remarks
328
+ * The promise resolves after deletion; directories are not removed.
329
+ *
330
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.unlink}
202
331
  */
203
332
  unlink() {
204
333
  return fsp.unlink(this.#value);
205
334
  }
206
335
  /**
207
- * @see {@link fsp.writeFile}
336
+ * Writes data to the file at the stored path.
337
+ *
338
+ * @remarks
339
+ * The promise resolves when writing completes; the default flag replaces existing file contents.
340
+ *
341
+ * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.writeFile}
208
342
  */
209
343
  writeFile(...args) {
210
344
  return fsp.writeFile(this.#value, ...args);
@@ -1 +1 @@
1
- {"version":3,"file":"path.js","names":["#value","#toStrings","#newInstance"],"sources":["../../src/classes/path.ts"],"sourcesContent":["import type { Buffer } from 'node:buffer';\nimport type { Abortable } from 'node:events';\nimport type * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport {\n basename,\n dirname,\n extname,\n format,\n isAbsolute,\n join,\n normalize,\n parse,\n relative,\n resolve,\n toNamespacedPath,\n} from 'node:path';\nimport type * as nodePath from 'node:path';\n\ntype DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;\n\n/**\n * Values accepted by the `Path` constructor and path-composition methods.\n */\nexport type PathLike = fs.PathLike | Path;\n\n/**\n * Class representing a file system path with various utility methods for path operations.\n *\n * All methods in the `Path` class are immutable, returning new instances with modified values\n * and leaving the original instance unchanged.\n */\nexport class Path {\n readonly #value: string;\n\n /**\n * Creates a normalized path value by joining the provided path segments.\n *\n * @param {PathLike[]} paths - Path segments accepted by Node.js `path.join` or another `Path` instance\n */\n constructor(...paths: PathLike[]) {\n this.#value = join(...this.#toStrings(paths));\n }\n\n // Symbols\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return this.#value;\n }\n\n [Symbol.toPrimitive](hint: string) {\n if (hint === 'number') throw new TypeError('Cannot convert a Path to a number');\n return this.#value;\n }\n\n // Private methods\n #newInstance(...paths: PathLike[]) {\n return new Path(...paths);\n }\n\n #toStrings(paths: PathLike[]) {\n return paths.map((path) => path.toString());\n }\n\n // Public getters\n\n /**\n * @see {@link nodePath.dirname}\n */\n get parent() {\n return this.dirname();\n }\n\n /**\n * Returns the internal path string value.\n */\n get value() {\n return this.#value;\n }\n\n // Public static methods\n\n /**\n * @see {@link nodePath.format}\n */\n static format(pathObject: nodePath.FormatInputPathObject) {\n return new Path(format(pathObject));\n }\n\n /**\n * @see {@link nodePath.resolve}\n */\n static resolve(...paths: PathLike[]) {\n return new this(...paths).resolve();\n }\n\n // Public base methods\n\n /**\n * @see {@link nodePath.basename}\n */\n basename(suffix?: string) {\n return basename(this.#value, suffix);\n }\n\n /**\n * @see {@link nodePath.dirname}\n */\n dirname() {\n return this.#newInstance(dirname(this.#value));\n }\n\n /**\n * @see {@link nodePath.extname}\n */\n extname() {\n return extname(this.#value);\n }\n\n /**\n * @see {@link nodePath.isAbsolute}\n */\n isAbsolute() {\n return isAbsolute(this.#value);\n }\n\n /**\n * @see {@link nodePath.normalize}\n */\n normalize() {\n return this.#newInstance(normalize(this.#value));\n }\n\n /**\n * @see {@link nodePath.join}\n */\n join(...paths: PathLike[]) {\n return this.#newInstance(this.#value, ...this.#toStrings(paths));\n }\n\n /**\n * @see {@link nodePath.parse}\n */\n parse() {\n return parse(this.#value);\n }\n\n /**\n * @see {@link nodePath.relative}\n */\n relative(to: PathLike) {\n return this.#newInstance(relative(this.#value, to.toString()));\n }\n\n /**\n * @see {@link nodePath.resolve}\n */\n resolve() {\n return this.#newInstance(resolve(this.#value));\n }\n\n toJSON() {\n return this.#value;\n }\n\n /**\n * @see {@link nodePath.toNamespacedPath}\n */\n toNamespacedPath() {\n return toNamespacedPath(this.#value);\n }\n\n /**\n * Converts the Path instance to a string.\n * This method returns the internal path string value,\n * making it useful for implicit and explicit string conversions.\n */\n toString() {\n return this.#value;\n }\n\n // Some commonly used promise fs methods\n\n /**\n * @see {@link fsp.access}\n */\n access(...args: DropFirstParameters<typeof fsp.access>) {\n return fsp.access(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.appendFile}\n */\n appendFile(...args: DropFirstParameters<typeof fsp.appendFile>) {\n return fsp.appendFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.chmod}\n */\n chmod(...args: DropFirstParameters<typeof fsp.chmod>) {\n return fsp.chmod(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.chown}\n */\n chown(...args: DropFirstParameters<typeof fsp.chown>) {\n return fsp.chown(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.copyFile}\n */\n copyFile(...args: DropFirstParameters<typeof fsp.copyFile>) {\n return fsp.copyFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.mkdir}\n */\n mkdir(\n options: fs.MakeDirectoryOptions & {\n recursive: true;\n },\n ): Promise<string>;\n mkdir(\n options?:\n | (fs.MakeDirectoryOptions & {\n recursive?: false;\n })\n | fs.Mode\n | null,\n ): Promise<void>;\n mkdir(options?: fs.MakeDirectoryOptions | fs.Mode | null): Promise<string | undefined>;\n mkdir(...args: any): any {\n return fsp.mkdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.open}\n */\n open(...args: DropFirstParameters<typeof fsp.open>) {\n return fsp.open(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.readdir}\n */\n readdir(\n path: PathLike,\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<string[]>;\n readdir(\n path: PathLike,\n options:\n | 'buffer'\n | {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes?: false;\n },\n ): Promise<Buffer[]>;\n readdir(\n path: PathLike,\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<Buffer[] | string[]>;\n readdir(\n path: PathLike,\n options: fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent[]>;\n readdir(\n path: PathLike,\n options: {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent<Buffer>[]>;\n readdir(...args: any): any {\n return fsp.readdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.readFile}\n */\n readFile(\n options?:\n | (Abortable & {\n encoding?: null;\n flag?: fs.OpenMode;\n })\n | null,\n ): Promise<Buffer>;\n readFile(\n options:\n | (Abortable & {\n encoding: BufferEncoding;\n flag?: fs.OpenMode;\n })\n | BufferEncoding,\n ): Promise<string>;\n readFile(\n options?:\n | (\n & Abortable\n & fs.ObjectEncodingOptions\n & { flag?: fs.OpenMode }\n )\n | BufferEncoding\n | null,\n ): Promise<Buffer | string>;\n readFile(...args: any): any {\n return fsp.readFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.rename}\n */\n rename(newPath: PathLike) {\n return fsp.rename(this.#value, newPath.toString());\n }\n\n /**\n * @see {@link fsp.rm}\n */\n rm(...args: DropFirstParameters<typeof fsp.rm>) {\n return fsp.rm(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.rmdir}\n */\n rmdir(...args: DropFirstParameters<typeof fsp.rmdir>) {\n return fsp.rmdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.stat}\n */\n stat(\n opts?: fs.StatOptions & {\n bigint?: false;\n },\n ): Promise<fs.Stats>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n },\n ): Promise<fs.BigIntStats>;\n stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats>;\n stat(...args: any): any {\n return fsp.stat(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.truncate}\n */\n truncate(...args: DropFirstParameters<typeof fsp.truncate>) {\n return fsp.truncate(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.unlink}\n */\n unlink() {\n return fsp.unlink(this.#value);\n }\n\n /**\n * @see {@link fsp.writeFile}\n */\n writeFile(...args: DropFirstParameters<typeof fsp.writeFile>) {\n return fsp.writeFile(this.#value, ...args);\n }\n}\n"],"mappings":";;;;;;;;;AAgCA,IAAa,OAAb,MAAa,KAAK;CACd;;;;;;CAOA,YAAY,GAAG,OAAmB;EAC9B,KAAKA,SAAS,KAAK,GAAG,KAAKC,WAAW,KAAK,CAAC;CAChD;CAGA,CAAC,OAAO,IAAI,4BAA4B,KAAK;EACzC,OAAO,KAAKD;CAChB;CAEA,CAAC,OAAO,aAAa,MAAc;EAC/B,IAAI,SAAS,UAAU,MAAM,IAAI,UAAU,mCAAmC;EAC9E,OAAO,KAAKA;CAChB;CAGA,aAAa,GAAG,OAAmB;EAC/B,OAAO,IAAI,KAAK,GAAG,KAAK;CAC5B;CAEA,WAAW,OAAmB;EAC1B,OAAO,MAAM,KAAK,SAAS,KAAK,SAAS,CAAC;CAC9C;;;;CAOA,IAAI,SAAS;EACT,OAAO,KAAK,QAAQ;CACxB;;;;CAKA,IAAI,QAAQ;EACR,OAAO,KAAKA;CAChB;;;;CAOA,OAAO,OAAO,YAA4C;EACtD,OAAO,IAAI,KAAK,OAAO,UAAU,CAAC;CACtC;;;;CAKA,OAAO,QAAQ,GAAG,OAAmB;EACjC,OAAO,IAAI,KAAK,GAAG,KAAK,CAAC,CAAC,QAAQ;CACtC;;;;CAOA,SAAS,QAAiB;EACtB,OAAO,SAAS,KAAKA,QAAQ,MAAM;CACvC;;;;CAKA,UAAU;EACN,OAAO,KAAKE,aAAa,Q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AI,KAAK,KAAKA,QAAQ,GAAG,IAAI;CACxC;CAkDA,QAAQ,GAAG,MAAgB;EACvB,OAAO,IAAI,QAAQ,KAAKA,QAAQ,GAAG,IAAI;CAC3C;CA+BA,SAAS,GAAG,MAAgB;EACxB,OAAO,IAAI,SAAS,KAAKA,QAAQ,GAAG,IAAI;CAC5C;;;;CAKA,OAAO,SAAmB;EACtB,OAAO,IAAI,OAAO,KAAKA,QAAQ,QAAQ,SAAS,CAAC;CACrD;;;;CAKA,GAAG,GAAG,MAA0C;EAC5C,OAAO,IAAI,GAAG,KAAKA,QAAQ,GAAG,IAAI;CACtC;;;;CAKA,MAAM,GAAG,MAA6C;EAClD,OAAO,IAAI,MAAM,KAAKA,QAAQ,GAAG,IAAI;CACzC;CAgBA,KAAK,GAAG,MAAgB;EACpB,OAAO,IAAI,KAAK,KAAKA,QAAQ,GAAG,IAAI;CACxC;;;;CAKA,SAAS,GAAG,MAAgD;EACxD,OAAO,IAAI,SAAS,KAAKA,QAAQ,GAAG,IAAI;CAC5C;;;;CAKA,SAAS;EACL,OAAO,IAAI,OAAO,KAAKA,MAAM;CACjC;;;;CAKA,UAAU,GAAG,MAAiD;EAC1D,OAAO,IAAI,UAAU,KAAKA,QAAQ,GAAG,IAAI;CAC7C;AACJ"}
1
+ {"version":3,"file":"path.js","names":[],"sources":["../../src/classes/path.ts"],"sourcesContent":["import type { Buffer } from 'node:buffer';\nimport type { Abortable } from 'node:events';\nimport type * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport * as nodePath from 'node:path';\n\ntype DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;\n\n/**\n * Values accepted by the `Path` constructor and path-composition methods.\n */\nexport type PathLike = fs.PathLike | Path;\n\n/**\n * An immutable file system path with Node.js path and file operations.\n *\n * @remarks\n * Path-composition methods return new instances and leave this instance unchanged.\n * File operations act on the stored path and forward Node.js defaults and promise rejections.\n * They do not update the stored path, including after a successful rename.\n * The constructor joins stringified inputs using the platform-specific Node.js path rules.\n */\nexport class Path {\n // Private instance properties\n readonly #value: string;\n\n // Constructor\n\n /**\n * Creates a normalized path value by joining the provided path segments.\n *\n * @param paths - Path segments accepted by Node.js `path.join` or another `Path` instance.\n */\n constructor(...paths: PathLike[]) {\n this.#value = nodePath.join(...this.#toStrings(paths));\n }\n\n // Private instance methods\n #newInstance(...paths: PathLike[]) {\n return new Path(...paths);\n }\n\n #toStrings(paths: PathLike[]) {\n return paths.map((path) => path.toString());\n }\n\n // Public instance accessors\n\n /**\n * The parent directory as a new `Path`; this instance is unchanged.\n *\n * @see {@link Path.dirname}\n */\n get parent() {\n return this.dirname();\n }\n\n /**\n * The normalized path string stored by this instance.\n */\n get value() {\n return this.#value;\n }\n\n // Public static methods\n\n /**\n * Creates a new path from a Node.js path object.\n *\n * @param pathObject - The path components to format.\n *\n * @returns A new normalized `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.format}\n */\n static format(pathObject: nodePath.FormatInputPathObject) {\n return new Path(nodePath.format(pathObject));\n }\n\n /**\n * Resolves joined path segments to an absolute path.\n *\n * @remarks\n * Inputs are joined before resolution; unlike Node.js `path.resolve`,\n * later absolute segments do not reset the path.\n *\n * @param paths - The stringified path segments to join.\n *\n * @returns A new absolute `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}\n */\n static resolve(...paths: PathLike[]) {\n return new this(...paths).resolve();\n }\n\n // Public instance methods\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return this.#value;\n }\n\n [Symbol.toPrimitive](hint: string) {\n if (hint === 'number') throw new TypeError('Cannot convert a Path to a number');\n return this.#value;\n }\n\n /**\n * Returns the final component of this path.\n *\n * @param suffix - An optional exact suffix to remove.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.basename}\n */\n basename(suffix?: string) {\n return nodePath.basename(this.#value, suffix);\n }\n\n /**\n * Returns the parent directory of this path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.dirname}\n */\n dirname() {\n return this.#newInstance(nodePath.dirname(this.#value));\n }\n\n /**\n * Returns the extension of the final path component.\n *\n * @returns The extension including its leading dot, or an empty string when absent.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.extname}\n */\n extname() {\n return nodePath.extname(this.#value);\n }\n\n /**\n * Checks whether this path is absolute on the current platform.\n *\n * @returns Whether this path is absolute.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.isAbsolute}\n */\n isAbsolute() {\n return nodePath.isAbsolute(this.#value);\n }\n\n /**\n * Normalizes separators and relative segments in this path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.normalize}\n */\n normalize() {\n return this.#newInstance(nodePath.normalize(this.#value));\n }\n\n /**\n * Joins additional segments onto this path.\n *\n * @param paths - The stringified path segments to append.\n *\n * @returns A new normalized `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.join}\n */\n join(...paths: PathLike[]) {\n return this.#newInstance(this.#value, ...this.#toStrings(paths));\n }\n\n /**\n * Parses this path into its root, directory, basename, extension, and name.\n *\n * @returns A new object containing the path components.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.parse}\n */\n parse() {\n return nodePath.parse(this.#value);\n }\n\n /**\n * Computes a relative path from this path to the destination.\n *\n * @param to - The destination path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.relative}\n */\n relative(to: PathLike) {\n return this.#newInstance(nodePath.relative(this.#value, to.toString()));\n }\n\n /**\n * Resolves this path to an absolute path using the current working directory.\n *\n * @remarks\n * Relative paths use the current working directory. This instance is unchanged.\n *\n * @returns A new absolute `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}\n */\n resolve() {\n return this.#newInstance(nodePath.resolve(this.#value));\n }\n\n toJSON() {\n return this.#value;\n }\n\n /**\n * Converts this path to the Windows namespace form when applicable.\n *\n * @returns The namespace-converted path string; this instance is unchanged.\n * On non-Windows platforms, the path text is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.toNamespacedPath}\n */\n toNamespacedPath() {\n return nodePath.toNamespacedPath(this.#value);\n }\n\n /**\n * Returns the stored path as a string.\n */\n toString() {\n return this.#value;\n }\n\n /**\n * Checks access permissions for the stored path.\n *\n * @remarks\n * The promise resolves when the access check succeeds and rejects if access is denied or the path is missing.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.access}\n */\n access(...args: DropFirstParameters<typeof fsp.access>) {\n return fsp.access(this.#value, ...args);\n }\n\n /**\n * Appends data to the file at the stored path.\n *\n * @remarks\n * The promise resolves when appending completes; a missing file is created according to the supplied options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.appendFile}\n */\n appendFile(...args: DropFirstParameters<typeof fsp.appendFile>) {\n return fsp.appendFile(this.#value, ...args);\n }\n\n /**\n * Changes the permissions of the stored path.\n *\n * @remarks\n * The promise resolves when the permissions are changed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chmod}\n */\n chmod(...args: DropFirstParameters<typeof fsp.chmod>) {\n return fsp.chmod(this.#value, ...args);\n }\n\n /**\n * Changes the owner and group of the stored path.\n *\n * @remarks\n * The promise resolves when the ownership is changed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chown}\n */\n chown(...args: DropFirstParameters<typeof fsp.chown>) {\n return fsp.chown(this.#value, ...args);\n }\n\n /**\n * Copies the file at the stored path to a destination.\n *\n * @remarks\n * The promise resolves when copying completes. The stored path remains the source path.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.copyFile}\n */\n copyFile(...args: DropFirstParameters<typeof fsp.copyFile>) {\n return fsp.copyFile(this.#value, ...args);\n }\n\n /**\n * Creates a directory at the stored path.\n *\n * @remarks\n * The promise resolves after creation. Recursive mode resolves to the first created directory path, or\n * `undefined` if no directory is created; nonrecursive mode resolves without a value.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.mkdir}\n */\n mkdir(options: fs.MakeDirectoryOptions & { recursive: true }): Promise<string | undefined>;\n mkdir(\n options?:\n | (fs.MakeDirectoryOptions & { recursive?: false })\n | fs.Mode\n | null,\n ): Promise<void>;\n mkdir(options?: fs.MakeDirectoryOptions | fs.Mode | null): Promise<string | undefined>;\n mkdir(...args: any): any {\n return fsp.mkdir(this.#value, ...args);\n }\n\n /**\n * Opens the file at the stored path.\n *\n * @remarks\n * The promise resolves to a new file handle. The caller must close the handle when it is no longer needed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.open}\n */\n open(...args: DropFirstParameters<typeof fsp.open>) {\n return fsp.open(this.#value, ...args);\n }\n\n /**\n * Reads the entries of the directory at the stored path.\n *\n * @remarks\n * The promise resolves to names, buffers, or directory entries according to the options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.readdir}\n */\n readdir(\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<string[]>;\n readdir(\n options:\n | 'buffer'\n | {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes?: false;\n },\n ): Promise<Buffer[]>;\n readdir(\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<Buffer[] | string[]>;\n readdir(\n options: fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent[]>;\n readdir(\n options: {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent<Buffer>[]>;\n readdir(...args: any): any {\n return fsp.readdir(this.#value, ...args);\n }\n\n /**\n * Reads the entire file at the stored path.\n *\n * @remarks\n * The promise resolves to a string when a text encoding is supplied, or a `Buffer` otherwise.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.readFile}\n */\n readFile(\n options?:\n | (Abortable & {\n encoding?: null;\n flag?: fs.OpenMode;\n })\n | null,\n ): Promise<Buffer>;\n readFile(\n options:\n | (Abortable & {\n encoding: BufferEncoding;\n flag?: fs.OpenMode;\n })\n | BufferEncoding,\n ): Promise<string>;\n readFile(\n options?:\n | (\n & Abortable\n & fs.ObjectEncodingOptions\n & { flag?: fs.OpenMode }\n )\n | BufferEncoding\n | null,\n ): Promise<Buffer | string>;\n readFile(...args: any): any {\n return fsp.readFile(this.#value, ...args);\n }\n\n /**\n * Renames or moves the file or directory at the stored path.\n *\n * @remarks\n * The promise resolves when the rename completes. This instance retains its original stored path.\n *\n * @param newPath - The destination path; this instance retains its original value.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rename}\n */\n rename(newPath: PathLike) {\n return fsp.rename(this.#value, newPath.toString());\n }\n\n /**\n * Removes the file or directory at the stored path.\n *\n * @remarks\n * The promise resolves after removal according to the supplied options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rm}\n */\n rm(...args: DropFirstParameters<typeof fsp.rm>) {\n return fsp.rm(this.#value, ...args);\n }\n\n /**\n * Removes the directory at the stored path.\n *\n * @remarks\n * The promise resolves after directory removal.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rmdir}\n */\n rmdir(...args: DropFirstParameters<typeof fsp.rmdir>) {\n return fsp.rmdir(this.#value, ...args);\n }\n\n /**\n * Reads file system metadata for the stored path.\n *\n * @remarks\n * The promise resolves to `Stats`, or `BigIntStats` when `bigint` is enabled.\n * If `throwIfNoEntry` is `false`, a missing path resolves to `undefined` instead of rejecting.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.stat}\n */\n stat(\n opts?: fs.StatOptions & {\n bigint?: false;\n throwIfNoEntry?: true;\n },\n ): Promise<fs.Stats>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n throwIfNoEntry?: true;\n },\n ): Promise<fs.BigIntStats>;\n stat(\n opts: fs.StatOptions & {\n bigint?: false;\n throwIfNoEntry: false;\n },\n ): Promise<fs.Stats | undefined>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n throwIfNoEntry: false;\n },\n ): Promise<fs.BigIntStats | undefined>;\n stat(opts: fs.StatOptions & { throwIfNoEntry?: true }): Promise<fs.BigIntStats | fs.Stats>;\n stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined>;\n async stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined> {\n try {\n return await fsp.stat(this.#value, opts);\n } catch (error) {\n if (\n opts?.throwIfNoEntry === false\n && error instanceof Error\n && 'code' in error\n && error.code === 'ENOENT'\n ) return undefined;\n\n throw error;\n }\n }\n\n /**\n * Truncates or extends the file at the stored path.\n *\n * @remarks\n * The promise resolves when the file reaches the requested length in bytes; the default length is `0`.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.truncate}\n */\n truncate(...args: DropFirstParameters<typeof fsp.truncate>) {\n return fsp.truncate(this.#value, ...args);\n }\n\n /**\n * Deletes the file or symbolic link at the stored path.\n *\n * @remarks\n * The promise resolves after deletion; directories are not removed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.unlink}\n */\n unlink() {\n return fsp.unlink(this.#value);\n }\n\n /**\n * Writes data to the file at the stored path.\n *\n * @remarks\n * The promise resolves when writing completes; the default flag replaces existing file contents.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.writeFile}\n */\n writeFile(...args: DropFirstParameters<typeof fsp.writeFile>) {\n return fsp.writeFile(this.#value, ...args);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,IAAa,OAAb,MAAa,KAAK;CAEd;;;;;;CASA,YAAY,GAAG,OAAmB;EAC9B,KAAK,SAAS,SAAS,KAAK,GAAG,KAAK,WAAW,KAAK,CAAC;CACzD;CAGA,aAAa,GA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MAAM,GAAG,MAA6C;EAClD,OAAO,IAAI,MAAM,KAAK,QAAQ,GAAG,IAAI;CACzC;CAqCA,MAAM,KAAK,MAAuE;EAC9E,IAAI;GACA,OAAO,MAAM,IAAI,KAAK,KAAK,QAAQ,IAAI;EAC3C,SAAS,OAAO;GACZ,IACI,MAAM,mBAAmB,SACtB,iBAAiB,SACjB,UAAU,SACV,MAAM,SAAS,UACpB,OAAO,KAAA;GAET,MAAM;EACV;CACJ;;;;;;;;;CAUA,SAAS,GAAG,MAAgD;EACxD,OAAO,IAAI,SAAS,KAAK,QAAQ,GAAG,IAAI;CAC5C;;;;;;;;;CAUA,SAAS;EACL,OAAO,IAAI,OAAO,KAAK,MAAM;CACjC;;;;;;;;;CAUA,UAAU,GAAG,MAAiD;EAC1D,OAAO,IAAI,UAAU,KAAK,QAAQ,GAAG,IAAI;CAC7C;AACJ"}
@@ -3,44 +3,41 @@ import { Decimal } from "decimal.js";
3
3
  /**
4
4
  * Values accepted by `PrecisionNumber` constructors and arithmetic methods.
5
5
  */
6
- type PrecisionNumberValue = Decimal.Value | PrecisionNumber | {
6
+ export type PrecisionNumberValue = Decimal.Value | PrecisionNumber | {
7
7
  toString: () => string;
8
8
  };
9
9
  /**
10
- * Chainable fixed-decimal wrapper around `decimal.js`.
10
+ * A fixed-decimal number with mutable and immutable arithmetic operations.
11
11
  *
12
+ * @remarks
12
13
  * `PrecisionNumber` stores values as `Decimal`, rounds every mutating operation to
13
14
  * the configured decimal places, and exposes both mutable and immutable arithmetic
14
15
  * methods. Mutable methods (`plus`, `minus`, `times`, `dividedBy`, `modulo`,
15
16
  * `pow`, `clamp`, `ceil`, `floor`, `negate`, `absoluteValue`) update the current
16
17
  * instance and return `this`; immutable methods prefixed with `to` return a new
17
- * `PrecisionNumber` with the same precision settings.
18
+ * `PrecisionNumber` with the same precision settings, leaving this instance unchanged.
19
+ * Decimal.js exceptions propagate unchanged; non-finite arithmetic results are not converted into exceptions.
18
20
  *
19
21
  * @example
20
- * ```typescript
22
+ *
23
+ * ```ts
21
24
  * import { PrecisionNumber } from '@kikiutils/shared/classes/precision-number';
22
25
  *
23
26
  * const value = new PrecisionNumber('1.239', 2).plus('2.111');
24
- * value.toString(); // '3.35'
25
- * value.toMinus('1').toString(); // '2.35' (original value remains '3.35')
27
+ * value.toString(); // => '3.35'
28
+ * value.toMinus('1').toString(); // => '2.35' (original value remains '3.35')
26
29
  * ```
27
30
  */
28
- declare class PrecisionNumber {
31
+ export declare class PrecisionNumber {
29
32
  #private;
30
33
  /**
31
34
  * Creates a fixed-decimal number.
32
35
  *
33
- * @param {PrecisionNumberValue} [value] - Initial value (default: `'0'`)
34
- * @param {number} [decimalPlaces] - Decimal places retained after operations (default: `2`)
35
- * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)
36
+ * @param value - Initial value (default: `'0'`).
37
+ * @param decimalPlaces - Decimal places retained after operations (default: `2`).
38
+ * @param rounding - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`).
36
39
  */
37
40
  constructor(value?: PrecisionNumberValue, decimalPlaces?: number, rounding?: Decimal.Rounding);
38
- /**
39
- * Converts to a number for numeric coercion and to the fixed string otherwise.
40
- *
41
- * @param {string} hint - JavaScript primitive-conversion hint
42
- */
43
- [Symbol.toPrimitive](hint: string): string | number;
44
41
  /**
45
42
  * Decimal places retained by mutating operations and default formatting.
46
43
  */
@@ -56,36 +53,43 @@ declare class PrecisionNumber {
56
53
  /**
57
54
  * Formats a value with decimal.js without creating a reusable instance.
58
55
  *
59
- * @param {PrecisionNumberValue} value - Value to format
60
- * @param {number} [decimalPlaces] - Decimal places to output (default: `2`)
61
- * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)
56
+ * @param value - Value to format.
57
+ * @param decimalPlaces - Decimal places to output (default: `2`).
58
+ * @param rounding - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`).
62
59
  *
63
- * @returns {string} Fixed-decimal string
60
+ * @returns Fixed-decimal string.
64
61
  */
65
62
  static toFixed(value: PrecisionNumberValue, decimalPlaces?: number, rounding?: Decimal.Rounding): string;
63
+ /**
64
+ * Converts to a number for numeric coercion and to the fixed string otherwise.
65
+ *
66
+ * @param hint - JavaScript primitive-conversion hint.
67
+ */
68
+ [Symbol.toPrimitive](hint: string): string | number;
66
69
  /**
67
70
  * Replaces the current value with its absolute value.
68
71
  *
69
- * @returns {this} The current instance for chaining
72
+ * @returns This instance for chaining.
70
73
  */
71
74
  absoluteValue(): this;
72
75
  /**
73
76
  * Rounds the current value up to the nearest integer in place.
74
77
  *
78
+ * @remarks
75
79
  * The stored value still uses this instance's configured decimal places for output.
76
80
  *
77
- * @returns {this} The current instance for chaining
81
+ * @returns This instance for chaining.
78
82
  */
79
83
  ceil(): this;
80
84
  /**
81
85
  * Restricts the current value to the inclusive range `[min, max]` in place.
82
86
  *
83
- * @param {PrecisionNumberValue} min - Lower bound
84
- * @param {PrecisionNumberValue} max - Upper bound
87
+ * @param min - Lower bound.
88
+ * @param max - Upper bound.
85
89
  *
86
- * @returns {this} The current instance for chaining
90
+ * @returns This instance for chaining.
87
91
  *
88
- * @throws {Error} If `min` is greater than `max`
92
+ * @throws Error if `min` is greater than `max`.
89
93
  */
90
94
  clamp(min: PrecisionNumberValue, max: PrecisionNumberValue): this;
91
95
  /**
@@ -95,25 +99,26 @@ declare class PrecisionNumber {
95
99
  /**
96
100
  * Divides the current value by another value in place.
97
101
  *
98
- * @param {PrecisionNumberValue} value - Divisor
102
+ * @param value - Divisor.
99
103
  *
100
- * @returns {this} The current instance for chaining
104
+ * @returns This instance for chaining.
101
105
  */
102
106
  dividedBy(value: PrecisionNumberValue): this;
103
107
  /**
104
108
  * Checks whether the current value equals another value.
105
109
  *
106
- * @param {PrecisionNumberValue} value - Value to compare
110
+ * @param value - Value to compare.
107
111
  *
108
- * @returns {boolean} `true` when both numeric values are equal
112
+ * @returns Whether both numeric values are equal.
109
113
  */
110
114
  equals(value: PrecisionNumberValue): boolean;
111
115
  /**
112
116
  * Rounds the current value down to the nearest integer in place.
113
117
  *
118
+ * @remarks
114
119
  * The stored value still uses this instance's configured decimal places for output.
115
120
  *
116
- * @returns {this} The current instance for chaining
121
+ * @returns This instance for chaining.
117
122
  */
118
123
  floor(): this;
119
124
  /**
@@ -163,9 +168,9 @@ declare class PrecisionNumber {
163
168
  /**
164
169
  * Replaces the current value with the remainder after division by another value.
165
170
  *
166
- * @param {PrecisionNumberValue} value - Divisor used to compute the remainder
171
+ * @param value - Divisor used to compute the remainder.
167
172
  *
168
- * @returns {this} The current instance for chaining
173
+ * @returns This instance for chaining.
169
174
  */
170
175
  modulo(value: PrecisionNumberValue): this;
171
176
  /**
@@ -179,9 +184,9 @@ declare class PrecisionNumber {
179
184
  /**
180
185
  * Raises the current value to an exponent in place.
181
186
  *
182
- * @param {PrecisionNumberValue} value - Exponent
187
+ * @param value - Exponent.
183
188
  *
184
- * @returns {this} The current instance for chaining
189
+ * @returns This instance for chaining.
185
190
  */
186
191
  pow(value: PrecisionNumberValue): this;
187
192
  /**
@@ -199,10 +204,10 @@ declare class PrecisionNumber {
199
204
  /**
200
205
  * Returns a new instance restricted to the inclusive range `[min, max]`.
201
206
  *
202
- * @param {PrecisionNumberValue} min - Lower bound
203
- * @param {PrecisionNumberValue} max - Upper bound
207
+ * @param min - Lower bound.
208
+ * @param max - Upper bound.
204
209
  *
205
- * @throws {Error} If `min` is greater than `max`
210
+ * @throws Error if `min` is greater than `max`.
206
211
  */
207
212
  toClamped(min: PrecisionNumberValue, max: PrecisionNumberValue): PrecisionNumber;
208
213
  /**
@@ -240,6 +245,7 @@ declare class PrecisionNumber {
240
245
  /**
241
246
  * Converts the current value to a JavaScript number.
242
247
  *
248
+ * @remarks
243
249
  * Use `toString`/`value` when preserving decimal precision is more important than native-number ergonomics.
244
250
  */
245
251
  toNumber(): number;
@@ -257,5 +263,4 @@ declare class PrecisionNumber {
257
263
  toTimes(value: PrecisionNumberValue): PrecisionNumber;
258
264
  }
259
265
  //#endregion
260
- export { PrecisionNumber, PrecisionNumberValue };
261
266
  //# sourceMappingURL=precision-number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"precision-number.d.ts","names":[],"sources":["../../src/classes/precision-number.ts"],"mappings":";;;;;KAKY,uBAAuB,QAAQ,QAAQ;EAAoB;;;;;;;;;;;;;;;;;;;;;cAqB1D;;;;;;;;;EAcL,YAAA,QAAO,sBACP,wBACA,WAAU,QAAQ;;;;;;GAqBrB,OAAO,aAAa;;;;MAmBjB;;;;MAOA,YAAQ,QAAA;;;;MAOR;;;;;;;;;;SAaG,QACH,OAAO,sBACP,wBACA,WAAU,QAAQ;;;;;;EAYtB;;;;;;;;EAYA;;;;;;;;;;;EAeA,MAAM,KAAK,sBAAsB,KAAK;;;;EAWtC,SAAK;;;;;;;;EAWL,UAAU,OAAO;;;;;;;;EAYjB,OAAO,OAAO;;;;;;;;EAWd;;;;EAQA,GAAG,OAAO;;;;EAOV,IAAI,OAAO;;;;EAOX;;;;EAOA;;;;EAOA;;;;EAOA;;;;EAOA;;;;EAOA;;;;EAOA,GAAG,OAAO;;;;EAOV,IAAI,OAAO;;;;EAOX,MAAM,OAAO;;;;;;;;EAYb,OAAO,OAAO;;;;EAQd;;;;EAQA,KAAK,OAAO;;;;;;;;EAYZ,IAAI,OAAO;;;;EAQX,MAAM,OAAO;;;;EAQb,mBAAe;;;;EAOf,UAAM;;;;;;;;;EAYN,UAAU,KAAK,sBAAsB,KAAK,uBAAoB;;;;EAO9D,YAAY,OAAO,uBAAoB;;;;EAWvC,WAAO;;;;EAOP;;;;EAOA,QAAQ,OAAO,uBAAoB;;;;EAWnC,SAAS,OAAO,uBAAoB;;;;EAWpC,aAAS;;;;EAOT,OAAO,OAAO,uBAAoB;;;;EAOlC,MAAM,OAAO,uBAAoB;;;;;;EASjC;;;;EAOA;;;;EAOA,QAAQ,wBAA6C,WAAU,QAAQ;;;;EAOvE,QAAQ,OAAO,uBAAoB"}
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