@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.
@@ -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>;
@@ -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<{
package/dist/fs/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  Fs
3
- } from "../chunk-KZWE4E4I.js";
3
+ } from "../chunk-XIAKCF2X.js";
4
4
  import "../chunk-EHOBCDHE.js";
5
+ import "../chunk-4X5DVWVM.js";
5
6
  import "../chunk-XHN56MDK.js";
6
7
  import "../chunk-7QVYU63E.js";
7
8
  export {
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
- return import_fs.default.existsSync((0, import_path.resolve)((0, import_path.join)(this.cwd, target)));
241
- return import_fs.default.existsSync((0, import_path.relative)(this.cwd ?? process.cwd(), target));
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
- readDir(path, options) {
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,9 +377,7 @@ var Fs = class extends MimeService {
274
377
  "utf-8"
275
378
  ), "executeCommand");
276
379
  existsSync(path) {
277
- if (!/\//gm.test(path))
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, 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;
@@ -284,12 +385,56 @@ var Fs = class extends MimeService {
284
385
  mkdirSync(path, options) {
285
386
  return import_fs.default.mkdirSync((0, import_path.relative)(this.cwd, path), options);
286
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);
422
+ }
287
423
  fileSizeMb(path) {
288
424
  return import_fs.default.statSync((0, import_path.relative)(this.cwd, path)).size / (1024 * 1024);
289
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
+ }
435
+ }
290
436
  generateDirIfDNE(path, options) {
291
- const doesExist = this.existsSync(path);
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.existsSync(filePath)) {
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.dirExists(dir)) {
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.dirExists(dir)) {
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);
@@ -525,7 +662,9 @@ var Fs = class extends MimeService {
525
662
  return await (0, import_sharp.default)(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
526
663
  } else if (tint && resize) {
527
664
  return await (0, import_sharp.default)(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
528
- } else return await (0, import_sharp.default)(target).toFormat(format, { quality }).toBuffer();
665
+ } else {
666
+ return await (0, import_sharp.default)(target).toFormat(format, { quality }).toBuffer();
667
+ }
529
668
  }
530
669
  };
531
670
 
@@ -657,6 +796,7 @@ var UtilsService = class {
657
796
  MimeService,
658
797
  UrlService,
659
798
  UtilsService,
660
- extMimeMap
799
+ extMimeMap,
800
+ unitsObj
661
801
  });
662
802
  //# 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-KZWE4E4I.js";
3
+ } from "./chunk-XIAKCF2X.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
@@ -229,10 +229,10 @@ declare class MimeService extends UrlService {
229
229
  getMimeFor<const E extends FileExtension>(ext: E, opts?: {
230
230
  type?: MimeTopLevelType;
231
231
  }): FileExtensionToMimeType<E>;
232
- isMimeFor<const E extends FileExtension>(ext: E, mime: FileExtensionToMimeType<E>): "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "application/octet-stream" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/node" | "text/javascript" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "application/x-gzip" | "application/gzip" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "image/jpeg" | "application/json" | "application/ld+json" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/x-ndjson" | "text/plain" | "model/obj" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "application/x-python-code" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "application/sql" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "application/toml" | "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed" | undefined;
232
+ isMimeFor<const E extends FileExtension>(ext: E, mime: FileExtensionToMimeType<E>): "application/octet-stream" | "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/node" | "text/javascript" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "application/x-gzip" | "application/gzip" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "image/jpeg" | "application/json" | "application/ld+json" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/x-ndjson" | "text/plain" | "model/obj" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "application/x-python-code" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "application/sql" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "application/toml" | "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed" | undefined;
233
233
  getMimeTypeForPath<T extends string>(path: T, opts?: {
234
234
  type?: MimeTopLevelType;
235
- }): "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "application/octet-stream" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/node" | "text/javascript" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "application/x-gzip" | "application/gzip" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "image/jpeg" | "application/json" | "application/ld+json" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/x-ndjson" | "text/plain" | "model/obj" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "application/x-python-code" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "application/sql" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "application/toml" | "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed";
235
+ }): "application/octet-stream" | "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/node" | "text/javascript" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "application/x-gzip" | "application/gzip" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "image/jpeg" | "application/json" | "application/ld+json" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/x-ndjson" | "text/plain" | "model/obj" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "application/x-python-code" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "application/sql" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "application/toml" | "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed";
236
236
  }
237
237
 
238
238
  export { type AllMimeTypes, type FileExtension, type FileExtensionToMimeType, type InferTopLevelPresent, MimeService, type MimeTopLevelType, type PresentMimeTopLevelTypes, extMimeMap };
@@ -229,10 +229,10 @@ declare class MimeService extends UrlService {
229
229
  getMimeFor<const E extends FileExtension>(ext: E, opts?: {
230
230
  type?: MimeTopLevelType;
231
231
  }): FileExtensionToMimeType<E>;
232
- isMimeFor<const E extends FileExtension>(ext: E, mime: FileExtensionToMimeType<E>): "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "application/octet-stream" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/node" | "text/javascript" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "application/x-gzip" | "application/gzip" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "image/jpeg" | "application/json" | "application/ld+json" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/x-ndjson" | "text/plain" | "model/obj" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "application/x-python-code" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "application/sql" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "application/toml" | "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed" | undefined;
232
+ isMimeFor<const E extends FileExtension>(ext: E, mime: FileExtensionToMimeType<E>): "application/octet-stream" | "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/node" | "text/javascript" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "application/x-gzip" | "application/gzip" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "image/jpeg" | "application/json" | "application/ld+json" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/x-ndjson" | "text/plain" | "model/obj" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "application/x-python-code" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "application/sql" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "application/toml" | "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed" | undefined;
233
233
  getMimeTypeForPath<T extends string>(path: T, opts?: {
234
234
  type?: MimeTopLevelType;
235
- }): "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "application/octet-stream" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/node" | "text/javascript" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "application/x-gzip" | "application/gzip" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "image/jpeg" | "application/json" | "application/ld+json" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/x-ndjson" | "text/plain" | "model/obj" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "application/x-python-code" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "application/sql" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "application/toml" | "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed";
235
+ }): "application/octet-stream" | "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/node" | "text/javascript" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "application/x-gzip" | "application/gzip" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "image/jpeg" | "application/json" | "application/ld+json" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/x-ndjson" | "text/plain" | "model/obj" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "application/x-python-code" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "application/sql" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "application/toml" | "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed";
236
236
  }
237
237
 
238
238
  export { type AllMimeTypes, type FileExtension, type FileExtensionToMimeType, type InferTopLevelPresent, MimeService, type MimeTopLevelType, type PresentMimeTopLevelTypes, extMimeMap };
@@ -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
@@ -101,10 +101,13 @@ type WriteStreamOptions = BufferEncodingUnion | {
101
101
  type WriteFileAsyncDataUnion = WithImplicitCoercion<string> | {
102
102
  [Symbol.toPrimitive](hint: "string"): string;
103
103
  };
104
- type ReadDirOptions = BufferEncodingUnion | ((ObjEncodingOptions & {
104
+ interface ReadDirOptionsEntity extends ObjEncodingOptions {
105
105
  withFileTypes?: false | undefined;
106
106
  recursive?: boolean | undefined;
107
- }) | null);
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 { 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 };
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 };