@d0paminedriven/fs 5.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -0
- package/dist/chunk-4X5DVWVM.js +14 -0
- package/dist/{chunk-HWF53VET.js → chunk-73BXX52B.js} +162 -27
- package/dist/fs/index.cjs +168 -26
- package/dist/fs/index.d.cts +85 -2
- package/dist/fs/index.d.ts +85 -2
- package/dist/fs/index.js +2 -1
- package/dist/index.cjs +172 -28
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -2
- package/dist/types/index.cjs +19 -0
- package/dist/types/index.d.cts +19 -3
- package/dist/types/index.d.ts +19 -3
- package/dist/types/index.js +7 -0
- package/package.json +7 -7
package/dist/fs/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import expand from 'dotenv-expand';
|
|
2
2
|
import sharp from 'sharp';
|
|
3
|
-
import { ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, RmDirOptions } from '../types/index.cjs';
|
|
3
|
+
import { ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, Unit, SizeOpts, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, RmDirOptions } from '../types/index.cjs';
|
|
4
4
|
import { MimeService } from '../mime/index.cjs';
|
|
5
5
|
import 'stream';
|
|
6
6
|
import 'buffer';
|
|
@@ -11,20 +11,97 @@ declare class Fs extends MimeService {
|
|
|
11
11
|
constructor(cwd: string);
|
|
12
12
|
private get myEnv();
|
|
13
13
|
parseDotEnv(): expand.DotenvExpandOutput;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param target path to the file or directory to check for existence
|
|
17
|
+
* @returns true if the file or directory exists, false otherwise
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const fs = new Fs(process.cwd());
|
|
21
|
+
* const exists = fs.exists("my-file.txt");
|
|
22
|
+
* console.log(exists); // true if the file exists, false otherwise
|
|
23
|
+
* ```
|
|
24
|
+
* @description
|
|
25
|
+
* This method checks if a file or directory exists at the specified path input
|
|
26
|
+
*
|
|
27
|
+
* Additional Note:
|
|
28
|
+
*
|
|
29
|
+
* say you have a directory that begins with a dot, such as `.turbo`;
|
|
30
|
+
*
|
|
31
|
+
* in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
14
34
|
exists<const T extends string>(target: T): boolean;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param ms milliseconds to wait
|
|
38
|
+
* @returns a promise that resolves after the specified number of milliseconds
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const fs = new Fs(process.cwd());
|
|
42
|
+
* await fs.wait(1000); // waits for 1 second
|
|
43
|
+
* console.log("Done waiting!");
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* Alternatively, you can use it like this:
|
|
47
|
+
* ```ts
|
|
48
|
+
* const fs = new Fs(process.cwd());
|
|
49
|
+
* fs.wait(1000).then(() => { // waits for 1 second
|
|
50
|
+
* console.log("Done waiting!");
|
|
51
|
+
* // do something after waiting
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @description
|
|
56
|
+
* This method is useful for delaying execution in asynchronous code, such as when you need to wait for a file operation to complete or when you want to introduce a delay in a loop.
|
|
57
|
+
*/
|
|
15
58
|
wait<T extends number>(ms: T): Promise<unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
|
|
61
|
+
* @param arr An array or readonly array of strings and/or Buffers
|
|
62
|
+
* @returns An array of strings with Buffers converted to UTF-8 strings.
|
|
63
|
+
*/
|
|
16
64
|
handleBuffStrArrUnion<const T extends (string | Buffer)[] | readonly (string | Buffer)[]>(arr: T): string[];
|
|
17
65
|
isRootPathTargeted<const T extends string>(path: T): boolean;
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param path path to the directory relative to the cwd
|
|
69
|
+
* @param options options for reading the directory, defaults to recursive
|
|
70
|
+
*
|
|
71
|
+
* The following two examples are equivalent:
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const fs = new Fs(process.cwd());
|
|
76
|
+
* const files = fs.readDir("./my-directory", { recursive: true });
|
|
77
|
+
* console.log(files);
|
|
78
|
+
* ```
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const fs = new Fs(process.cwd());
|
|
82
|
+
* const files = fs.readDir("my-directory", { recursive: true });
|
|
83
|
+
* console.log(files);
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @returns an array of strings representing the contents of the directory
|
|
87
|
+
*/
|
|
18
88
|
readDir<const T extends string>(path: T, options?: ReadDirOptions): string[];
|
|
19
89
|
executeCommand: <const T extends string>({ command, ...options }: ExecuteCommandProps<T>) => string;
|
|
20
90
|
existsSync<const T extends string>(path: T): boolean;
|
|
21
91
|
pathHandler<const T extends string>(path: T): string;
|
|
22
92
|
mkdirSync<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
|
|
93
|
+
private units;
|
|
94
|
+
private u;
|
|
95
|
+
autoFileSizeRaw(size: number | bigint): {
|
|
96
|
+
value: number;
|
|
97
|
+
unit: "B" | "KB" | "MB" | "GB" | "TB" | "PB" | undefined;
|
|
98
|
+
};
|
|
99
|
+
getSize<const S extends Unit | Lowercase<Unit> | "auto">(size: number | bigint, target: S, opts?: SizeOpts): string | number;
|
|
23
100
|
fileSizeMb<const T extends string>(path: T): number;
|
|
101
|
+
fileSize<const T extends string, const S extends Unit | Lowercase<Unit> | "auto">(path: T, target: S, opts?: SizeOpts): string | number;
|
|
24
102
|
generateDirIfDNE<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
|
|
25
103
|
withWs<const T extends string>(path: T, data: WriteStreamDataShape, options?: WriteStreamOptions): string | boolean | undefined;
|
|
26
104
|
writeFileAsync: <const T extends string>(path: T, data: WriteFileAsyncDataUnion, options?: WriteFileAsyncOptions) => Promise<string | void>;
|
|
27
|
-
dirExists<const T extends string>(dir: T): boolean;
|
|
28
105
|
unlink<const P extends string>(path: P): Promise<void>;
|
|
29
106
|
rmFile<const FP extends string>(filePath: FP): void;
|
|
30
107
|
rmdir<const D extends string>(dir: D, options?: RmDirOptions): Promise<void>;
|
|
@@ -55,6 +132,12 @@ declare class Fs extends MimeService {
|
|
|
55
132
|
*/
|
|
56
133
|
fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
57
134
|
fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* @access package-private
|
|
138
|
+
*
|
|
139
|
+
* work in progress, for internal package maintainer use only
|
|
140
|
+
*/
|
|
58
141
|
imageTransform<const F extends "webp" | "avif" | "jpg" | "png" | "tif" | "tiff" | "jp2" | "jpeg">({ format, target, quality, tint, resize }: {
|
|
59
142
|
format: F;
|
|
60
143
|
target: Buffer<ArrayBuffer>;
|
package/dist/fs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import expand from 'dotenv-expand';
|
|
2
2
|
import sharp from 'sharp';
|
|
3
|
-
import { ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, RmDirOptions } from '../types/index.js';
|
|
3
|
+
import { ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, Unit, SizeOpts, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, RmDirOptions } from '../types/index.js';
|
|
4
4
|
import { MimeService } from '../mime/index.js';
|
|
5
5
|
import 'stream';
|
|
6
6
|
import 'buffer';
|
|
@@ -11,20 +11,97 @@ declare class Fs extends MimeService {
|
|
|
11
11
|
constructor(cwd: string);
|
|
12
12
|
private get myEnv();
|
|
13
13
|
parseDotEnv(): expand.DotenvExpandOutput;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param target path to the file or directory to check for existence
|
|
17
|
+
* @returns true if the file or directory exists, false otherwise
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const fs = new Fs(process.cwd());
|
|
21
|
+
* const exists = fs.exists("my-file.txt");
|
|
22
|
+
* console.log(exists); // true if the file exists, false otherwise
|
|
23
|
+
* ```
|
|
24
|
+
* @description
|
|
25
|
+
* This method checks if a file or directory exists at the specified path input
|
|
26
|
+
*
|
|
27
|
+
* Additional Note:
|
|
28
|
+
*
|
|
29
|
+
* say you have a directory that begins with a dot, such as `.turbo`;
|
|
30
|
+
*
|
|
31
|
+
* in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
14
34
|
exists<const T extends string>(target: T): boolean;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param ms milliseconds to wait
|
|
38
|
+
* @returns a promise that resolves after the specified number of milliseconds
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const fs = new Fs(process.cwd());
|
|
42
|
+
* await fs.wait(1000); // waits for 1 second
|
|
43
|
+
* console.log("Done waiting!");
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* Alternatively, you can use it like this:
|
|
47
|
+
* ```ts
|
|
48
|
+
* const fs = new Fs(process.cwd());
|
|
49
|
+
* fs.wait(1000).then(() => { // waits for 1 second
|
|
50
|
+
* console.log("Done waiting!");
|
|
51
|
+
* // do something after waiting
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @description
|
|
56
|
+
* This method is useful for delaying execution in asynchronous code, such as when you need to wait for a file operation to complete or when you want to introduce a delay in a loop.
|
|
57
|
+
*/
|
|
15
58
|
wait<T extends number>(ms: T): Promise<unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
|
|
61
|
+
* @param arr An array or readonly array of strings and/or Buffers
|
|
62
|
+
* @returns An array of strings with Buffers converted to UTF-8 strings.
|
|
63
|
+
*/
|
|
16
64
|
handleBuffStrArrUnion<const T extends (string | Buffer)[] | readonly (string | Buffer)[]>(arr: T): string[];
|
|
17
65
|
isRootPathTargeted<const T extends string>(path: T): boolean;
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param path path to the directory relative to the cwd
|
|
69
|
+
* @param options options for reading the directory, defaults to recursive
|
|
70
|
+
*
|
|
71
|
+
* The following two examples are equivalent:
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const fs = new Fs(process.cwd());
|
|
76
|
+
* const files = fs.readDir("./my-directory", { recursive: true });
|
|
77
|
+
* console.log(files);
|
|
78
|
+
* ```
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const fs = new Fs(process.cwd());
|
|
82
|
+
* const files = fs.readDir("my-directory", { recursive: true });
|
|
83
|
+
* console.log(files);
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @returns an array of strings representing the contents of the directory
|
|
87
|
+
*/
|
|
18
88
|
readDir<const T extends string>(path: T, options?: ReadDirOptions): string[];
|
|
19
89
|
executeCommand: <const T extends string>({ command, ...options }: ExecuteCommandProps<T>) => string;
|
|
20
90
|
existsSync<const T extends string>(path: T): boolean;
|
|
21
91
|
pathHandler<const T extends string>(path: T): string;
|
|
22
92
|
mkdirSync<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
|
|
93
|
+
private units;
|
|
94
|
+
private u;
|
|
95
|
+
autoFileSizeRaw(size: number | bigint): {
|
|
96
|
+
value: number;
|
|
97
|
+
unit: "B" | "KB" | "MB" | "GB" | "TB" | "PB" | undefined;
|
|
98
|
+
};
|
|
99
|
+
getSize<const S extends Unit | Lowercase<Unit> | "auto">(size: number | bigint, target: S, opts?: SizeOpts): string | number;
|
|
23
100
|
fileSizeMb<const T extends string>(path: T): number;
|
|
101
|
+
fileSize<const T extends string, const S extends Unit | Lowercase<Unit> | "auto">(path: T, target: S, opts?: SizeOpts): string | number;
|
|
24
102
|
generateDirIfDNE<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
|
|
25
103
|
withWs<const T extends string>(path: T, data: WriteStreamDataShape, options?: WriteStreamOptions): string | boolean | undefined;
|
|
26
104
|
writeFileAsync: <const T extends string>(path: T, data: WriteFileAsyncDataUnion, options?: WriteFileAsyncOptions) => Promise<string | void>;
|
|
27
|
-
dirExists<const T extends string>(dir: T): boolean;
|
|
28
105
|
unlink<const P extends string>(path: P): Promise<void>;
|
|
29
106
|
rmFile<const FP extends string>(filePath: FP): void;
|
|
30
107
|
rmdir<const D extends string>(dir: D, options?: RmDirOptions): Promise<void>;
|
|
@@ -55,6 +132,12 @@ declare class Fs extends MimeService {
|
|
|
55
132
|
*/
|
|
56
133
|
fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
57
134
|
fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* @access package-private
|
|
138
|
+
*
|
|
139
|
+
* work in progress, for internal package maintainer use only
|
|
140
|
+
*/
|
|
58
141
|
imageTransform<const F extends "webp" | "avif" | "jpg" | "png" | "tif" | "tiff" | "jp2" | "jpeg">({ format, target, quality, tint, resize }: {
|
|
59
142
|
format: F;
|
|
60
143
|
target: Buffer<ArrayBuffer>;
|
package/dist/fs/index.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,8 @@ __export(index_exports, {
|
|
|
35
35
|
MimeService: () => MimeService,
|
|
36
36
|
UrlService: () => UrlService,
|
|
37
37
|
UtilsService: () => UtilsService,
|
|
38
|
-
extMimeMap: () => extMimeMap
|
|
38
|
+
extMimeMap: () => extMimeMap,
|
|
39
|
+
unitsObj: () => unitsObj
|
|
39
40
|
});
|
|
40
41
|
module.exports = __toCommonJS(index_exports);
|
|
41
42
|
|
|
@@ -219,6 +220,16 @@ var MimeService = class extends UrlService {
|
|
|
219
220
|
}
|
|
220
221
|
};
|
|
221
222
|
|
|
223
|
+
// src/types/index.ts
|
|
224
|
+
var unitsObj = {
|
|
225
|
+
PB: 5,
|
|
226
|
+
TB: 4,
|
|
227
|
+
GB: 3,
|
|
228
|
+
MB: 2,
|
|
229
|
+
KB: 1,
|
|
230
|
+
B: 0
|
|
231
|
+
};
|
|
232
|
+
|
|
222
233
|
// src/fs/index.ts
|
|
223
234
|
dotenv.config();
|
|
224
235
|
var Fs = class extends MimeService {
|
|
@@ -235,14 +246,84 @@ var Fs = class extends MimeService {
|
|
|
235
246
|
parseDotEnv() {
|
|
236
247
|
return import_dotenv_expand.default.expand(this.myEnv);
|
|
237
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
*
|
|
251
|
+
* @param target path to the file or directory to check for existence
|
|
252
|
+
* @returns true if the file or directory exists, false otherwise
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* const fs = new Fs(process.cwd());
|
|
256
|
+
* const exists = fs.exists("my-file.txt");
|
|
257
|
+
* console.log(exists); // true if the file exists, false otherwise
|
|
258
|
+
* ```
|
|
259
|
+
* @description
|
|
260
|
+
* This method checks if a file or directory exists at the specified path input
|
|
261
|
+
*
|
|
262
|
+
* Additional Note:
|
|
263
|
+
*
|
|
264
|
+
* say you have a directory that begins with a dot, such as `.turbo`;
|
|
265
|
+
*
|
|
266
|
+
* in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
|
|
267
|
+
*
|
|
268
|
+
*/
|
|
238
269
|
exists(target) {
|
|
239
|
-
if (!/\//gm.test(target))
|
|
240
|
-
|
|
241
|
-
|
|
270
|
+
if (!/\//gm.test(target)) {
|
|
271
|
+
if (/\./g.test(target)) {
|
|
272
|
+
return import_fs.default.existsSync((0, import_path.resolve)((0, import_path.join)(this.cwd, target)));
|
|
273
|
+
} else {
|
|
274
|
+
const statsSync = import_fs.default.statSync((0, import_path.resolve)((0, import_path.join)(this.cwd, target)), {
|
|
275
|
+
throwIfNoEntry: false
|
|
276
|
+
});
|
|
277
|
+
const isDir = statsSync?.isDirectory();
|
|
278
|
+
if (isDir) {
|
|
279
|
+
return isDir;
|
|
280
|
+
} else return false;
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
if (/\./g.test(target)) {
|
|
284
|
+
return import_fs.default.existsSync((0, import_path.relative)(this.cwd ?? process.cwd(), target));
|
|
285
|
+
} else {
|
|
286
|
+
const statsSync = import_fs.default.statSync((0, import_path.relative)(this.cwd, target), {
|
|
287
|
+
throwIfNoEntry: false
|
|
288
|
+
});
|
|
289
|
+
const isDir = statsSync?.isDirectory();
|
|
290
|
+
if (isDir) {
|
|
291
|
+
return isDir;
|
|
292
|
+
} else return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
242
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
*
|
|
298
|
+
* @param ms milliseconds to wait
|
|
299
|
+
* @returns a promise that resolves after the specified number of milliseconds
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* const fs = new Fs(process.cwd());
|
|
303
|
+
* await fs.wait(1000); // waits for 1 second
|
|
304
|
+
* console.log("Done waiting!");
|
|
305
|
+
* ```
|
|
306
|
+
*
|
|
307
|
+
* Alternatively, you can use it like this:
|
|
308
|
+
* ```ts
|
|
309
|
+
* const fs = new Fs(process.cwd());
|
|
310
|
+
* fs.wait(1000).then(() => { // waits for 1 second
|
|
311
|
+
* console.log("Done waiting!");
|
|
312
|
+
* // do something after waiting
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* @description
|
|
317
|
+
* This method is useful for delaying execution in asynchronous code, such as when you need to wait for a file operation to complete or when you want to introduce a delay in a loop.
|
|
318
|
+
*/
|
|
243
319
|
wait(ms) {
|
|
244
320
|
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
245
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
|
|
324
|
+
* @param arr An array or readonly array of strings and/or Buffers
|
|
325
|
+
* @returns An array of strings with Buffers converted to UTF-8 strings.
|
|
326
|
+
*/
|
|
246
327
|
handleBuffStrArrUnion(arr) {
|
|
247
328
|
return arr.map(
|
|
248
329
|
(v) => Buffer.isBuffer(v) ? Buffer.from(v).toString("utf-8") : v
|
|
@@ -253,10 +334,32 @@ var Fs = class extends MimeService {
|
|
|
253
334
|
return true;
|
|
254
335
|
} else return false;
|
|
255
336
|
}
|
|
256
|
-
|
|
337
|
+
/**
|
|
338
|
+
*
|
|
339
|
+
* @param path path to the directory relative to the cwd
|
|
340
|
+
* @param options options for reading the directory, defaults to recursive
|
|
341
|
+
*
|
|
342
|
+
* The following two examples are equivalent:
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```ts
|
|
346
|
+
* const fs = new Fs(process.cwd());
|
|
347
|
+
* const files = fs.readDir("./my-directory", { recursive: true });
|
|
348
|
+
* console.log(files);
|
|
349
|
+
* ```
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* const fs = new Fs(process.cwd());
|
|
353
|
+
* const files = fs.readDir("my-directory", { recursive: true });
|
|
354
|
+
* console.log(files);
|
|
355
|
+
* ```
|
|
356
|
+
*
|
|
357
|
+
* @returns an array of strings representing the contents of the directory
|
|
358
|
+
*/
|
|
359
|
+
readDir(path, options = { recursive: true }) {
|
|
257
360
|
if (this.isRootPathTargeted(path)) {
|
|
258
361
|
return this.handleBuffStrArrUnion(
|
|
259
|
-
import_fs.default.readdirSync((0, import_path.resolve)((0, import_path.join)(this.cwd, "./")), options)
|
|
362
|
+
import_fs.default.readdirSync((0, import_path.resolve)((0, import_path.join)(this.cwd, "./")), { ...options })
|
|
260
363
|
);
|
|
261
364
|
} else {
|
|
262
365
|
return this.handleBuffStrArrUnion(
|
|
@@ -274,22 +377,64 @@ var Fs = class extends MimeService {
|
|
|
274
377
|
"utf-8"
|
|
275
378
|
), "executeCommand");
|
|
276
379
|
existsSync(path) {
|
|
277
|
-
|
|
278
|
-
return import_fs.default.existsSync((0, import_path.resolve)((0, import_path.join)(this.cwd, path)));
|
|
279
|
-
return import_fs.default.existsSync((0, import_path.relative)(this.cwd ?? process.cwd(), path));
|
|
380
|
+
return this.exists(path);
|
|
280
381
|
}
|
|
281
382
|
pathHandler(path) {
|
|
282
383
|
return /\//g.test(path) === true ? path.split(/([/])/gim).reverse().slice(2).reverse().join("") : path;
|
|
283
384
|
}
|
|
284
385
|
mkdirSync(path, options) {
|
|
285
|
-
return import_fs.default.mkdirSync((0, import_path.relative)(this.cwd
|
|
386
|
+
return import_fs.default.mkdirSync((0, import_path.relative)(this.cwd, path), options);
|
|
387
|
+
}
|
|
388
|
+
units = unitsObj;
|
|
389
|
+
u = ["B", "KB", "MB", "GB", "TB", "PB"];
|
|
390
|
+
autoFileSizeRaw(size) {
|
|
391
|
+
let s = typeof size === "bigint" ? Number(size) : size;
|
|
392
|
+
let i = 0;
|
|
393
|
+
while (s >= 1024 && i < this.u.length - 1) {
|
|
394
|
+
s /= 1024;
|
|
395
|
+
i++;
|
|
396
|
+
}
|
|
397
|
+
return { value: s, unit: this.u[i] };
|
|
398
|
+
}
|
|
399
|
+
getSize(size, target, opts = { decimals: 4, includeUnits: true }) {
|
|
400
|
+
const { decimals, includeUnits } = opts;
|
|
401
|
+
if (target === "auto") {
|
|
402
|
+
const { value, unit } = this.autoFileSizeRaw(size);
|
|
403
|
+
const rounded2 = value.toFixed(decimals);
|
|
404
|
+
return includeUnits ? `${rounded2} ${unit}` : Number.parseFloat(rounded2);
|
|
405
|
+
}
|
|
406
|
+
const key = target.toUpperCase();
|
|
407
|
+
const exp = this.units[key];
|
|
408
|
+
const divisor = typeof size === "bigint" ? 1024n ** BigInt(exp) : 1024 ** exp;
|
|
409
|
+
let v = 0;
|
|
410
|
+
if (typeof size === "bigint" || typeof divisor === "bigint") {
|
|
411
|
+
if (typeof size === "bigint" && typeof divisor === "bigint")
|
|
412
|
+
v = Number(size / divisor);
|
|
413
|
+
else if (typeof size !== "bigint" && typeof divisor === "bigint")
|
|
414
|
+
v = size / Number(divisor);
|
|
415
|
+
else if (typeof size === "bigint" && typeof divisor !== "bigint")
|
|
416
|
+
v = Number(size) / divisor;
|
|
417
|
+
} else if (typeof size === "number" && typeof divisor === "number") {
|
|
418
|
+
v = size / divisor;
|
|
419
|
+
}
|
|
420
|
+
const rounded = v.toFixed(decimals);
|
|
421
|
+
return includeUnits ? `${rounded} ${key}` : Number.parseFloat(rounded);
|
|
286
422
|
}
|
|
287
423
|
fileSizeMb(path) {
|
|
288
|
-
return import_fs.default.statSync((0, import_path.relative)(this.cwd
|
|
424
|
+
return import_fs.default.statSync((0, import_path.relative)(this.cwd, path)).size / (1024 * 1024);
|
|
425
|
+
}
|
|
426
|
+
fileSize(path, target, opts) {
|
|
427
|
+
if (!this.exists(path)) throw new Error(`path ${path} does not exist`);
|
|
428
|
+
else {
|
|
429
|
+
return this.getSize(
|
|
430
|
+
import_fs.default.statSync((0, import_path.relative)(this.cwd, path)).size,
|
|
431
|
+
target,
|
|
432
|
+
opts
|
|
433
|
+
);
|
|
434
|
+
}
|
|
289
435
|
}
|
|
290
436
|
generateDirIfDNE(path, options) {
|
|
291
|
-
|
|
292
|
-
if (doesExist === true) return;
|
|
437
|
+
if (this.existsSync(path)) return;
|
|
293
438
|
else {
|
|
294
439
|
return this.mkdirSync(path, options);
|
|
295
440
|
}
|
|
@@ -335,14 +480,6 @@ var Fs = class extends MimeService {
|
|
|
335
480
|
);
|
|
336
481
|
}
|
|
337
482
|
}, "writeFileAsync");
|
|
338
|
-
dirExists(dir) {
|
|
339
|
-
const resolved = (0, import_path.relative)(this.cwd, dir);
|
|
340
|
-
try {
|
|
341
|
-
return import_fs.default.statSync(resolved).isDirectory();
|
|
342
|
-
} catch {
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
483
|
async unlink(path) {
|
|
347
484
|
if (this.existsSync(path)) {
|
|
348
485
|
return await import_promises.default.unlink((0, import_path.relative)(this.cwd, path));
|
|
@@ -351,7 +488,7 @@ var Fs = class extends MimeService {
|
|
|
351
488
|
}
|
|
352
489
|
}
|
|
353
490
|
rmFile(filePath) {
|
|
354
|
-
if (this.
|
|
491
|
+
if (this.exists(filePath)) {
|
|
355
492
|
if (this.isRootPathTargeted(filePath)) {
|
|
356
493
|
import_fs.default.rmSync((0, import_path.resolve)((0, import_path.join)(this.cwd, filePath)));
|
|
357
494
|
} else import_fs.default.rmSync((0, import_path.resolve)(this.cwd, filePath));
|
|
@@ -359,7 +496,7 @@ var Fs = class extends MimeService {
|
|
|
359
496
|
}
|
|
360
497
|
async rmdir(dir, options) {
|
|
361
498
|
const resolved = (0, import_path.relative)(this.cwd, dir);
|
|
362
|
-
if (this.
|
|
499
|
+
if (this.exists(dir)) {
|
|
363
500
|
return import_promises.default.rmdir((0, import_path.relative)(this.cwd, dir), options);
|
|
364
501
|
} else {
|
|
365
502
|
throw new Error(`directory ${resolved} does not exist`);
|
|
@@ -367,7 +504,7 @@ var Fs = class extends MimeService {
|
|
|
367
504
|
}
|
|
368
505
|
rmDirSync(dir) {
|
|
369
506
|
const resolved = (0, import_path.resolve)(this.cwd, dir);
|
|
370
|
-
if (this.
|
|
507
|
+
if (this.exists(dir)) {
|
|
371
508
|
return import_fs.default.rm(resolved, { force: true, recursive: true }, (err) => {
|
|
372
509
|
if (err?.message) {
|
|
373
510
|
console.error(err?.message);
|
|
@@ -497,12 +634,18 @@ var Fs = class extends MimeService {
|
|
|
497
634
|
return;
|
|
498
635
|
}
|
|
499
636
|
const result = await this.assetToBufferView(inputUrl);
|
|
500
|
-
const
|
|
501
|
-
this.withWs(formattedPath, Buffer.from(
|
|
637
|
+
const cleanedData = this.cleanDataUrl(result.b64encodedData);
|
|
638
|
+
this.withWs(formattedPath, Buffer.from(cleanedData, "base64"));
|
|
502
639
|
} catch (err) {
|
|
503
|
-
console.error(`[
|
|
640
|
+
console.error(`[fetchRemoteWriteLocalLargeFiles error]:`, err);
|
|
504
641
|
}
|
|
505
642
|
}
|
|
643
|
+
/**
|
|
644
|
+
*
|
|
645
|
+
* @access package-private
|
|
646
|
+
*
|
|
647
|
+
* work in progress, for internal package maintainer use only
|
|
648
|
+
*/
|
|
506
649
|
// USE fluent-ffmpeg for video/animated image transforms (apng, etc)
|
|
507
650
|
// https://www.npmjs.com/package/fluent-ffmpeg
|
|
508
651
|
// https://www.npmjs.com/package/@types/fluent-ffmpeg
|
|
@@ -651,6 +794,7 @@ var UtilsService = class {
|
|
|
651
794
|
MimeService,
|
|
652
795
|
UrlService,
|
|
653
796
|
UtilsService,
|
|
654
|
-
extMimeMap
|
|
797
|
+
extMimeMap,
|
|
798
|
+
unitsObj
|
|
655
799
|
});
|
|
656
800
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as Fs } from './fs/index.cjs';
|
|
2
2
|
export { AllMimeTypes, FileExtension, FileExtensionToMimeType, InferTopLevelPresent, MimeService, MimeTopLevelType, PresentMimeTopLevelTypes, extMimeMap } from './mime/index.cjs';
|
|
3
|
-
export { Abortable, ArrayBufferView, ArrayOrReadOnlyArray, BashEnv, BufferEncodingUnion, CoercionUnion, CommonExecOptions, CommonOptions, ConditionalPromise, ConditionalToRequired, Depth, Dict, Equal, ExcludeFieldEnumerable, ExecSyncOptions, ExecSyncOptionsWithBufferEncoding, ExecSyncOptionsWithStringEncoding, ExecuteCommandProps, Expect, Extends, FieldToConditionallyNever, IOType, InferDepth, InjectScriptsProps, MkDirOptions, MkDirSyncOptions, MkDirSyncProps, Mode, ObjEncodingOptions, OmitSrc, OpenMode, ParsedUrlInfo, ProcessEnv, ProcessEnvOptions, ReadDirOptions, ReadDirProps, RemoveFields, RequiredToConditional, RmDirOptions, RmDirProps, Signals, StdioOptions, TypedArray, Unenumerate, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR } from './types/index.cjs';
|
|
3
|
+
export { Abortable, ArrayBufferView, ArrayOrReadOnlyArray, BashEnv, BufferEncodingUnion, CoercionUnion, CommonExecOptions, CommonOptions, ConditionalPromise, ConditionalToRequired, Depth, Dict, Equal, ExcludeFieldEnumerable, ExecSyncOptions, ExecSyncOptionsWithBufferEncoding, ExecSyncOptionsWithStringEncoding, ExecuteCommandProps, Expect, Extends, FieldToConditionallyNever, IOType, InferDepth, InjectScriptsProps, MkDirOptions, MkDirSyncOptions, MkDirSyncProps, Mode, ObjEncodingOptions, OmitSrc, OpenMode, ParsedUrlInfo, ProcessEnv, ProcessEnvOptions, ReadDirOptions, ReadDirProps, RemoveFields, RequiredToConditional, RmDirOptions, RmDirProps, Signals, SizeOpts, StdioOptions, TypedArray, Unenumerate, Unit, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR, unitsObj } from './types/index.cjs';
|
|
4
4
|
export { HandleQueryParamsOrHash, InferExtensionIfPresent, LastSegment, SplitForwardSlash, UrlFileExt, UrlService } from './url/index.cjs';
|
|
5
5
|
export { UtilsService } from './utils/index.cjs';
|
|
6
6
|
import 'dotenv-expand';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as Fs } from './fs/index.js';
|
|
2
2
|
export { AllMimeTypes, FileExtension, FileExtensionToMimeType, InferTopLevelPresent, MimeService, MimeTopLevelType, PresentMimeTopLevelTypes, extMimeMap } from './mime/index.js';
|
|
3
|
-
export { Abortable, ArrayBufferView, ArrayOrReadOnlyArray, BashEnv, BufferEncodingUnion, CoercionUnion, CommonExecOptions, CommonOptions, ConditionalPromise, ConditionalToRequired, Depth, Dict, Equal, ExcludeFieldEnumerable, ExecSyncOptions, ExecSyncOptionsWithBufferEncoding, ExecSyncOptionsWithStringEncoding, ExecuteCommandProps, Expect, Extends, FieldToConditionallyNever, IOType, InferDepth, InjectScriptsProps, MkDirOptions, MkDirSyncOptions, MkDirSyncProps, Mode, ObjEncodingOptions, OmitSrc, OpenMode, ParsedUrlInfo, ProcessEnv, ProcessEnvOptions, ReadDirOptions, ReadDirProps, RemoveFields, RequiredToConditional, RmDirOptions, RmDirProps, Signals, StdioOptions, TypedArray, Unenumerate, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR } from './types/index.js';
|
|
3
|
+
export { Abortable, ArrayBufferView, ArrayOrReadOnlyArray, BashEnv, BufferEncodingUnion, CoercionUnion, CommonExecOptions, CommonOptions, ConditionalPromise, ConditionalToRequired, Depth, Dict, Equal, ExcludeFieldEnumerable, ExecSyncOptions, ExecSyncOptionsWithBufferEncoding, ExecSyncOptionsWithStringEncoding, ExecuteCommandProps, Expect, Extends, FieldToConditionallyNever, IOType, InferDepth, InjectScriptsProps, MkDirOptions, MkDirSyncOptions, MkDirSyncProps, Mode, ObjEncodingOptions, OmitSrc, OpenMode, ParsedUrlInfo, ProcessEnv, ProcessEnvOptions, ReadDirOptions, ReadDirProps, RemoveFields, RequiredToConditional, RmDirOptions, RmDirProps, Signals, SizeOpts, StdioOptions, TypedArray, Unenumerate, Unit, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR, unitsObj } from './types/index.js';
|
|
4
4
|
export { HandleQueryParamsOrHash, InferExtensionIfPresent, LastSegment, SplitForwardSlash, UrlFileExt, UrlService } from './url/index.js';
|
|
5
5
|
export { UtilsService } from './utils/index.js';
|
|
6
6
|
import 'dotenv-expand';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Fs
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-73BXX52B.js";
|
|
4
4
|
import {
|
|
5
5
|
MimeService,
|
|
6
6
|
extMimeMap
|
|
7
7
|
} from "./chunk-EHOBCDHE.js";
|
|
8
|
+
import {
|
|
9
|
+
unitsObj
|
|
10
|
+
} from "./chunk-4X5DVWVM.js";
|
|
8
11
|
import {
|
|
9
12
|
UrlService
|
|
10
13
|
} from "./chunk-XHN56MDK.js";
|
|
@@ -17,6 +20,7 @@ export {
|
|
|
17
20
|
MimeService,
|
|
18
21
|
UrlService,
|
|
19
22
|
UtilsService,
|
|
20
|
-
extMimeMap
|
|
23
|
+
extMimeMap,
|
|
24
|
+
unitsObj
|
|
21
25
|
};
|
|
22
26
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.cjs
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,5 +19,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
19
|
|
|
16
20
|
// src/types/index.ts
|
|
17
21
|
var types_exports = {};
|
|
22
|
+
__export(types_exports, {
|
|
23
|
+
unitsObj: () => unitsObj
|
|
24
|
+
});
|
|
18
25
|
module.exports = __toCommonJS(types_exports);
|
|
26
|
+
var unitsObj = {
|
|
27
|
+
PB: 5,
|
|
28
|
+
TB: 4,
|
|
29
|
+
GB: 3,
|
|
30
|
+
MB: 2,
|
|
31
|
+
KB: 1,
|
|
32
|
+
B: 0
|
|
33
|
+
};
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
unitsObj
|
|
37
|
+
});
|
|
19
38
|
//# sourceMappingURL=index.cjs.map
|
package/dist/types/index.d.cts
CHANGED
|
@@ -101,10 +101,13 @@ type WriteStreamOptions = BufferEncodingUnion | {
|
|
|
101
101
|
type WriteFileAsyncDataUnion = WithImplicitCoercion<string> | {
|
|
102
102
|
[Symbol.toPrimitive](hint: "string"): string;
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
interface ReadDirOptionsEntity extends ObjEncodingOptions {
|
|
105
105
|
withFileTypes?: false | undefined;
|
|
106
106
|
recursive?: boolean | undefined;
|
|
107
|
-
}
|
|
107
|
+
}
|
|
108
|
+
type ReadDirOptions = {
|
|
109
|
+
[P in keyof ReadDirOptionsEntity]: ReadDirOptionsEntity[P];
|
|
110
|
+
};
|
|
108
111
|
type WriteFileAsyncOptions = (ObjEncodingOptions & {
|
|
109
112
|
mode?: Mode | undefined;
|
|
110
113
|
flag?: OpenMode | undefined;
|
|
@@ -243,5 +246,18 @@ type ParsedUrlInfo = {
|
|
|
243
246
|
search: string;
|
|
244
247
|
hash: string;
|
|
245
248
|
};
|
|
249
|
+
declare const unitsObj: {
|
|
250
|
+
readonly PB: 5;
|
|
251
|
+
readonly TB: 4;
|
|
252
|
+
readonly GB: 3;
|
|
253
|
+
readonly MB: 2;
|
|
254
|
+
readonly KB: 1;
|
|
255
|
+
readonly B: 0;
|
|
256
|
+
};
|
|
257
|
+
type Unit = keyof typeof unitsObj;
|
|
258
|
+
type SizeOpts = {
|
|
259
|
+
decimals?: number;
|
|
260
|
+
includeUnits?: boolean;
|
|
261
|
+
};
|
|
246
262
|
|
|
247
|
-
export type
|
|
263
|
+
export { type Abortable, type ArrayBufferView, type ArrayOrReadOnlyArray, type BashEnv, type BufferEncodingUnion, type CoercionUnion, type CommonExecOptions, type CommonOptions, type ConditionalPromise, type ConditionalToRequired, type Depth, type Dict, type Equal, type ExcludeFieldEnumerable, type ExecSyncOptions, type ExecSyncOptionsWithBufferEncoding, type ExecSyncOptionsWithStringEncoding, type ExecuteCommandProps, type Expect, type Extends, type FieldToConditionallyNever, type IOType, type InferDepth, type InjectScriptsProps, type MkDirOptions, type MkDirSyncOptions, type MkDirSyncProps, type Mode, type ObjEncodingOptions, type OmitSrc, type OpenMode, type ParsedUrlInfo, type ProcessEnv, type ProcessEnvOptions, type ReadDirOptions, type ReadDirOptionsEntity, type ReadDirProps, type RemoveFields, type RequiredToConditional, type RmDirOptions, type RmDirProps, type Signals, type SizeOpts, type StdioOptions, type TypedArray, type Unenumerate, type Unit, type UnwrapPromise, type Without, type WriteFileAsyncDataUnion, type WriteFileAsyncOptions, type WriteFileAsyncProps, type WriteStreamDataShape, type WriteStreamOptions, type WriteStreamProps, type XOR, unitsObj };
|