@d0paminedriven/fs 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ // src/types/index.ts
2
+ var unitsObj = {
3
+ PB: 5,
4
+ TB: 4,
5
+ GB: 3,
6
+ MB: 2,
7
+ KB: 1,
8
+ B: 0
9
+ };
10
+
11
+ export {
12
+ unitsObj
13
+ };
14
+ //# sourceMappingURL=chunk-4X5DVWVM.js.map
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  MimeService
3
3
  } from "./chunk-EHOBCDHE.js";
4
+ import {
5
+ unitsObj
6
+ } from "./chunk-4X5DVWVM.js";
4
7
  import {
5
8
  __name
6
9
  } from "./chunk-7QVYU63E.js";
@@ -28,14 +31,84 @@ var Fs = class extends MimeService {
28
31
  parseDotEnv() {
29
32
  return expand.expand(this.myEnv);
30
33
  }
34
+ /**
35
+ *
36
+ * @param target path to the file or directory to check for existence
37
+ * @returns true if the file or directory exists, false otherwise
38
+ * @example
39
+ * ```ts
40
+ * const fs = new Fs(process.cwd());
41
+ * const exists = fs.exists("my-file.txt");
42
+ * console.log(exists); // true if the file exists, false otherwise
43
+ * ```
44
+ * @description
45
+ * This method checks if a file or directory exists at the specified path input
46
+ *
47
+ * Additional Note:
48
+ *
49
+ * say you have a directory that begins with a dot, such as `.turbo`;
50
+ *
51
+ * in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
52
+ *
53
+ */
31
54
  exists(target) {
32
- if (!/\//gm.test(target))
33
- return fsSync.existsSync(resolve(join(this.cwd, target)));
34
- return fsSync.existsSync(relative(this.cwd ?? process.cwd(), target));
55
+ if (!/\//gm.test(target)) {
56
+ if (/\./g.test(target)) {
57
+ return fsSync.existsSync(resolve(join(this.cwd, target)));
58
+ } else {
59
+ const statsSync = fsSync.statSync(resolve(join(this.cwd, target)), {
60
+ throwIfNoEntry: false
61
+ });
62
+ const isDir = statsSync?.isDirectory();
63
+ if (isDir) {
64
+ return isDir;
65
+ } else return false;
66
+ }
67
+ } else {
68
+ if (/\./g.test(target)) {
69
+ return fsSync.existsSync(relative(this.cwd ?? process.cwd(), target));
70
+ } else {
71
+ const statsSync = fsSync.statSync(relative(this.cwd, target), {
72
+ throwIfNoEntry: false
73
+ });
74
+ const isDir = statsSync?.isDirectory();
75
+ if (isDir) {
76
+ return isDir;
77
+ } else return false;
78
+ }
79
+ }
35
80
  }
81
+ /**
82
+ *
83
+ * @param ms milliseconds to wait
84
+ * @returns a promise that resolves after the specified number of milliseconds
85
+ * @example
86
+ * ```ts
87
+ * const fs = new Fs(process.cwd());
88
+ * await fs.wait(1000); // waits for 1 second
89
+ * console.log("Done waiting!");
90
+ * ```
91
+ *
92
+ * Alternatively, you can use it like this:
93
+ * ```ts
94
+ * const fs = new Fs(process.cwd());
95
+ * fs.wait(1000).then(() => { // waits for 1 second
96
+ * console.log("Done waiting!");
97
+ * // do something after waiting
98
+ * });
99
+ * ```
100
+ *
101
+ * @description
102
+ * 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.
103
+ */
36
104
  wait(ms) {
37
105
  return new Promise((resolve2) => setTimeout(resolve2, ms));
38
106
  }
107
+ /**
108
+ * Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
109
+ * @param arr An array or readonly array of strings and/or Buffers
110
+ * @returns An array of strings with Buffers converted to UTF-8 strings.
111
+ */
39
112
  handleBuffStrArrUnion(arr) {
40
113
  return arr.map(
41
114
  (v) => Buffer.isBuffer(v) ? Buffer.from(v).toString("utf-8") : v
@@ -46,10 +119,32 @@ var Fs = class extends MimeService {
46
119
  return true;
47
120
  } else return false;
48
121
  }
49
- readDir(path, options) {
122
+ /**
123
+ *
124
+ * @param path path to the directory relative to the cwd
125
+ * @param options options for reading the directory, defaults to recursive
126
+ *
127
+ * The following two examples are equivalent:
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const fs = new Fs(process.cwd());
132
+ * const files = fs.readDir("./my-directory", { recursive: true });
133
+ * console.log(files);
134
+ * ```
135
+ * @example
136
+ * ```ts
137
+ * const fs = new Fs(process.cwd());
138
+ * const files = fs.readDir("my-directory", { recursive: true });
139
+ * console.log(files);
140
+ * ```
141
+ *
142
+ * @returns an array of strings representing the contents of the directory
143
+ */
144
+ readDir(path, options = { recursive: true }) {
50
145
  if (this.isRootPathTargeted(path)) {
51
146
  return this.handleBuffStrArrUnion(
52
- fsSync.readdirSync(resolve(join(this.cwd, "./")), options)
147
+ fsSync.readdirSync(resolve(join(this.cwd, "./")), { ...options })
53
148
  );
54
149
  } else {
55
150
  return this.handleBuffStrArrUnion(
@@ -67,9 +162,7 @@ var Fs = class extends MimeService {
67
162
  "utf-8"
68
163
  ), "executeCommand");
69
164
  existsSync(path) {
70
- if (!/\//gm.test(path))
71
- return fsSync.existsSync(resolve(join(this.cwd, path)));
72
- return fsSync.existsSync(relative(this.cwd, path));
165
+ return this.exists(path);
73
166
  }
74
167
  pathHandler(path) {
75
168
  return /\//g.test(path) === true ? path.split(/([/])/gim).reverse().slice(2).reverse().join("") : path;
@@ -77,12 +170,56 @@ var Fs = class extends MimeService {
77
170
  mkdirSync(path, options) {
78
171
  return fsSync.mkdirSync(relative(this.cwd, path), options);
79
172
  }
173
+ units = unitsObj;
174
+ u = ["B", "KB", "MB", "GB", "TB", "PB"];
175
+ autoFileSizeRaw(size) {
176
+ let s = typeof size === "bigint" ? Number(size) : size;
177
+ let i = 0;
178
+ while (s >= 1024 && i < this.u.length - 1) {
179
+ s /= 1024;
180
+ i++;
181
+ }
182
+ return { value: s, unit: this.u[i] };
183
+ }
184
+ getSize(size, target, opts = { decimals: 4, includeUnits: true }) {
185
+ const { decimals, includeUnits } = opts;
186
+ if (target === "auto") {
187
+ const { value, unit } = this.autoFileSizeRaw(size);
188
+ const rounded2 = value.toFixed(decimals);
189
+ return includeUnits ? `${rounded2} ${unit}` : Number.parseFloat(rounded2);
190
+ }
191
+ const key = target.toUpperCase();
192
+ const exp = this.units[key];
193
+ const divisor = typeof size === "bigint" ? 1024n ** BigInt(exp) : 1024 ** exp;
194
+ let v = 0;
195
+ if (typeof size === "bigint" || typeof divisor === "bigint") {
196
+ if (typeof size === "bigint" && typeof divisor === "bigint")
197
+ v = Number(size / divisor);
198
+ else if (typeof size !== "bigint" && typeof divisor === "bigint")
199
+ v = size / Number(divisor);
200
+ else if (typeof size === "bigint" && typeof divisor !== "bigint")
201
+ v = Number(size) / divisor;
202
+ } else if (typeof size === "number" && typeof divisor === "number") {
203
+ v = size / divisor;
204
+ }
205
+ const rounded = v.toFixed(decimals);
206
+ return includeUnits ? `${rounded} ${key}` : Number.parseFloat(rounded);
207
+ }
80
208
  fileSizeMb(path) {
81
209
  return fsSync.statSync(relative(this.cwd, path)).size / (1024 * 1024);
82
210
  }
211
+ fileSize(path, target, opts) {
212
+ if (!this.exists(path)) throw new Error(`path ${path} does not exist`);
213
+ else {
214
+ return this.getSize(
215
+ fsSync.statSync(relative(this.cwd, path)).size,
216
+ target,
217
+ opts
218
+ );
219
+ }
220
+ }
83
221
  generateDirIfDNE(path, options) {
84
- const doesExist = this.existsSync(path);
85
- if (doesExist === true) return;
222
+ if (this.existsSync(path)) return;
86
223
  else {
87
224
  return this.mkdirSync(path, options);
88
225
  }
@@ -128,14 +265,6 @@ var Fs = class extends MimeService {
128
265
  );
129
266
  }
130
267
  }, "writeFileAsync");
131
- dirExists(dir) {
132
- const resolved = relative(this.cwd, dir);
133
- try {
134
- return fsSync.statSync(resolved).isDirectory();
135
- } catch {
136
- return false;
137
- }
138
- }
139
268
  async unlink(path) {
140
269
  if (this.existsSync(path)) {
141
270
  return await fsAsync.unlink(relative(this.cwd, path));
@@ -144,7 +273,7 @@ var Fs = class extends MimeService {
144
273
  }
145
274
  }
146
275
  rmFile(filePath) {
147
- if (this.existsSync(filePath)) {
276
+ if (this.exists(filePath)) {
148
277
  if (this.isRootPathTargeted(filePath)) {
149
278
  fsSync.rmSync(resolve(join(this.cwd, filePath)));
150
279
  } else fsSync.rmSync(resolve(this.cwd, filePath));
@@ -152,7 +281,7 @@ var Fs = class extends MimeService {
152
281
  }
153
282
  async rmdir(dir, options) {
154
283
  const resolved = relative(this.cwd, dir);
155
- if (this.dirExists(dir)) {
284
+ if (this.exists(dir)) {
156
285
  return fsAsync.rmdir(relative(this.cwd, dir), options);
157
286
  } else {
158
287
  throw new Error(`directory ${resolved} does not exist`);
@@ -160,7 +289,7 @@ var Fs = class extends MimeService {
160
289
  }
161
290
  rmDirSync(dir) {
162
291
  const resolved = resolve(this.cwd, dir);
163
- if (this.dirExists(dir)) {
292
+ if (this.exists(dir)) {
164
293
  return fsSync.rm(resolved, { force: true, recursive: true }, (err) => {
165
294
  if (err?.message) {
166
295
  console.error(err?.message);
@@ -318,11 +447,13 @@ var Fs = class extends MimeService {
318
447
  return await sharp(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
319
448
  } else if (tint && resize) {
320
449
  return await sharp(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
321
- } else return await sharp(target).toFormat(format, { quality }).toBuffer();
450
+ } else {
451
+ return await sharp(target).toFormat(format, { quality }).toBuffer();
452
+ }
322
453
  }
323
454
  };
324
455
 
325
456
  export {
326
457
  Fs
327
458
  };
328
- //# sourceMappingURL=chunk-KZWE4E4I.js.map
459
+ //# sourceMappingURL=chunk-XIAKCF2X.js.map
package/dist/fs/index.cjs CHANGED
@@ -213,6 +213,16 @@ var MimeService = class extends UrlService {
213
213
  }
214
214
  };
215
215
 
216
+ // src/types/index.ts
217
+ var unitsObj = {
218
+ PB: 5,
219
+ TB: 4,
220
+ GB: 3,
221
+ MB: 2,
222
+ KB: 1,
223
+ B: 0
224
+ };
225
+
216
226
  // src/fs/index.ts
217
227
  dotenv.config();
218
228
  var Fs = class extends MimeService {
@@ -229,14 +239,84 @@ var Fs = class extends MimeService {
229
239
  parseDotEnv() {
230
240
  return import_dotenv_expand.default.expand(this.myEnv);
231
241
  }
242
+ /**
243
+ *
244
+ * @param target path to the file or directory to check for existence
245
+ * @returns true if the file or directory exists, false otherwise
246
+ * @example
247
+ * ```ts
248
+ * const fs = new Fs(process.cwd());
249
+ * const exists = fs.exists("my-file.txt");
250
+ * console.log(exists); // true if the file exists, false otherwise
251
+ * ```
252
+ * @description
253
+ * This method checks if a file or directory exists at the specified path input
254
+ *
255
+ * Additional Note:
256
+ *
257
+ * say you have a directory that begins with a dot, such as `.turbo`;
258
+ *
259
+ * in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
260
+ *
261
+ */
232
262
  exists(target) {
233
- if (!/\//gm.test(target))
234
- return import_fs.default.existsSync((0, import_path.resolve)((0, import_path.join)(this.cwd, target)));
235
- return import_fs.default.existsSync((0, import_path.relative)(this.cwd ?? process.cwd(), target));
263
+ if (!/\//gm.test(target)) {
264
+ if (/\./g.test(target)) {
265
+ return import_fs.default.existsSync((0, import_path.resolve)((0, import_path.join)(this.cwd, target)));
266
+ } else {
267
+ const statsSync = import_fs.default.statSync((0, import_path.resolve)((0, import_path.join)(this.cwd, target)), {
268
+ throwIfNoEntry: false
269
+ });
270
+ const isDir = statsSync?.isDirectory();
271
+ if (isDir) {
272
+ return isDir;
273
+ } else return false;
274
+ }
275
+ } else {
276
+ if (/\./g.test(target)) {
277
+ return import_fs.default.existsSync((0, import_path.relative)(this.cwd ?? process.cwd(), target));
278
+ } else {
279
+ const statsSync = import_fs.default.statSync((0, import_path.relative)(this.cwd, target), {
280
+ throwIfNoEntry: false
281
+ });
282
+ const isDir = statsSync?.isDirectory();
283
+ if (isDir) {
284
+ return isDir;
285
+ } else return false;
286
+ }
287
+ }
236
288
  }
289
+ /**
290
+ *
291
+ * @param ms milliseconds to wait
292
+ * @returns a promise that resolves after the specified number of milliseconds
293
+ * @example
294
+ * ```ts
295
+ * const fs = new Fs(process.cwd());
296
+ * await fs.wait(1000); // waits for 1 second
297
+ * console.log("Done waiting!");
298
+ * ```
299
+ *
300
+ * Alternatively, you can use it like this:
301
+ * ```ts
302
+ * const fs = new Fs(process.cwd());
303
+ * fs.wait(1000).then(() => { // waits for 1 second
304
+ * console.log("Done waiting!");
305
+ * // do something after waiting
306
+ * });
307
+ * ```
308
+ *
309
+ * @description
310
+ * 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.
311
+ */
237
312
  wait(ms) {
238
313
  return new Promise((resolve2) => setTimeout(resolve2, ms));
239
314
  }
315
+ /**
316
+ * Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
317
+ * @param arr An array or readonly array of strings and/or Buffers
318
+ * @returns An array of strings with Buffers converted to UTF-8 strings.
319
+ */
240
320
  handleBuffStrArrUnion(arr) {
241
321
  return arr.map(
242
322
  (v) => Buffer.isBuffer(v) ? Buffer.from(v).toString("utf-8") : v
@@ -247,10 +327,32 @@ var Fs = class extends MimeService {
247
327
  return true;
248
328
  } else return false;
249
329
  }
250
- readDir(path, options) {
330
+ /**
331
+ *
332
+ * @param path path to the directory relative to the cwd
333
+ * @param options options for reading the directory, defaults to recursive
334
+ *
335
+ * The following two examples are equivalent:
336
+ *
337
+ * @example
338
+ * ```ts
339
+ * const fs = new Fs(process.cwd());
340
+ * const files = fs.readDir("./my-directory", { recursive: true });
341
+ * console.log(files);
342
+ * ```
343
+ * @example
344
+ * ```ts
345
+ * const fs = new Fs(process.cwd());
346
+ * const files = fs.readDir("my-directory", { recursive: true });
347
+ * console.log(files);
348
+ * ```
349
+ *
350
+ * @returns an array of strings representing the contents of the directory
351
+ */
352
+ readDir(path, options = { recursive: true }) {
251
353
  if (this.isRootPathTargeted(path)) {
252
354
  return this.handleBuffStrArrUnion(
253
- import_fs.default.readdirSync((0, import_path.resolve)((0, import_path.join)(this.cwd, "./")), options)
355
+ import_fs.default.readdirSync((0, import_path.resolve)((0, import_path.join)(this.cwd, "./")), { ...options })
254
356
  );
255
357
  } else {
256
358
  return this.handleBuffStrArrUnion(
@@ -268,9 +370,7 @@ var Fs = class extends MimeService {
268
370
  "utf-8"
269
371
  ), "executeCommand");
270
372
  existsSync(path) {
271
- if (!/\//gm.test(path))
272
- return import_fs.default.existsSync((0, import_path.resolve)((0, import_path.join)(this.cwd, path)));
273
- return import_fs.default.existsSync((0, import_path.relative)(this.cwd, path));
373
+ return this.exists(path);
274
374
  }
275
375
  pathHandler(path) {
276
376
  return /\//g.test(path) === true ? path.split(/([/])/gim).reverse().slice(2).reverse().join("") : path;
@@ -278,12 +378,56 @@ var Fs = class extends MimeService {
278
378
  mkdirSync(path, options) {
279
379
  return import_fs.default.mkdirSync((0, import_path.relative)(this.cwd, path), options);
280
380
  }
381
+ units = unitsObj;
382
+ u = ["B", "KB", "MB", "GB", "TB", "PB"];
383
+ autoFileSizeRaw(size) {
384
+ let s = typeof size === "bigint" ? Number(size) : size;
385
+ let i = 0;
386
+ while (s >= 1024 && i < this.u.length - 1) {
387
+ s /= 1024;
388
+ i++;
389
+ }
390
+ return { value: s, unit: this.u[i] };
391
+ }
392
+ getSize(size, target, opts = { decimals: 4, includeUnits: true }) {
393
+ const { decimals, includeUnits } = opts;
394
+ if (target === "auto") {
395
+ const { value, unit } = this.autoFileSizeRaw(size);
396
+ const rounded2 = value.toFixed(decimals);
397
+ return includeUnits ? `${rounded2} ${unit}` : Number.parseFloat(rounded2);
398
+ }
399
+ const key = target.toUpperCase();
400
+ const exp = this.units[key];
401
+ const divisor = typeof size === "bigint" ? 1024n ** BigInt(exp) : 1024 ** exp;
402
+ let v = 0;
403
+ if (typeof size === "bigint" || typeof divisor === "bigint") {
404
+ if (typeof size === "bigint" && typeof divisor === "bigint")
405
+ v = Number(size / divisor);
406
+ else if (typeof size !== "bigint" && typeof divisor === "bigint")
407
+ v = size / Number(divisor);
408
+ else if (typeof size === "bigint" && typeof divisor !== "bigint")
409
+ v = Number(size) / divisor;
410
+ } else if (typeof size === "number" && typeof divisor === "number") {
411
+ v = size / divisor;
412
+ }
413
+ const rounded = v.toFixed(decimals);
414
+ return includeUnits ? `${rounded} ${key}` : Number.parseFloat(rounded);
415
+ }
281
416
  fileSizeMb(path) {
282
417
  return import_fs.default.statSync((0, import_path.relative)(this.cwd, path)).size / (1024 * 1024);
283
418
  }
419
+ fileSize(path, target, opts) {
420
+ if (!this.exists(path)) throw new Error(`path ${path} does not exist`);
421
+ else {
422
+ return this.getSize(
423
+ import_fs.default.statSync((0, import_path.relative)(this.cwd, path)).size,
424
+ target,
425
+ opts
426
+ );
427
+ }
428
+ }
284
429
  generateDirIfDNE(path, options) {
285
- const doesExist = this.existsSync(path);
286
- if (doesExist === true) return;
430
+ if (this.existsSync(path)) return;
287
431
  else {
288
432
  return this.mkdirSync(path, options);
289
433
  }
@@ -329,14 +473,6 @@ var Fs = class extends MimeService {
329
473
  );
330
474
  }
331
475
  }, "writeFileAsync");
332
- dirExists(dir) {
333
- const resolved = (0, import_path.relative)(this.cwd, dir);
334
- try {
335
- return import_fs.default.statSync(resolved).isDirectory();
336
- } catch {
337
- return false;
338
- }
339
- }
340
476
  async unlink(path) {
341
477
  if (this.existsSync(path)) {
342
478
  return await import_promises.default.unlink((0, import_path.relative)(this.cwd, path));
@@ -345,7 +481,7 @@ var Fs = class extends MimeService {
345
481
  }
346
482
  }
347
483
  rmFile(filePath) {
348
- if (this.existsSync(filePath)) {
484
+ if (this.exists(filePath)) {
349
485
  if (this.isRootPathTargeted(filePath)) {
350
486
  import_fs.default.rmSync((0, import_path.resolve)((0, import_path.join)(this.cwd, filePath)));
351
487
  } else import_fs.default.rmSync((0, import_path.resolve)(this.cwd, filePath));
@@ -353,7 +489,7 @@ var Fs = class extends MimeService {
353
489
  }
354
490
  async rmdir(dir, options) {
355
491
  const resolved = (0, import_path.relative)(this.cwd, dir);
356
- if (this.dirExists(dir)) {
492
+ if (this.exists(dir)) {
357
493
  return import_promises.default.rmdir((0, import_path.relative)(this.cwd, dir), options);
358
494
  } else {
359
495
  throw new Error(`directory ${resolved} does not exist`);
@@ -361,7 +497,7 @@ var Fs = class extends MimeService {
361
497
  }
362
498
  rmDirSync(dir) {
363
499
  const resolved = (0, import_path.resolve)(this.cwd, dir);
364
- if (this.dirExists(dir)) {
500
+ if (this.exists(dir)) {
365
501
  return import_fs.default.rm(resolved, { force: true, recursive: true }, (err) => {
366
502
  if (err?.message) {
367
503
  console.error(err?.message);
@@ -519,7 +655,9 @@ var Fs = class extends MimeService {
519
655
  return await (0, import_sharp.default)(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
520
656
  } else if (tint && resize) {
521
657
  return await (0, import_sharp.default)(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
522
- } else return await (0, import_sharp.default)(target).toFormat(format, { quality }).toBuffer();
658
+ } else {
659
+ return await (0, import_sharp.default)(target).toFormat(format, { quality }).toBuffer();
660
+ }
523
661
  }
524
662
  };
525
663
  //# sourceMappingURL=index.cjs.map
@@ -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>;
@@ -32,7 +109,7 @@ declare class Fs extends MimeService {
32
109
  fileToBuffer: <const T extends string>(path: T) => Buffer<ArrayBuffer>;
33
110
  dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
34
111
  assetToBuffer<const T extends string>(path: T): Promise<{
35
- readonly b64encodedData: `data:audio/aac;base64, ${string}` | `data:application/x-abiword;base64, ${string}` | `data:image/aces;base64, ${string}` | `data:image/apng;base64, ${string}` | `data:application/x-freearc;base64, ${string}` | `data:image/avci;base64, ${string}` | `data:image/avif;base64, ${string}` | `data:video/x-msvideo;base64, ${string}` | `data:application/vnd.amazon.ebook;base64, ${string}` | `data:application/octet-stream;base64, ${string}` | `data:image/bmp;base64, ${string}` | `data:application/x-bzip;base64, ${string}` | `data:application/x-bzip2;base64, ${string}` | `data:application/x-cdf;base64, ${string}` | `data:application/node;base64, ${string}` | `data:text/javascript;base64, ${string}` | `data:application/x-csh;base64, ${string}` | `data:text/css;base64, ${string}` | `data:text/csv;base64, ${string}` | `data:application/msword;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64, ${string}` | `data:image/dpx;base64, ${string}` | `data:image/emf;base64, ${string}` | `data:application/vnd.ms-fontobject;base64, ${string}` | `data:application/epub+zip;base64, ${string}` | `data:image/gif;base64, ${string}` | `data:model/gltf-binary;base64, ${string}` | `data:model/gltf+json;base64, ${string}` | `data:application/x-gzip;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:haptics/hjif;base64, ${string}` | `data:haptics/hmpg;base64, ${string}` | `data:text/html;base64, ${string}` | `data:image/vnd.microsoft.icon;base64, ${string}` | `data:text/calendar;base64, ${string}` | `data:haptics/ivs;base64, ${string}` | `data:application/java-archive;base64, ${string}` | `data:image/jpeg;base64, ${string}` | `data:application/json;base64, ${string}` | `data:application/ld+json;base64, ${string}` | `data:image/ktx;base64, ${string}` | `data:image/ktx2;base64, ${string}` | `data:application/vnd.apple.mpegurl;base64, ${string}` | `data:audio/mp4;base64, ${string}` | `data:video/mp4;base64, ${string}` | `data:text/markdown;base64, ${string}` | `data:application/x-mdx;base64, ${string}` | `data:audio/midi;base64, ${string}` | `data:audio/x-midi;base64, ${string}` | `data:audio/mpeg;base64, ${string}` | `data:video/mpeg;base64, ${string}` | `data:application/vnd.apple.installer+xml;base64, ${string}` | `data:application/x-ndjson;base64, ${string}` | `data:text/plain;base64, ${string}` | `data:model/obj;base64, ${string}` | `data:application/vnd.oasis.opendocument.presentation;base64, ${string}` | `data:application/vnd.oasis.opendocument.spreadsheet;base64, ${string}` | `data:application/vnd.oasis.opendocument.text;base64, ${string}` | `data:audio/ogg;base64, ${string}` | `data:video/ogg;base64, ${string}` | `data:application/ogg;base64, ${string}` | `data:font/otf;base64, ${string}` | `data:image/png;base64, ${string}` | `data:application/pdf;base64, ${string}` | `data:application/x-httpd-php;base64, ${string}` | `data:application/vnd.apple.pkpass;base64, ${string}` | `data:application/vnd.ms-powerpoint;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64, ${string}` | `data:text/x-python;base64, ${string}` | `data:application/x-python-code;base64, ${string}` | `data:application/vnd.rar;base64, ${string}` | `data:application/rtf;base64, ${string}` | `data:application/x-sh;base64, ${string}` | `data:application/sql;base64, ${string}` | `data:image/svg+xml;base64, ${string}` | `data:application/x-tar;base64, ${string}` | `data:image/tiff;base64, ${string}` | `data:application/toml;base64, ${string}` | `data:text/typescript;base64, ${string}` | `data:video/mp2t;base64, ${string}` | `data:video/vnd.dlna.mpeg-tts;base64, ${string}` | `data:application/font-sfnt;base64, ${string}` | `data:font/ttf;base64, ${string}` | `data:model/vnd.usdz+zip;base64, ${string}` | `data:application/vnd.visio;base64, ${string}` | `data:text/vtt;base64, ${string}` | `data:application/wasm;base64, ${string}` | `data:audio/wav;base64, ${string}` | `data:video/webm;base64, ${string}` | `data:image/webp;base64, ${string}` | `data:font/woff;base64, ${string}` | `data:font/woff2;base64, ${string}` | `data:application/xhtml+xml;base64, ${string}` | `data:application/vnd.ms-excel;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64, ${string}` | `data:application/xml;base64, ${string}` | `data:application/vnd.mozilla.xul+xml;base64, ${string}` | `data:application/yaml;base64, ${string}` | `data:application/zip;base64, ${string}` | `data:application/x-zip-compressed;base64, ${string}` | `data:video/3gpp;base64, ${string}` | `data:video/3gpp2;base64, ${string}` | `data:application/x-7z-compressed;base64, ${string}`;
112
+ readonly b64encodedData: `data:application/octet-stream;base64, ${string}` | `data:audio/aac;base64, ${string}` | `data:application/x-abiword;base64, ${string}` | `data:image/aces;base64, ${string}` | `data:image/apng;base64, ${string}` | `data:application/x-freearc;base64, ${string}` | `data:image/avci;base64, ${string}` | `data:image/avif;base64, ${string}` | `data:video/x-msvideo;base64, ${string}` | `data:application/vnd.amazon.ebook;base64, ${string}` | `data:image/bmp;base64, ${string}` | `data:application/x-bzip;base64, ${string}` | `data:application/x-bzip2;base64, ${string}` | `data:application/x-cdf;base64, ${string}` | `data:application/node;base64, ${string}` | `data:text/javascript;base64, ${string}` | `data:application/x-csh;base64, ${string}` | `data:text/css;base64, ${string}` | `data:text/csv;base64, ${string}` | `data:application/msword;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64, ${string}` | `data:image/dpx;base64, ${string}` | `data:image/emf;base64, ${string}` | `data:application/vnd.ms-fontobject;base64, ${string}` | `data:application/epub+zip;base64, ${string}` | `data:image/gif;base64, ${string}` | `data:model/gltf-binary;base64, ${string}` | `data:model/gltf+json;base64, ${string}` | `data:application/x-gzip;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:haptics/hjif;base64, ${string}` | `data:haptics/hmpg;base64, ${string}` | `data:text/html;base64, ${string}` | `data:image/vnd.microsoft.icon;base64, ${string}` | `data:text/calendar;base64, ${string}` | `data:haptics/ivs;base64, ${string}` | `data:application/java-archive;base64, ${string}` | `data:image/jpeg;base64, ${string}` | `data:application/json;base64, ${string}` | `data:application/ld+json;base64, ${string}` | `data:image/ktx;base64, ${string}` | `data:image/ktx2;base64, ${string}` | `data:application/vnd.apple.mpegurl;base64, ${string}` | `data:audio/mp4;base64, ${string}` | `data:video/mp4;base64, ${string}` | `data:text/markdown;base64, ${string}` | `data:application/x-mdx;base64, ${string}` | `data:audio/midi;base64, ${string}` | `data:audio/x-midi;base64, ${string}` | `data:audio/mpeg;base64, ${string}` | `data:video/mpeg;base64, ${string}` | `data:application/vnd.apple.installer+xml;base64, ${string}` | `data:application/x-ndjson;base64, ${string}` | `data:text/plain;base64, ${string}` | `data:model/obj;base64, ${string}` | `data:application/vnd.oasis.opendocument.presentation;base64, ${string}` | `data:application/vnd.oasis.opendocument.spreadsheet;base64, ${string}` | `data:application/vnd.oasis.opendocument.text;base64, ${string}` | `data:audio/ogg;base64, ${string}` | `data:video/ogg;base64, ${string}` | `data:application/ogg;base64, ${string}` | `data:font/otf;base64, ${string}` | `data:image/png;base64, ${string}` | `data:application/pdf;base64, ${string}` | `data:application/x-httpd-php;base64, ${string}` | `data:application/vnd.apple.pkpass;base64, ${string}` | `data:application/vnd.ms-powerpoint;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64, ${string}` | `data:text/x-python;base64, ${string}` | `data:application/x-python-code;base64, ${string}` | `data:application/vnd.rar;base64, ${string}` | `data:application/rtf;base64, ${string}` | `data:application/x-sh;base64, ${string}` | `data:application/sql;base64, ${string}` | `data:image/svg+xml;base64, ${string}` | `data:application/x-tar;base64, ${string}` | `data:image/tiff;base64, ${string}` | `data:application/toml;base64, ${string}` | `data:text/typescript;base64, ${string}` | `data:video/mp2t;base64, ${string}` | `data:video/vnd.dlna.mpeg-tts;base64, ${string}` | `data:application/font-sfnt;base64, ${string}` | `data:font/ttf;base64, ${string}` | `data:model/vnd.usdz+zip;base64, ${string}` | `data:application/vnd.visio;base64, ${string}` | `data:text/vtt;base64, ${string}` | `data:application/wasm;base64, ${string}` | `data:audio/wav;base64, ${string}` | `data:video/webm;base64, ${string}` | `data:image/webp;base64, ${string}` | `data:font/woff;base64, ${string}` | `data:font/woff2;base64, ${string}` | `data:application/xhtml+xml;base64, ${string}` | `data:application/vnd.ms-excel;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64, ${string}` | `data:application/xml;base64, ${string}` | `data:application/vnd.mozilla.xul+xml;base64, ${string}` | `data:application/yaml;base64, ${string}` | `data:application/zip;base64, ${string}` | `data:application/x-zip-compressed;base64, ${string}` | `data:video/3gpp;base64, ${string}` | `data:video/3gpp2;base64, ${string}` | `data:application/x-7z-compressed;base64, ${string}`;
36
113
  readonly extension: "aac" | "abw" | "aces" | "apng" | "arc" | "avci" | "avif" | "avi" | "azw" | "bin" | "bmp" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "doc" | "docx" | "dpx" | "emf" | "eot" | "epub" | "gif" | "glb" | "gltf" | "gz" | "hjif" | "hmpg" | "htm" | "html" | "ico" | "ics" | "ivs" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rtf" | "sh" | "sql" | "svg" | "tar" | "tif" | "tiff" | "toml" | "ts" | "ttf" | "txt" | "usdz" | "vsd" | "vtt" | "wasm" | "wav" | "weba" | "webp" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "yaml" | "yml" | "zip" | "3gp" | "3g2" | "7z";
37
114
  }>;
38
115
  assetToBufferView<const T extends string>(path: T): Promise<{