@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.
- 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 +457 -0
- package/dist/classes/enhanced-date.d.ts.map +1 -0
- package/dist/classes/enhanced-date.js +635 -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 +188 -54
- 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 +13 -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 +21 -21
- package/src/buffer.ts +18 -19
- package/src/classes/enhanced-date.ts +715 -0
- package/src/classes/path.ts +248 -96
- 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
package/src/classes/path.ts
CHANGED
|
@@ -2,20 +2,7 @@ import type { Buffer } from 'node:buffer';
|
|
|
2
2
|
import type { Abortable } from 'node:events';
|
|
3
3
|
import type * as fs from 'node:fs';
|
|
4
4
|
import * as fsp from 'node:fs/promises';
|
|
5
|
-
import
|
|
6
|
-
basename,
|
|
7
|
-
dirname,
|
|
8
|
-
extname,
|
|
9
|
-
format,
|
|
10
|
-
isAbsolute,
|
|
11
|
-
join,
|
|
12
|
-
normalize,
|
|
13
|
-
parse,
|
|
14
|
-
relative,
|
|
15
|
-
resolve,
|
|
16
|
-
toNamespacedPath,
|
|
17
|
-
} from 'node:path';
|
|
18
|
-
import type * as nodePath from 'node:path';
|
|
5
|
+
import * as nodePath from 'node:path';
|
|
19
6
|
|
|
20
7
|
type DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;
|
|
21
8
|
|
|
@@ -25,34 +12,30 @@ type DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extend
|
|
|
25
12
|
export type PathLike = fs.PathLike | Path;
|
|
26
13
|
|
|
27
14
|
/**
|
|
28
|
-
*
|
|
15
|
+
* An immutable file system path with Node.js path and file operations.
|
|
29
16
|
*
|
|
30
|
-
*
|
|
31
|
-
* and
|
|
17
|
+
* @remarks
|
|
18
|
+
* Path-composition methods return new instances and leave this instance unchanged.
|
|
19
|
+
* File operations act on the stored path and forward Node.js defaults and promise rejections.
|
|
20
|
+
* They do not update the stored path, including after a successful rename.
|
|
21
|
+
* The constructor joins stringified inputs using the platform-specific Node.js path rules.
|
|
32
22
|
*/
|
|
33
23
|
export class Path {
|
|
24
|
+
// Private instance properties
|
|
34
25
|
readonly #value: string;
|
|
35
26
|
|
|
27
|
+
// Constructor
|
|
28
|
+
|
|
36
29
|
/**
|
|
37
30
|
* Creates a normalized path value by joining the provided path segments.
|
|
38
31
|
*
|
|
39
|
-
* @param
|
|
32
|
+
* @param paths - Path segments accepted by Node.js `path.join` or another `Path` instance.
|
|
40
33
|
*/
|
|
41
34
|
constructor(...paths: PathLike[]) {
|
|
42
|
-
this.#value = join(...this.#toStrings(paths));
|
|
35
|
+
this.#value = nodePath.join(...this.#toStrings(paths));
|
|
43
36
|
}
|
|
44
37
|
|
|
45
|
-
//
|
|
46
|
-
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
47
|
-
return this.#value;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
[Symbol.toPrimitive](hint: string) {
|
|
51
|
-
if (hint === 'number') throw new TypeError('Cannot convert a Path to a number');
|
|
52
|
-
return this.#value;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Private methods
|
|
38
|
+
// Private instance methods
|
|
56
39
|
#newInstance(...paths: PathLike[]) {
|
|
57
40
|
return new Path(...paths);
|
|
58
41
|
}
|
|
@@ -61,17 +44,19 @@ export class Path {
|
|
|
61
44
|
return paths.map((path) => path.toString());
|
|
62
45
|
}
|
|
63
46
|
|
|
64
|
-
// Public
|
|
47
|
+
// Public instance accessors
|
|
65
48
|
|
|
66
49
|
/**
|
|
67
|
-
*
|
|
50
|
+
* The parent directory as a new `Path`; this instance is unchanged.
|
|
51
|
+
*
|
|
52
|
+
* @see {@link Path.dirname}
|
|
68
53
|
*/
|
|
69
54
|
get parent() {
|
|
70
55
|
return this.dirname();
|
|
71
56
|
}
|
|
72
57
|
|
|
73
58
|
/**
|
|
74
|
-
*
|
|
59
|
+
* The normalized path string stored by this instance.
|
|
75
60
|
*/
|
|
76
61
|
get value() {
|
|
77
62
|
return this.#value;
|
|
@@ -80,82 +65,149 @@ export class Path {
|
|
|
80
65
|
// Public static methods
|
|
81
66
|
|
|
82
67
|
/**
|
|
83
|
-
*
|
|
68
|
+
* Creates a new path from a Node.js path object.
|
|
69
|
+
*
|
|
70
|
+
* @param pathObject - The path components to format.
|
|
71
|
+
*
|
|
72
|
+
* @returns A new normalized `Path`.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.format}
|
|
84
75
|
*/
|
|
85
76
|
static format(pathObject: nodePath.FormatInputPathObject) {
|
|
86
|
-
return new Path(format(pathObject));
|
|
77
|
+
return new Path(nodePath.format(pathObject));
|
|
87
78
|
}
|
|
88
79
|
|
|
89
80
|
/**
|
|
90
|
-
*
|
|
81
|
+
* Resolves joined path segments to an absolute path.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* Inputs are joined before resolution; unlike Node.js `path.resolve`,
|
|
85
|
+
* later absolute segments do not reset the path.
|
|
86
|
+
*
|
|
87
|
+
* @param paths - The stringified path segments to join.
|
|
88
|
+
*
|
|
89
|
+
* @returns A new absolute `Path`.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}
|
|
91
92
|
*/
|
|
92
93
|
static resolve(...paths: PathLike[]) {
|
|
93
94
|
return new this(...paths).resolve();
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
// Public
|
|
97
|
+
// Public instance methods
|
|
98
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
99
|
+
return this.#value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
[Symbol.toPrimitive](hint: string) {
|
|
103
|
+
if (hint === 'number') throw new TypeError('Cannot convert a Path to a number');
|
|
104
|
+
return this.#value;
|
|
105
|
+
}
|
|
97
106
|
|
|
98
107
|
/**
|
|
99
|
-
*
|
|
108
|
+
* Returns the final component of this path.
|
|
109
|
+
*
|
|
110
|
+
* @param suffix - An optional exact suffix to remove.
|
|
111
|
+
*
|
|
112
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.basename}
|
|
100
113
|
*/
|
|
101
114
|
basename(suffix?: string) {
|
|
102
|
-
return basename(this.#value, suffix);
|
|
115
|
+
return nodePath.basename(this.#value, suffix);
|
|
103
116
|
}
|
|
104
117
|
|
|
105
118
|
/**
|
|
106
|
-
*
|
|
119
|
+
* Returns the parent directory of 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.dirname}
|
|
107
124
|
*/
|
|
108
125
|
dirname() {
|
|
109
|
-
return this.#newInstance(dirname(this.#value));
|
|
126
|
+
return this.#newInstance(nodePath.dirname(this.#value));
|
|
110
127
|
}
|
|
111
128
|
|
|
112
129
|
/**
|
|
113
|
-
*
|
|
130
|
+
* Returns the extension of the final path component.
|
|
131
|
+
*
|
|
132
|
+
* @returns The extension including its leading dot, or an empty string when absent.
|
|
133
|
+
*
|
|
134
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.extname}
|
|
114
135
|
*/
|
|
115
136
|
extname() {
|
|
116
|
-
return extname(this.#value);
|
|
137
|
+
return nodePath.extname(this.#value);
|
|
117
138
|
}
|
|
118
139
|
|
|
119
140
|
/**
|
|
120
|
-
*
|
|
141
|
+
* Checks whether this path is absolute on the current platform.
|
|
142
|
+
*
|
|
143
|
+
* @returns Whether this path is absolute.
|
|
144
|
+
*
|
|
145
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.isAbsolute}
|
|
121
146
|
*/
|
|
122
147
|
isAbsolute() {
|
|
123
|
-
return isAbsolute(this.#value);
|
|
148
|
+
return nodePath.isAbsolute(this.#value);
|
|
124
149
|
}
|
|
125
150
|
|
|
126
151
|
/**
|
|
127
|
-
*
|
|
152
|
+
* Normalizes separators and relative segments in this path.
|
|
153
|
+
*
|
|
154
|
+
* @returns A new `Path`; this instance is unchanged.
|
|
155
|
+
*
|
|
156
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.normalize}
|
|
128
157
|
*/
|
|
129
158
|
normalize() {
|
|
130
|
-
return this.#newInstance(normalize(this.#value));
|
|
159
|
+
return this.#newInstance(nodePath.normalize(this.#value));
|
|
131
160
|
}
|
|
132
161
|
|
|
133
162
|
/**
|
|
134
|
-
*
|
|
163
|
+
* Joins additional segments onto this path.
|
|
164
|
+
*
|
|
165
|
+
* @param paths - The stringified path segments to append.
|
|
166
|
+
*
|
|
167
|
+
* @returns A new normalized `Path`; this instance is unchanged.
|
|
168
|
+
*
|
|
169
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.join}
|
|
135
170
|
*/
|
|
136
171
|
join(...paths: PathLike[]) {
|
|
137
172
|
return this.#newInstance(this.#value, ...this.#toStrings(paths));
|
|
138
173
|
}
|
|
139
174
|
|
|
140
175
|
/**
|
|
141
|
-
*
|
|
176
|
+
* Parses this path into its root, directory, basename, extension, and name.
|
|
177
|
+
*
|
|
178
|
+
* @returns A new object containing the path components.
|
|
179
|
+
*
|
|
180
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.parse}
|
|
142
181
|
*/
|
|
143
182
|
parse() {
|
|
144
|
-
return parse(this.#value);
|
|
183
|
+
return nodePath.parse(this.#value);
|
|
145
184
|
}
|
|
146
185
|
|
|
147
186
|
/**
|
|
148
|
-
*
|
|
187
|
+
* Computes a relative path from this path to the destination.
|
|
188
|
+
*
|
|
189
|
+
* @param to - The destination path.
|
|
190
|
+
*
|
|
191
|
+
* @returns A new `Path`; this instance is unchanged.
|
|
192
|
+
*
|
|
193
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.relative}
|
|
149
194
|
*/
|
|
150
195
|
relative(to: PathLike) {
|
|
151
|
-
return this.#newInstance(relative(this.#value, to.toString()));
|
|
196
|
+
return this.#newInstance(nodePath.relative(this.#value, to.toString()));
|
|
152
197
|
}
|
|
153
198
|
|
|
154
199
|
/**
|
|
155
|
-
*
|
|
200
|
+
* Resolves this path to an absolute path using the current working directory.
|
|
201
|
+
*
|
|
202
|
+
* @remarks
|
|
203
|
+
* Relative paths use the current working directory. This instance is unchanged.
|
|
204
|
+
*
|
|
205
|
+
* @returns A new absolute `Path`.
|
|
206
|
+
*
|
|
207
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}
|
|
156
208
|
*/
|
|
157
209
|
resolve() {
|
|
158
|
-
return this.#newInstance(resolve(this.#value));
|
|
210
|
+
return this.#newInstance(nodePath.resolve(this.#value));
|
|
159
211
|
}
|
|
160
212
|
|
|
161
213
|
toJSON() {
|
|
@@ -163,71 +215,97 @@ export class Path {
|
|
|
163
215
|
}
|
|
164
216
|
|
|
165
217
|
/**
|
|
166
|
-
*
|
|
218
|
+
* Converts this path to the Windows namespace form when applicable.
|
|
219
|
+
*
|
|
220
|
+
* @returns The namespace-converted path string; this instance is unchanged.
|
|
221
|
+
* On non-Windows platforms, the path text is unchanged.
|
|
222
|
+
*
|
|
223
|
+
* @see {@link https://nodejs.org/api/path.html | Node.js path.toNamespacedPath}
|
|
167
224
|
*/
|
|
168
225
|
toNamespacedPath() {
|
|
169
|
-
return toNamespacedPath(this.#value);
|
|
226
|
+
return nodePath.toNamespacedPath(this.#value);
|
|
170
227
|
}
|
|
171
228
|
|
|
172
229
|
/**
|
|
173
|
-
*
|
|
174
|
-
* This method returns the internal path string value,
|
|
175
|
-
* making it useful for implicit and explicit string conversions.
|
|
230
|
+
* Returns the stored path as a string.
|
|
176
231
|
*/
|
|
177
232
|
toString() {
|
|
178
233
|
return this.#value;
|
|
179
234
|
}
|
|
180
235
|
|
|
181
|
-
// Some commonly used promise fs methods
|
|
182
|
-
|
|
183
236
|
/**
|
|
184
|
-
*
|
|
237
|
+
* Checks access permissions for the stored path.
|
|
238
|
+
*
|
|
239
|
+
* @remarks
|
|
240
|
+
* The promise resolves when the access check succeeds and rejects if access is denied or the path is missing.
|
|
241
|
+
*
|
|
242
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.access}
|
|
185
243
|
*/
|
|
186
244
|
access(...args: DropFirstParameters<typeof fsp.access>) {
|
|
187
245
|
return fsp.access(this.#value, ...args);
|
|
188
246
|
}
|
|
189
247
|
|
|
190
248
|
/**
|
|
191
|
-
*
|
|
249
|
+
* Appends data to the file at the stored path.
|
|
250
|
+
*
|
|
251
|
+
* @remarks
|
|
252
|
+
* The promise resolves when appending completes; a missing file is created according to the supplied options.
|
|
253
|
+
*
|
|
254
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.appendFile}
|
|
192
255
|
*/
|
|
193
256
|
appendFile(...args: DropFirstParameters<typeof fsp.appendFile>) {
|
|
194
257
|
return fsp.appendFile(this.#value, ...args);
|
|
195
258
|
}
|
|
196
259
|
|
|
197
260
|
/**
|
|
198
|
-
*
|
|
261
|
+
* Changes the permissions of the stored path.
|
|
262
|
+
*
|
|
263
|
+
* @remarks
|
|
264
|
+
* The promise resolves when the permissions are changed.
|
|
265
|
+
*
|
|
266
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chmod}
|
|
199
267
|
*/
|
|
200
268
|
chmod(...args: DropFirstParameters<typeof fsp.chmod>) {
|
|
201
269
|
return fsp.chmod(this.#value, ...args);
|
|
202
270
|
}
|
|
203
271
|
|
|
204
272
|
/**
|
|
205
|
-
*
|
|
273
|
+
* Changes the owner and group of the stored path.
|
|
274
|
+
*
|
|
275
|
+
* @remarks
|
|
276
|
+
* The promise resolves when the ownership is changed.
|
|
277
|
+
*
|
|
278
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chown}
|
|
206
279
|
*/
|
|
207
280
|
chown(...args: DropFirstParameters<typeof fsp.chown>) {
|
|
208
281
|
return fsp.chown(this.#value, ...args);
|
|
209
282
|
}
|
|
210
283
|
|
|
211
284
|
/**
|
|
212
|
-
*
|
|
285
|
+
* Copies the file at the stored path to a destination.
|
|
286
|
+
*
|
|
287
|
+
* @remarks
|
|
288
|
+
* The promise resolves when copying completes. The stored path remains the source path.
|
|
289
|
+
*
|
|
290
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.copyFile}
|
|
213
291
|
*/
|
|
214
292
|
copyFile(...args: DropFirstParameters<typeof fsp.copyFile>) {
|
|
215
293
|
return fsp.copyFile(this.#value, ...args);
|
|
216
294
|
}
|
|
217
295
|
|
|
218
296
|
/**
|
|
219
|
-
*
|
|
297
|
+
* Creates a directory at the stored path.
|
|
298
|
+
*
|
|
299
|
+
* @remarks
|
|
300
|
+
* The promise resolves after creation. Recursive mode resolves to the first created directory path, or
|
|
301
|
+
* `undefined` if no directory is created; nonrecursive mode resolves without a value.
|
|
302
|
+
*
|
|
303
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.mkdir}
|
|
220
304
|
*/
|
|
221
|
-
mkdir(
|
|
222
|
-
options: fs.MakeDirectoryOptions & {
|
|
223
|
-
recursive: true;
|
|
224
|
-
},
|
|
225
|
-
): Promise<string>;
|
|
305
|
+
mkdir(options: fs.MakeDirectoryOptions & { recursive: true }): Promise<string | undefined>;
|
|
226
306
|
mkdir(
|
|
227
307
|
options?:
|
|
228
|
-
| (fs.MakeDirectoryOptions & {
|
|
229
|
-
recursive?: false;
|
|
230
|
-
})
|
|
308
|
+
| (fs.MakeDirectoryOptions & { recursive?: false })
|
|
231
309
|
| fs.Mode
|
|
232
310
|
| null,
|
|
233
311
|
): Promise<void>;
|
|
@@ -237,17 +315,26 @@ export class Path {
|
|
|
237
315
|
}
|
|
238
316
|
|
|
239
317
|
/**
|
|
240
|
-
*
|
|
318
|
+
* Opens the file at the stored path.
|
|
319
|
+
*
|
|
320
|
+
* @remarks
|
|
321
|
+
* The promise resolves to a new file handle. The caller must close the handle when it is no longer needed.
|
|
322
|
+
*
|
|
323
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.open}
|
|
241
324
|
*/
|
|
242
325
|
open(...args: DropFirstParameters<typeof fsp.open>) {
|
|
243
326
|
return fsp.open(this.#value, ...args);
|
|
244
327
|
}
|
|
245
328
|
|
|
246
329
|
/**
|
|
247
|
-
*
|
|
330
|
+
* Reads the entries of the directory at the stored path.
|
|
331
|
+
*
|
|
332
|
+
* @remarks
|
|
333
|
+
* The promise resolves to names, buffers, or directory entries according to the options.
|
|
334
|
+
*
|
|
335
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.readdir}
|
|
248
336
|
*/
|
|
249
337
|
readdir(
|
|
250
|
-
path: PathLike,
|
|
251
338
|
options?:
|
|
252
339
|
| BufferEncoding
|
|
253
340
|
| (fs.ObjectEncodingOptions & {
|
|
@@ -257,7 +344,6 @@ export class Path {
|
|
|
257
344
|
| null,
|
|
258
345
|
): Promise<string[]>;
|
|
259
346
|
readdir(
|
|
260
|
-
path: PathLike,
|
|
261
347
|
options:
|
|
262
348
|
| 'buffer'
|
|
263
349
|
| {
|
|
@@ -267,7 +353,6 @@ export class Path {
|
|
|
267
353
|
},
|
|
268
354
|
): Promise<Buffer[]>;
|
|
269
355
|
readdir(
|
|
270
|
-
path: PathLike,
|
|
271
356
|
options?:
|
|
272
357
|
| BufferEncoding
|
|
273
358
|
| (fs.ObjectEncodingOptions & {
|
|
@@ -277,14 +362,12 @@ export class Path {
|
|
|
277
362
|
| null,
|
|
278
363
|
): Promise<Buffer[] | string[]>;
|
|
279
364
|
readdir(
|
|
280
|
-
path: PathLike,
|
|
281
365
|
options: fs.ObjectEncodingOptions & {
|
|
282
366
|
recursive?: boolean;
|
|
283
367
|
withFileTypes: true;
|
|
284
368
|
},
|
|
285
369
|
): Promise<fs.Dirent[]>;
|
|
286
370
|
readdir(
|
|
287
|
-
path: PathLike,
|
|
288
371
|
options: {
|
|
289
372
|
encoding: 'buffer';
|
|
290
373
|
recursive?: boolean;
|
|
@@ -296,7 +379,12 @@ export class Path {
|
|
|
296
379
|
}
|
|
297
380
|
|
|
298
381
|
/**
|
|
299
|
-
*
|
|
382
|
+
* Reads the entire file at the stored path.
|
|
383
|
+
*
|
|
384
|
+
* @remarks
|
|
385
|
+
* The promise resolves to a string when a text encoding is supplied, or a `Buffer` otherwise.
|
|
386
|
+
*
|
|
387
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.readFile}
|
|
300
388
|
*/
|
|
301
389
|
readFile(
|
|
302
390
|
options?:
|
|
@@ -329,60 +417,124 @@ export class Path {
|
|
|
329
417
|
}
|
|
330
418
|
|
|
331
419
|
/**
|
|
332
|
-
*
|
|
420
|
+
* Renames or moves the file or directory at the stored path.
|
|
421
|
+
*
|
|
422
|
+
* @remarks
|
|
423
|
+
* The promise resolves when the rename completes. This instance retains its original stored path.
|
|
424
|
+
*
|
|
425
|
+
* @param newPath - The destination path; this instance retains its original value.
|
|
426
|
+
*
|
|
427
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rename}
|
|
333
428
|
*/
|
|
334
429
|
rename(newPath: PathLike) {
|
|
335
430
|
return fsp.rename(this.#value, newPath.toString());
|
|
336
431
|
}
|
|
337
432
|
|
|
338
433
|
/**
|
|
339
|
-
*
|
|
434
|
+
* Removes the file or directory at the stored path.
|
|
435
|
+
*
|
|
436
|
+
* @remarks
|
|
437
|
+
* The promise resolves after removal according to the supplied options.
|
|
438
|
+
*
|
|
439
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rm}
|
|
340
440
|
*/
|
|
341
441
|
rm(...args: DropFirstParameters<typeof fsp.rm>) {
|
|
342
442
|
return fsp.rm(this.#value, ...args);
|
|
343
443
|
}
|
|
344
444
|
|
|
345
445
|
/**
|
|
346
|
-
*
|
|
446
|
+
* Removes the directory at the stored path.
|
|
447
|
+
*
|
|
448
|
+
* @remarks
|
|
449
|
+
* The promise resolves after directory removal.
|
|
450
|
+
*
|
|
451
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rmdir}
|
|
347
452
|
*/
|
|
348
453
|
rmdir(...args: DropFirstParameters<typeof fsp.rmdir>) {
|
|
349
454
|
return fsp.rmdir(this.#value, ...args);
|
|
350
455
|
}
|
|
351
456
|
|
|
352
457
|
/**
|
|
353
|
-
*
|
|
458
|
+
* Reads file system metadata for the stored path.
|
|
459
|
+
*
|
|
460
|
+
* @remarks
|
|
461
|
+
* The promise resolves to `Stats`, or `BigIntStats` when `bigint` is enabled.
|
|
462
|
+
* If `throwIfNoEntry` is `false`, a missing path resolves to `undefined` instead of rejecting.
|
|
463
|
+
*
|
|
464
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.stat}
|
|
354
465
|
*/
|
|
355
466
|
stat(
|
|
356
467
|
opts?: fs.StatOptions & {
|
|
357
468
|
bigint?: false;
|
|
469
|
+
throwIfNoEntry?: true;
|
|
358
470
|
},
|
|
359
471
|
): Promise<fs.Stats>;
|
|
360
472
|
stat(
|
|
361
473
|
opts: fs.StatOptions & {
|
|
362
474
|
bigint: true;
|
|
475
|
+
throwIfNoEntry?: true;
|
|
363
476
|
},
|
|
364
477
|
): Promise<fs.BigIntStats>;
|
|
365
|
-
stat(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
478
|
+
stat(
|
|
479
|
+
opts: fs.StatOptions & {
|
|
480
|
+
bigint?: false;
|
|
481
|
+
throwIfNoEntry: false;
|
|
482
|
+
},
|
|
483
|
+
): Promise<fs.Stats | undefined>;
|
|
484
|
+
stat(
|
|
485
|
+
opts: fs.StatOptions & {
|
|
486
|
+
bigint: true;
|
|
487
|
+
throwIfNoEntry: false;
|
|
488
|
+
},
|
|
489
|
+
): Promise<fs.BigIntStats | undefined>;
|
|
490
|
+
stat(opts: fs.StatOptions & { throwIfNoEntry?: true }): Promise<fs.BigIntStats | fs.Stats>;
|
|
491
|
+
stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined>;
|
|
492
|
+
async stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined> {
|
|
493
|
+
try {
|
|
494
|
+
return await fsp.stat(this.#value, opts);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
if (
|
|
497
|
+
opts?.throwIfNoEntry === false
|
|
498
|
+
&& error instanceof Error
|
|
499
|
+
&& 'code' in error
|
|
500
|
+
&& error.code === 'ENOENT'
|
|
501
|
+
) return undefined;
|
|
502
|
+
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Truncates or extends the file at the stored path.
|
|
509
|
+
*
|
|
510
|
+
* @remarks
|
|
511
|
+
* The promise resolves when the file reaches the requested length in bytes; the default length is `0`.
|
|
512
|
+
*
|
|
513
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.truncate}
|
|
372
514
|
*/
|
|
373
515
|
truncate(...args: DropFirstParameters<typeof fsp.truncate>) {
|
|
374
516
|
return fsp.truncate(this.#value, ...args);
|
|
375
517
|
}
|
|
376
518
|
|
|
377
519
|
/**
|
|
378
|
-
*
|
|
520
|
+
* Deletes the file or symbolic link at the stored path.
|
|
521
|
+
*
|
|
522
|
+
* @remarks
|
|
523
|
+
* The promise resolves after deletion; directories are not removed.
|
|
524
|
+
*
|
|
525
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.unlink}
|
|
379
526
|
*/
|
|
380
527
|
unlink() {
|
|
381
528
|
return fsp.unlink(this.#value);
|
|
382
529
|
}
|
|
383
530
|
|
|
384
531
|
/**
|
|
385
|
-
*
|
|
532
|
+
* Writes data to the file at the stored path.
|
|
533
|
+
*
|
|
534
|
+
* @remarks
|
|
535
|
+
* The promise resolves when writing completes; the default flag replaces existing file contents.
|
|
536
|
+
*
|
|
537
|
+
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.writeFile}
|
|
386
538
|
*/
|
|
387
539
|
writeFile(...args: DropFirstParameters<typeof fsp.writeFile>) {
|
|
388
540
|
return fsp.writeFile(this.#value, ...args);
|