@d0paminedriven/fs 0.1.0 → 1.0.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/{chunk-K45COKAJ.js → chunk-MFKSUNKN.js} +94 -32
- package/dist/fs/index.cjs +93 -31
- package/dist/fs/index.d.cts +141 -9
- package/dist/fs/index.d.ts +141 -9
- package/dist/fs/index.js +1 -1
- package/dist/index.cjs +93 -31
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/types/index.d.cts +2 -1
- package/dist/types/index.d.ts +2 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -363,11 +363,22 @@ var Fs = class {
|
|
|
363
363
|
/* end url */
|
|
364
364
|
get gzVal() {
|
|
365
365
|
return ["application/x-gzip", "application/gzip"].reduce(
|
|
366
|
-
(
|
|
366
|
+
(union) => union
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
get objVal() {
|
|
370
|
+
return ["application/octet-stream", "text/plain", "model/obj"].reduce((union) => union);
|
|
371
|
+
}
|
|
372
|
+
get tsVal() {
|
|
373
|
+
return ["text/typescript", "video/mp2t", "video/vnd.dlna.mpeg-tts"].reduce((union) => union);
|
|
374
|
+
}
|
|
375
|
+
get ttfVal() {
|
|
376
|
+
return ["application/font-sfnt", "font/ttf"].reduce(
|
|
377
|
+
(union) => union
|
|
367
378
|
);
|
|
368
379
|
}
|
|
369
380
|
get zipVal() {
|
|
370
|
-
return ["application/zip", "application/x-zip-compressed"].reduce((
|
|
381
|
+
return ["application/zip", "application/x-zip-compressed"].reduce((union) => union);
|
|
371
382
|
}
|
|
372
383
|
get mimeTypeObj() {
|
|
373
384
|
return {
|
|
@@ -392,6 +403,8 @@ var Fs = class {
|
|
|
392
403
|
eot: "application/vnd.ms-fontobject",
|
|
393
404
|
epub: "application/epub+zip",
|
|
394
405
|
gif: "image/gif",
|
|
406
|
+
glb: "model/gltf-binary",
|
|
407
|
+
gltf: "model/gltf+json",
|
|
395
408
|
gz: this.gzVal,
|
|
396
409
|
htm: "text/html",
|
|
397
410
|
html: "text/html",
|
|
@@ -404,6 +417,8 @@ var Fs = class {
|
|
|
404
417
|
json: "application/json",
|
|
405
418
|
jsonld: "application/ld+json",
|
|
406
419
|
m3u8: "application/vnd.apple.mpegurl",
|
|
420
|
+
m4a: "audio/mp4",
|
|
421
|
+
m4v: "video/mp4",
|
|
407
422
|
md: "text/markdown",
|
|
408
423
|
mdx: "application/x-mdx",
|
|
409
424
|
mid: "audio/midi",
|
|
@@ -414,10 +429,12 @@ var Fs = class {
|
|
|
414
429
|
mpeg: "video/mpeg",
|
|
415
430
|
mpkg: "application/vnd.apple.installer+xml",
|
|
416
431
|
ndjson: "application/x-ndjson",
|
|
432
|
+
obj: this.objVal,
|
|
417
433
|
odp: "application/vnd.oasis.opendocument.presentation",
|
|
418
434
|
ods: "application/vnd.oasis.opendocument.spreadsheet",
|
|
419
435
|
odt: "application/vnd.oasis.opendocument.text",
|
|
420
436
|
oga: "audio/ogg",
|
|
437
|
+
ogg: "audio/ogg",
|
|
421
438
|
ogv: "video/ogg",
|
|
422
439
|
ogx: "application/ogg",
|
|
423
440
|
opus: "audio/ogg",
|
|
@@ -428,6 +445,8 @@ var Fs = class {
|
|
|
428
445
|
pkpass: "application/vnd.apple.pkpass",
|
|
429
446
|
ppt: "application/vnd.ms-powerpoint",
|
|
430
447
|
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
448
|
+
py: "text/x-python",
|
|
449
|
+
pyc: "application/x-python-code",
|
|
431
450
|
rar: "application/vnd.rar",
|
|
432
451
|
rtf: "application/rtf",
|
|
433
452
|
sh: "application/x-sh",
|
|
@@ -435,10 +454,12 @@ var Fs = class {
|
|
|
435
454
|
tar: "application/x-tar",
|
|
436
455
|
tif: "image/tiff",
|
|
437
456
|
tiff: "image/tiff",
|
|
438
|
-
ts:
|
|
439
|
-
ttf:
|
|
457
|
+
ts: this.tsVal,
|
|
458
|
+
ttf: this.ttfVal,
|
|
440
459
|
txt: "text/plain",
|
|
441
460
|
vsd: "application/vnd.visio",
|
|
461
|
+
vtt: "text/vtt",
|
|
462
|
+
wasm: "application/wasm",
|
|
442
463
|
wav: "audio/wav",
|
|
443
464
|
weba: "video/webm",
|
|
444
465
|
webp: "image/webp",
|
|
@@ -456,18 +477,20 @@ var Fs = class {
|
|
|
456
477
|
};
|
|
457
478
|
}
|
|
458
479
|
assetType(url) {
|
|
459
|
-
|
|
480
|
+
const u = this.parseUrl(url);
|
|
481
|
+
return u.pathname?.split(/([.])/gim)?.reverse()?.[0];
|
|
460
482
|
}
|
|
461
483
|
getMime(input) {
|
|
462
484
|
return this.mimeTypeObj[input];
|
|
463
485
|
}
|
|
486
|
+
hmm = /* @__PURE__ */ __name((input) => {
|
|
487
|
+
return this.mimeTypeObj[input];
|
|
488
|
+
}, "hmm");
|
|
464
489
|
async assetToBuffer(path) {
|
|
465
490
|
const [fetcher] = await Promise.all([
|
|
466
491
|
fetch(path).then((t) => t.arrayBuffer())
|
|
467
492
|
]);
|
|
468
|
-
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(
|
|
469
|
-
Buffer.from(fetcher).toJSON().data
|
|
470
|
-
).toString("base64")}`;
|
|
493
|
+
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(fetcher).toString("base64")}`;
|
|
471
494
|
const extension = this.assetType(path);
|
|
472
495
|
return {
|
|
473
496
|
b64encodedData,
|
|
@@ -475,27 +498,34 @@ var Fs = class {
|
|
|
475
498
|
};
|
|
476
499
|
}
|
|
477
500
|
async assetToBufferView(path) {
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
501
|
+
const response = await fetch(path);
|
|
502
|
+
if (!response.ok) {
|
|
503
|
+
throw new Error(`Failed to fetch asset: ${response.statusText}`);
|
|
504
|
+
}
|
|
505
|
+
const reader = response.body?.getReader();
|
|
506
|
+
if (reader) {
|
|
507
|
+
const chunks = [];
|
|
508
|
+
while (true) {
|
|
509
|
+
const { done, value } = await reader.read();
|
|
510
|
+
if (done) break;
|
|
511
|
+
if (value) chunks.push(value);
|
|
486
512
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
b64encodedData,
|
|
497
|
-
|
|
498
|
-
|
|
513
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
514
|
+
const completeBuffer = new Uint8Array(totalLength);
|
|
515
|
+
let offset = 0;
|
|
516
|
+
for (const chunk of chunks) {
|
|
517
|
+
completeBuffer.set(chunk, offset);
|
|
518
|
+
offset += chunk.length;
|
|
519
|
+
}
|
|
520
|
+
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(completeBuffer).toString("base64")}`;
|
|
521
|
+
const extension = this.assetType(path);
|
|
522
|
+
return { b64encodedData, extension };
|
|
523
|
+
} else {
|
|
524
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
525
|
+
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(arrayBuffer).toString("base64")}`;
|
|
526
|
+
const extension = this.assetType(path);
|
|
527
|
+
return { b64encodedData, extension };
|
|
528
|
+
}
|
|
499
529
|
}
|
|
500
530
|
formatHelper(f) {
|
|
501
531
|
if (/([A-Za-z]+-[A-Za-z]+)/g.test(f) === true) {
|
|
@@ -504,7 +534,7 @@ var Fs = class {
|
|
|
504
534
|
} else return f.substring(0, 1).toUpperCase().concat(f.substring(1));
|
|
505
535
|
}
|
|
506
536
|
range(from, to) {
|
|
507
|
-
const values =
|
|
537
|
+
const values = Array.of();
|
|
508
538
|
for (let i = from; i < to; i++) {
|
|
509
539
|
values.push(i);
|
|
510
540
|
}
|
|
@@ -544,10 +574,9 @@ var Fs = class {
|
|
|
544
574
|
{
|
|
545
575
|
const sliceSize = 512;
|
|
546
576
|
const typeMatch = b64Data.match(
|
|
547
|
-
/^data:(image|application|video|text|font)\/[A-Za-z0-9+-.]+;base64,/
|
|
577
|
+
/^data:(image|application|video|text|model|font)\/[A-Za-z0-9+-.]+;base64,/
|
|
548
578
|
);
|
|
549
579
|
const type = typeMatch?.[1];
|
|
550
|
-
console.log(type ?? "");
|
|
551
580
|
if (!typeMatch) {
|
|
552
581
|
throw new Error(`${b64Data} is not a valid data Url`);
|
|
553
582
|
}
|
|
@@ -567,6 +596,39 @@ var Fs = class {
|
|
|
567
596
|
return blob;
|
|
568
597
|
}
|
|
569
598
|
}
|
|
599
|
+
cleanDataUrl(props) {
|
|
600
|
+
return props.replace(
|
|
601
|
+
/^data:(image|application|video|text|font|model|audio)\/[A-Za-z0-9+-.]+;base64,/,
|
|
602
|
+
""
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
*
|
|
607
|
+
* @param inputUrl remote url to fetch data from
|
|
608
|
+
* @param outputPath desired output path relative to the cwd
|
|
609
|
+
* @param useDetectedExtension optional, defaults to true
|
|
610
|
+
*
|
|
611
|
+
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
612
|
+
*
|
|
613
|
+
* 🚫 'public/assets/image-1'
|
|
614
|
+
*
|
|
615
|
+
* ✅ 'public/assets/image-1.png'
|
|
616
|
+
*/
|
|
617
|
+
async fetchRemoteWriteLocal(inputUrl, outputPath, useDetectedExtension = true) {
|
|
618
|
+
try {
|
|
619
|
+
const result = await this.assetToBufferView(inputUrl);
|
|
620
|
+
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
621
|
+
const formattedPath = useDetectedExtension ? `${outputPath}.${result.extension}` : outputPath;
|
|
622
|
+
if (/\./g.test(formattedPath) === false) {
|
|
623
|
+
throw new Error(
|
|
624
|
+
"either add false as the third argument in `fetchRemoteWriteLocal` [input, output, use-detected-file-extension (defaults to true)]"
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
628
|
+
} catch (err) {
|
|
629
|
+
return console.error(err);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
570
632
|
};
|
|
571
633
|
// Annotate the CommonJS export names for ESM import in node:
|
|
572
634
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -2,3 +2,4 @@ export { default as Fs } from './fs/index.cjs';
|
|
|
2
2
|
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, Signals, StdioOptions, TypedArray, Unenumerate, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR } from './types/index.cjs';
|
|
3
3
|
import 'dotenv-expand';
|
|
4
4
|
import 'stream';
|
|
5
|
+
import 'buffer';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { default as Fs } from './fs/index.js';
|
|
|
2
2
|
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, Signals, StdioOptions, TypedArray, Unenumerate, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR } from './types/index.js';
|
|
3
3
|
import 'dotenv-expand';
|
|
4
4
|
import 'stream';
|
|
5
|
+
import 'buffer';
|
package/dist/index.js
CHANGED
package/dist/types/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as stream from 'stream';
|
|
2
|
+
import { WithImplicitCoercion } from 'buffer';
|
|
2
3
|
|
|
3
4
|
type BufferEncodingUnion = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex" | "utf-16le";
|
|
4
5
|
interface Dict<T> {
|
|
@@ -83,7 +84,7 @@ interface MkDirOptions {
|
|
|
83
84
|
}
|
|
84
85
|
type BashEnv = "development" | "production" | "test" | undefined;
|
|
85
86
|
type CoercionUnion = string | Uint8Array | readonly number[];
|
|
86
|
-
type WriteStreamDataShape = WithImplicitCoercion<CoercionUnion
|
|
87
|
+
type WriteStreamDataShape = WithImplicitCoercion<CoercionUnion> | CoercionUnion;
|
|
87
88
|
type WriteStreamProps<T extends string = string> = {
|
|
88
89
|
data: WithImplicitCoercion<CoercionUnion>;
|
|
89
90
|
cwd: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as stream from 'stream';
|
|
2
|
+
import { WithImplicitCoercion } from 'buffer';
|
|
2
3
|
|
|
3
4
|
type BufferEncodingUnion = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex" | "utf-16le";
|
|
4
5
|
interface Dict<T> {
|
|
@@ -83,7 +84,7 @@ interface MkDirOptions {
|
|
|
83
84
|
}
|
|
84
85
|
type BashEnv = "development" | "production" | "test" | undefined;
|
|
85
86
|
type CoercionUnion = string | Uint8Array | readonly number[];
|
|
86
|
-
type WriteStreamDataShape = WithImplicitCoercion<CoercionUnion
|
|
87
|
+
type WriteStreamDataShape = WithImplicitCoercion<CoercionUnion> | CoercionUnion;
|
|
87
88
|
type WriteStreamProps<T extends string = string> = {
|
|
88
89
|
data: WithImplicitCoercion<CoercionUnion>;
|
|
89
90
|
cwd: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0paminedriven/fs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "convenient fs helpers",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"dotenv": "^16.4.7"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@microsoft/api-extractor": "^7.
|
|
42
|
-
"@swc/core": "^1.
|
|
43
|
-
"@swc/wasm": "^1.
|
|
44
|
-
"@types/node": "^22.
|
|
41
|
+
"@microsoft/api-extractor": "^7.52.2",
|
|
42
|
+
"@swc/core": "^1.11.13",
|
|
43
|
+
"@swc/wasm": "^1.11.13",
|
|
44
|
+
"@types/node": "^22.13.13",
|
|
45
45
|
"chokidar": "^4.0.3",
|
|
46
46
|
"dotenv": "^16.4.7",
|
|
47
47
|
"dotenv-cli": "^8.0.0",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"eslint": "latest",
|
|
50
50
|
"jiti": "^2.4.2",
|
|
51
51
|
"prettier": "latest",
|
|
52
|
-
"terser": "^5.
|
|
52
|
+
"terser": "^5.39.0",
|
|
53
53
|
"tslib": "latest",
|
|
54
54
|
"tsup": "latest",
|
|
55
55
|
"tsx": "latest",
|
|
56
56
|
"typescript": "latest",
|
|
57
57
|
"typescript-eslint": "latest",
|
|
58
58
|
"@portfolio/eslint-config": "1.0.0",
|
|
59
|
-
"@portfolio/
|
|
60
|
-
"@portfolio/
|
|
59
|
+
"@portfolio/tsconfig": "0.1.0",
|
|
60
|
+
"@portfolio/prettier-config": "0.1.0"
|
|
61
61
|
},
|
|
62
62
|
"prettier": "@portfolio/prettier-config",
|
|
63
63
|
"scripts": {
|