@d0paminedriven/fs 7.0.1 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts DELETED
@@ -1,9 +0,0 @@
1
- export { default as Fs } from './fs/index.cjs';
2
- export { AllMimeTypes, FileExtension, FileExtensionToMimeType, InferTopLevelPresent, MimeService, MimeTopLevelType, MimeType, MimeTypeToFileExtension, PresentMimeTopLevelTypes, extMimeMap, mimeToExt } from './mime/index.cjs';
3
- export { Abortable, ArrFieldReplacer, ArrayBufferView, ArrayOrReadOnlyArray, BashEnv, BoxInfo, BufferEncodingUnion, CTR, CoercionUnion, CommonExecOptions, CommonOptions, ConditionalPromise, ConditionalToRequired, DX, DeepPartial, DeepPartialFields, DeepReplace, Depth, Dict, Equal, ExcludeFieldEnumerable, ExecSyncOptions, ExecSyncOptionsWithBufferEncoding, ExecSyncOptionsWithStringEncoding, ExecuteCommandProps, Expect, Extends, FieldToConditionallyNever, IOType, ImageSize, InferDepth, InjectScriptsProps, IsExact, IsOptional, MkDirOptions, MkDirSyncOptions, MkDirSyncProps, Mode, ObjEncodingOptions, OmitSrc, OnlyOptional, OnlyRequired, OpenMode, ParsedUrlInfo, ProcessEnv, ProcessEnvOptions, RTC, ReadDirOptions, ReadDirOptionsEntity, ReadDirProps, RemoveFields, RequireNested, RequiredToConditional, Rm, RmDirOptions, RmDirProps, Signals, SizeOpts, StdioOptions, TCN, TypedArray, Unenumerate, Unit, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR, unitsObj } from './types/index.cjs';
4
- export { HandleQueryParamsOrHash, InferExtensionIfPresent, LastSegment, SplitForwardSlash, UrlFileExt, UrlService } from './url/index.cjs';
5
- export { UtilsService } from './utils/index.cjs';
6
- import 'dotenv-expand';
7
- import 'sharp';
8
- import 'stream';
9
- import 'buffer';
@@ -1,494 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/mime/index.ts
22
- var mime_exports = {};
23
- __export(mime_exports, {
24
- MimeService: () => MimeService,
25
- extMimeMap: () => extMimeMap,
26
- mimeToExt: () => mimeToExt
27
- });
28
- module.exports = __toCommonJS(mime_exports);
29
-
30
- // src/utils/index.ts
31
- var UtilsService = class {
32
- static {
33
- __name(this, "UtilsService");
34
- }
35
- chunkArray(arr, maxChunkLength) {
36
- const chunks = Array.of();
37
- let currentChunkLength = 0;
38
- let currentChunk = Array.of();
39
- for (const [index, val] of arr.entries()) {
40
- if (val.length + currentChunkLength >= maxChunkLength) {
41
- if (currentChunk.length) {
42
- chunks.push(currentChunk);
43
- }
44
- currentChunkLength = val.length;
45
- currentChunk = [val];
46
- } else {
47
- currentChunk.push(val);
48
- currentChunkLength += val.length + 1;
49
- }
50
- if (arr.length === index + 1) {
51
- chunks.push(currentChunk);
52
- }
53
- }
54
- return chunks.length ? chunks : [arr];
55
- }
56
- b64ToBlob(b64Data) {
57
- {
58
- const sliceSize = 512;
59
- const typeMatch = /^data:((?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*);base64,(.+)$/i.exec(
60
- b64Data
61
- );
62
- if (!typeMatch) {
63
- throw new Error(`${b64Data} is not a valid data Url`);
64
- }
65
- const type = typeMatch[1];
66
- const base64Data = typeMatch?.[2] ?? "";
67
- const byteCharacters = Buffer.from(base64Data, "base64").toString(
68
- "binary"
69
- );
70
- const byteArrays = Array.of();
71
- for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
72
- const slice = byteCharacters.slice(offset, offset + sliceSize);
73
- const byteNumbers = new Array(slice.length);
74
- for (let i = 0; i < slice.length; i++) {
75
- byteNumbers[i] = slice.charCodeAt(i);
76
- }
77
- const byteArray = new Uint8Array(byteNumbers);
78
- byteArrays.push(byteArray);
79
- }
80
- const blob = new Blob(byteArrays, { type });
81
- return blob;
82
- }
83
- }
84
- arrToArrOfArrs = /* @__PURE__ */ __name(({
85
- arrToFragment = Array.of(),
86
- arrOfArrsAggregator = Array.of(),
87
- interval
88
- }) => new Promise(
89
- (resolve, _reject) => resolve(
90
- ((interval2) => {
91
- for (let i = 0; i <= arrToFragment.length; i++) {
92
- if ((i % interval2 === 0 || i === 0) && i <= arrToFragment.length) {
93
- let segment = arrToFragment.slice(i, i + interval2);
94
- arrOfArrsAggregator.push(segment);
95
- }
96
- }
97
- })(interval)
98
- )
99
- ).then((_) => arrOfArrsAggregator), "arrToArrOfArrs");
100
- extractTuple(obj, props) {
101
- return [props, obj[props]];
102
- }
103
- sort(obj, order) {
104
- return Object.fromEntries(
105
- Object.entries(obj).sort(
106
- ([a, _aa], [b, _bb]) => order === "DESC" ? b.localeCompare(a) - a.localeCompare(b) : a.localeCompare(b) - b.localeCompare(a)
107
- )
108
- );
109
- }
110
- excludeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
111
- const resolve = Object.fromEntries(
112
- Object.entries(obj).map(([key, val]) => {
113
- if (props.includes(key)) {
114
- return ["omit", "omit"];
115
- } else return [key, val];
116
- }).filter(([t, _v]) => /omit/.test(t) === false)
117
- );
118
- return typeof sort !== "undefined" ? this.sort(resolve, sort) : resolve;
119
- }, "excludeTargeted");
120
- includeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
121
- const resolve = Object.fromEntries(
122
- props.map((val) => this.extractTuple(obj, val))
123
- );
124
- return typeof sort !== "undefined" ? this.sort(resolve, sort) : resolve;
125
- }, "includeTargeted");
126
- countsSorter = /* @__PURE__ */ __name((counter, keySort = "ASC", valSort = "DESC") => Object.fromEntries(
127
- Array.from(Object.entries(counter)).sort(
128
- ([aStr, _aNum], [bStr, _bNum]) => keySort === "DESC" ? bStr.localeCompare(aStr) - aStr.localeCompare(bStr) : aStr.localeCompare(bStr) - bStr.localeCompare(aStr)
129
- ).sort(([aStr, aNum], [bStr, bNum]) => {
130
- if (typeof (aNum && bNum) === "number") {
131
- return valSort === "ASC" ? aNum - bNum : bNum - aNum;
132
- } else if (typeof (aNum && bNum) === "string") {
133
- return valSort === "ASC" ? aStr.localeCompare(bStr) - bStr.localeCompare(aStr) : bStr.localeCompare(aStr) - aStr.localeCompare(bStr);
134
- } else
135
- throw new Error(
136
- "only Record<string, string> and Record<string,number> types supported"
137
- );
138
- })
139
- ), "countsSorter");
140
- range(from, to) {
141
- const values = Array.of();
142
- for (let i = from; i < to; i++) {
143
- values.push(i);
144
- }
145
- return values;
146
- }
147
- isPrimeNumber = /* @__PURE__ */ __name((n) => {
148
- for (let i = 2; n > i; i++) {
149
- if (n % i === 0) {
150
- return false;
151
- }
152
- }
153
- return n > 1;
154
- }, "isPrimeNumber");
155
- acceptor = /* @__PURE__ */ __name((num) => [...Array(num !== 0 ? num : this.range(num = -101, num = 101)).keys()].reverse().filter(this.isPrimeNumber), "acceptor");
156
- };
157
-
158
- // src/url/index.ts
159
- var UrlService = class extends UtilsService {
160
- static {
161
- __name(this, "UrlService");
162
- }
163
- URL_REGEX = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
164
- parseUrl(url) {
165
- const parsed = this.URL_REGEX.exec(url);
166
- if (parsed) {
167
- return {
168
- href: parsed[0],
169
- protocol: parsed[1] ?? "",
170
- baseUrl: `${parsed[1]}${parsed[3]}`,
171
- host: parsed[4] ?? "",
172
- pathname: parsed[5] ?? "",
173
- search: parsed[6] ?? "",
174
- hash: parsed[8] ?? ""
175
- };
176
- } else return null;
177
- }
178
- };
179
-
180
- // src/mime/index.ts
181
- var extMimeMap = {
182
- aac: ["audio/aac"],
183
- abw: ["application/x-abiword"],
184
- aces: ["image/aces"],
185
- apng: ["image/apng"],
186
- arc: ["application/x-freearc"],
187
- avci: ["image/avci"],
188
- avif: ["image/avif"],
189
- avi: ["video/x-msvideo"],
190
- azw: ["application/vnd.amazon.ebook"],
191
- bin: ["application/octet-stream", "multipart/voice-message"],
192
- bmp: ["image/bmp"],
193
- bz: ["application/x-bzip"],
194
- bz2: ["application/x-bzip2"],
195
- cda: ["application/x-cdf"],
196
- cjs: ["application/node", "text/javascript"],
197
- csh: ["application/x-csh"],
198
- css: ["text/css"],
199
- csv: ["text/csv"],
200
- doc: ["application/msword"],
201
- docx: [
202
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
203
- ],
204
- dpx: ["image/dpx"],
205
- emf: ["image/emf"],
206
- eot: ["application/vnd.ms-fontobject"],
207
- epub: ["application/epub+zip"],
208
- gif: ["image/gif"],
209
- glb: ["model/gltf-binary"],
210
- gltf: ["model/gltf+json"],
211
- gz: ["application/gzip", "application/x-gzip"],
212
- hjif: ["haptics/hjif"],
213
- hmpg: ["haptics/hmpg"],
214
- htm: ["text/html"],
215
- html: ["text/html"],
216
- ico: ["image/vnd.microsoft.icon"],
217
- ics: ["text/calendar"],
218
- ivs: ["haptics/ivs"],
219
- ivt: ["haptics/ivs"],
220
- jar: ["application/java-archive"],
221
- jpeg: ["image/jpeg"],
222
- jpg: ["image/jpeg"],
223
- js: ["application/node", "text/javascript"],
224
- json: ["application/json"],
225
- jsonld: ["application/ld+json"],
226
- ktx: ["image/ktx"],
227
- ktx2: ["image/ktx2"],
228
- m3u8: ["application/vnd.apple.mpegurl"],
229
- m4a: ["audio/mp4"],
230
- m4v: ["video/mp4"],
231
- md: ["text/markdown"],
232
- mdx: ["application/x-mdx"],
233
- mid: ["audio/midi"],
234
- midi: ["audio/x-midi"],
235
- mjs: ["text/javascript"],
236
- mp3: ["audio/mpeg"],
237
- mp4: ["video/mp4"],
238
- mpeg: ["video/mpeg"],
239
- mpkg: ["application/vnd.apple.installer+xml"],
240
- ndjson: ["application/x-ndjson"],
241
- node: ["application/node", "text/javascript"],
242
- obj: ["model/obj", "application/octet-stream", "text/plain"],
243
- odp: ["application/vnd.oasis.opendocument.presentation"],
244
- ods: ["application/vnd.oasis.opendocument.spreadsheet"],
245
- odt: ["application/vnd.oasis.opendocument.text"],
246
- oga: ["audio/ogg"],
247
- ogg: ["audio/ogg"],
248
- ogv: ["video/ogg"],
249
- ogx: ["application/ogg"],
250
- opus: ["audio/ogg"],
251
- otf: ["font/otf"],
252
- png: ["image/png"],
253
- pdf: ["application/pdf"],
254
- php: ["application/x-httpd-php"],
255
- pkpass: ["application/vnd.apple.pkpass"],
256
- ppt: ["application/vnd.ms-powerpoint"],
257
- pptx: [
258
- "application/vnd.openxmlformats-officedocument.presentationml.presentation"
259
- ],
260
- py: ["text/x-python"],
261
- pyc: ["application/x-python-code"],
262
- rar: ["application/vnd.rar"],
263
- rs: ["text/rust"],
264
- rtf: ["application/rtf"],
265
- sh: ["application/x-sh"],
266
- sql: ["application/sql"],
267
- sse: ["text/event-stream"],
268
- svg: ["image/svg+xml"],
269
- tar: ["application/x-tar"],
270
- tif: ["image/tiff"],
271
- tiff: ["image/tiff"],
272
- toml: ["application/toml"],
273
- ts: ["text/typescript", "video/mp2t", "video/vnd.dlna.mpeg-tts"],
274
- ttf: ["application/font-sfnt", "font/ttf"],
275
- txt: ["text/plain"],
276
- usdz: ["model/vnd.usdz+zip"],
277
- vsd: ["application/vnd.visio"],
278
- vtt: ["text/vtt"],
279
- wasm: ["application/wasm"],
280
- wav: ["audio/wav"],
281
- weba: ["video/webm"],
282
- webp: ["image/webp"],
283
- woff: ["font/woff"],
284
- woff2: ["font/woff2"],
285
- xhtml: ["application/xhtml+xml"],
286
- xls: ["application/vnd.ms-excel"],
287
- xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
288
- xml: ["application/xml"],
289
- xul: ["application/vnd.mozilla.xul+xml"],
290
- yaml: ["application/yaml"],
291
- yml: ["application/yaml"],
292
- zip: ["application/zip", "application/x-zip-compressed"],
293
- "3gp": ["video/3gpp"],
294
- "3g2": ["video/3gpp2"],
295
- "7z": ["application/x-7z-compressed"]
296
- };
297
- var mimeToExt = {
298
- "application/epub+zip": ["epub"],
299
- "application/font-sfnt": ["ttf"],
300
- "application/gzip": ["gz"],
301
- "application/java-archive": ["jar"],
302
- "application/json": ["json"],
303
- "application/ld+json": ["jsonld"],
304
- "application/msword": ["doc"],
305
- "application/node": ["node", "js"],
306
- "application/octet-stream": ["bin", "obj"],
307
- "application/ogg": ["ogx"],
308
- "application/pdf": ["pdf"],
309
- "application/rtf": ["rtf"],
310
- "application/sql": ["sql"],
311
- "application/toml": ["toml"],
312
- "application/vnd.amazon.ebook": ["azw"],
313
- "application/vnd.apple.installer+xml": ["mpkg"],
314
- "application/vnd.apple.mpegurl": ["m3u8"],
315
- "application/vnd.apple.pkpass": ["pkpass"],
316
- "application/vnd.mozilla.xul+xml": ["xul"],
317
- "application/vnd.ms-excel": ["xls"],
318
- "application/vnd.ms-fontobject": ["eot"],
319
- "application/vnd.ms-powerpoint": ["ppt"],
320
- "application/vnd.oasis.opendocument.presentation": ["odp"],
321
- "application/vnd.oasis.opendocument.spreadsheet": ["ods"],
322
- "application/vnd.oasis.opendocument.text": ["odt"],
323
- "application/vnd.openxmlformats-officedocument.presentationml.presentation": [
324
- "pptx"
325
- ],
326
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ["xlsx"],
327
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [
328
- "docx"
329
- ],
330
- "application/vnd.rar": ["rar"],
331
- "application/vnd.visio": ["vsd"],
332
- "application/wasm": ["wasm"],
333
- "application/x-7z-compressed": ["7z"],
334
- "application/x-abiword": ["abw"],
335
- "application/x-bzip": ["bz"],
336
- "application/x-bzip2": ["bz2"],
337
- "application/x-cdf": ["cda"],
338
- "application/x-csh": ["csh"],
339
- "application/x-freearc": ["arc"],
340
- "application/x-gzip": ["gz"],
341
- "application/x-httpd-php": ["php"],
342
- "application/x-mdx": ["mdx"],
343
- "application/x-ndjson": ["ndjson"],
344
- "application/x-python-code": ["pyc"],
345
- "application/x-sh": ["sh"],
346
- "application/x-tar": ["tar"],
347
- "application/x-zip-compressed": ["zip"],
348
- "application/xhtml+xml": ["xhtml"],
349
- "application/xml": ["xml"],
350
- "application/yaml": ["yml", "yaml"],
351
- "application/zip": ["zip"],
352
- "audio/aac": ["aac"],
353
- "audio/midi": ["mid"],
354
- "audio/mp4": ["m4a"],
355
- "audio/mpeg": ["mp3"],
356
- "audio/ogg": ["opus", "ogg", "oga"],
357
- "audio/wav": ["wav"],
358
- "audio/x-midi": ["midi"],
359
- "font/otf": ["otf"],
360
- "font/ttf": ["ttf"],
361
- "font/woff": ["woff"],
362
- "font/woff2": ["woff2"],
363
- "haptics/hjif": ["hjif"],
364
- "haptics/hmpg": ["hmpg"],
365
- "haptics/ivs": ["ivs", "ivt"],
366
- "image/aces": ["aces"],
367
- "image/apng": ["apng"],
368
- "image/avci": ["avci"],
369
- "image/avif": ["avif"],
370
- "image/bmp": ["bmp"],
371
- "image/dpx": ["dpx"],
372
- "image/emf": ["emf"],
373
- "image/gif": ["gif"],
374
- "image/jpeg": ["jpg", "jpeg"],
375
- "image/ktx": ["ktx"],
376
- "image/ktx2": ["ktx2"],
377
- "image/png": ["png"],
378
- "image/svg+xml": ["svg"],
379
- "image/tiff": ["tiff", "tif"],
380
- "image/vnd.microsoft.icon": ["ico"],
381
- "image/webp": ["webp"],
382
- "model/gltf-binary": ["glb"],
383
- "model/gltf+json": ["gltf"],
384
- "model/obj": ["obj"],
385
- "model/vnd.usdz+zip": ["usdz"],
386
- "multipart/voice-message": ["bin"],
387
- "text/calendar": ["ics"],
388
- "text/css": ["css"],
389
- "text/csv": ["csv"],
390
- "text/event-stream": ["sse", "ts", "rs", "py", "txt"],
391
- "text/html": ["html", "htm"],
392
- "text/javascript": ["cjs", "js", "mjs"],
393
- "text/markdown": ["md"],
394
- "text/plain": ["txt"],
395
- "text/rust": ["rs"],
396
- "text/typescript": ["ts"],
397
- "text/vtt": ["vtt"],
398
- "text/x-python": ["py"],
399
- "video/3gpp": ["3gp"],
400
- "video/3gpp2": ["3g2"],
401
- "video/mp2t": ["ts"],
402
- "video/mp4": ["mp4", "m4v"],
403
- "video/mpeg": ["mpeg"],
404
- "video/ogg": ["ogv"],
405
- "video/vnd.dlna.mpeg-tts": ["ts"],
406
- "video/webm": ["weba"],
407
- "video/x-msvideo": ["avi"]
408
- };
409
- var MimeService = class extends UrlService {
410
- static {
411
- __name(this, "MimeService");
412
- }
413
- constructor() {
414
- super();
415
- }
416
- mimeTypeObj = extMimeMap;
417
- toExtObj = mimeToExt;
418
- compareMimeToExt(p = "mime") {
419
- let a = {};
420
- if (p === "mime") {
421
- for (const [_key, vals] of Object.entries(extMimeMap)) {
422
- for (const val of vals) {
423
- a[val] = (a[val] ?? 0) + 1;
424
- }
425
- }
426
- for (const [key, _val] of Object.entries(mimeToExt)) {
427
- a[key] = (a[key] ?? 0) + 1;
428
- }
429
- return Object.fromEntries(
430
- Object.entries(a).sort(([_a, aa], [_b, bb]) => bb - aa)
431
- );
432
- } else {
433
- for (const [_key, vals] of Object.entries(mimeToExt)) {
434
- for (const val of vals) {
435
- a[val] = (a[val] ?? 0) + 1;
436
- }
437
- }
438
- for (const [key, _val] of Object.entries(extMimeMap)) {
439
- a[key] = (a[key] ?? 0) + 1;
440
- }
441
- return Object.fromEntries(
442
- Object.entries(a).sort(([_a, aa], [_b, bb]) => bb - aa)
443
- );
444
- }
445
- }
446
- mimeToExt(mime) {
447
- const extensions = this.toExtObj[mime];
448
- if (extensions.length === 1) return extensions[0];
449
- if (extensions.length === 2) {
450
- return extensions[0];
451
- }
452
- if (extensions.length === 3) {
453
- if (mime === "audio/ogg") return "ogg";
454
- return extensions[0];
455
- }
456
- if (extensions.length === 5) {
457
- return "sse";
458
- }
459
- return extensions[0];
460
- }
461
- assetType(url) {
462
- const parsed = this.parseUrl(url);
463
- if (!parsed) return void 0;
464
- const ext = parsed.pathname.split(/([.])/g)?.reverse()?.[0]?.toLowerCase();
465
- return ext && ext in this.mimeTypeObj ? ext : void 0;
466
- }
467
- getMimes(ext) {
468
- return this.mimeTypeObj[ext];
469
- }
470
- getMimeFor(ext, opts) {
471
- const mimes = this.getMimes(ext);
472
- if (mimes.length === 1) return mimes[0];
473
- if (opts?.type) {
474
- const found = mimes.find((mime) => mime.startsWith(opts.type + "/"));
475
- return found ?? mimes[0];
476
- }
477
- return mimes[0];
478
- }
479
- isMimeFor(ext, mime) {
480
- return this.getMimes(ext).find((s) => s === mime);
481
- }
482
- getMimeTypeForPath(path, opts) {
483
- const ext = this.assetType(path);
484
- if (!ext) return "application/octet-stream";
485
- return this.getMimeFor(ext, opts);
486
- }
487
- };
488
- // Annotate the CommonJS export names for ESM import in node:
489
- 0 && (module.exports = {
490
- MimeService,
491
- extMimeMap,
492
- mimeToExt
493
- });
494
- //# sourceMappingURL=index.cjs.map