@d0paminedriven/fs 0.2.0 → 2.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-MZZJMVSV.js → chunk-J3NUWUIN.js} +213 -53
- package/dist/fs/index.cjs +211 -51
- package/dist/fs/index.d.cts +208 -13
- package/dist/fs/index.d.ts +208 -13
- package/dist/fs/index.js +1 -1
- package/dist/index.cjs +211 -51
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -133,6 +133,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
|
|
|
133
133
|
var import_path = require("path");
|
|
134
134
|
var dotenv = __toESM(require("dotenv"), 1);
|
|
135
135
|
var import_dotenv_expand = __toESM(require_main(), 1);
|
|
136
|
+
var import_sharp = __toESM(require("sharp"), 1);
|
|
136
137
|
dotenv.config();
|
|
137
138
|
var Fs = class {
|
|
138
139
|
constructor(cwd) {
|
|
@@ -152,20 +153,20 @@ var Fs = class {
|
|
|
152
153
|
);
|
|
153
154
|
}
|
|
154
155
|
excludeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
|
|
155
|
-
const
|
|
156
|
+
const resolve2 = Object.fromEntries(
|
|
156
157
|
Object.entries(obj).map(([key, val]) => {
|
|
157
158
|
if (props.includes(key)) {
|
|
158
159
|
return ["omit", "omit"];
|
|
159
160
|
} else return [key, val];
|
|
160
161
|
}).filter(([t, _v]) => /omit/.test(t) === false)
|
|
161
162
|
);
|
|
162
|
-
return typeof sort !== "undefined" ? this.sort(
|
|
163
|
+
return typeof sort !== "undefined" ? this.sort(resolve2, sort) : resolve2;
|
|
163
164
|
}, "excludeTargeted");
|
|
164
165
|
includeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
|
|
165
|
-
const
|
|
166
|
+
const resolve2 = Object.fromEntries(
|
|
166
167
|
props.map((val) => this.extractTuple(obj, val))
|
|
167
168
|
);
|
|
168
|
-
return typeof sort !== "undefined" ? this.sort(
|
|
169
|
+
return typeof sort !== "undefined" ? this.sort(resolve2, sort) : resolve2;
|
|
169
170
|
}, "includeTargeted");
|
|
170
171
|
get myEnv() {
|
|
171
172
|
return dotenv.config({ processEnv: {} });
|
|
@@ -189,6 +190,7 @@ var Fs = class {
|
|
|
189
190
|
return { ...this.omitFields(targ, keys) };
|
|
190
191
|
}
|
|
191
192
|
exists(target) {
|
|
193
|
+
if (!/\//gm.test(target)) return import_fs.default.existsSync((0, import_path.resolve)((0, import_path.join)(this.cwd, target)));
|
|
192
194
|
return import_fs.default.existsSync((0, import_path.relative)(this.cwd ?? process.cwd(), target));
|
|
193
195
|
}
|
|
194
196
|
arrToArrOfArrs = /* @__PURE__ */ __name(({
|
|
@@ -196,7 +198,7 @@ var Fs = class {
|
|
|
196
198
|
arrOfArrsAggregator = Array.of(),
|
|
197
199
|
interval
|
|
198
200
|
}) => new Promise(
|
|
199
|
-
(
|
|
201
|
+
(resolve2, _reject) => resolve2(
|
|
200
202
|
((interval2) => {
|
|
201
203
|
for (let i = 0; i <= arrToFragment.length; i++) {
|
|
202
204
|
if ((i % interval2 === 0 || i === 0) && i <= arrToFragment.length) {
|
|
@@ -208,7 +210,7 @@ var Fs = class {
|
|
|
208
210
|
)
|
|
209
211
|
).then((_) => arrOfArrsAggregator), "arrToArrOfArrs");
|
|
210
212
|
wait(ms) {
|
|
211
|
-
return new Promise((
|
|
213
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
212
214
|
}
|
|
213
215
|
countsSorter = /* @__PURE__ */ __name(({
|
|
214
216
|
counter,
|
|
@@ -226,8 +228,15 @@ var Fs = class {
|
|
|
226
228
|
(v) => Buffer.isBuffer(v) ? Buffer.from(v).toString("utf-8") : v
|
|
227
229
|
);
|
|
228
230
|
}
|
|
231
|
+
isRootPathTargeted(path) {
|
|
232
|
+
if (/^(?:\.\/|\.|\/|root|\.\.\/|~\/\.?|cwd|\.\/\.)$/g.test(path)) {
|
|
233
|
+
return true;
|
|
234
|
+
} else return false;
|
|
235
|
+
}
|
|
229
236
|
readDir(path, options) {
|
|
230
|
-
|
|
237
|
+
if (this.isRootPathTargeted(path)) {
|
|
238
|
+
return this.handleBuffStrArrUnion(import_fs.default.readdirSync((0, import_path.resolve)((0, import_path.join)(this.cwd, "./")), options));
|
|
239
|
+
} else return this.handleBuffStrArrUnion(
|
|
231
240
|
import_fs.default.readdirSync(
|
|
232
241
|
(0, import_path.relative)(this.cwd ??= process.cwd(), path),
|
|
233
242
|
options
|
|
@@ -237,9 +246,7 @@ var Fs = class {
|
|
|
237
246
|
executeCommand = /* @__PURE__ */ __name(({
|
|
238
247
|
command,
|
|
239
248
|
...options
|
|
240
|
-
}) => Buffer.from(
|
|
241
|
-
Buffer.from((0, import_child_process.execSync)(command, { ...options }).toJSON().data)
|
|
242
|
-
).toString("utf-8"), "executeCommand");
|
|
249
|
+
}) => Buffer.from((0, import_child_process.execSync)(command, { ...options }).toJSON().data).toString("utf-8"), "executeCommand");
|
|
243
250
|
fileGenTimestamp(d) {
|
|
244
251
|
const date = d.toISOString();
|
|
245
252
|
return `/* file-autogenerated by @d0paminedriven/fs on ${date.split(/([T])/gm)?.[0]} at ${date.split(/([T])/gm)[2]?.split(/([Z])/gm)?.[0]} UTC */`;
|
|
@@ -251,6 +258,7 @@ var Fs = class {
|
|
|
251
258
|
return this.fileGenTimestamp(d).replace("/*", "<!--").replace("*/", "-->");
|
|
252
259
|
}
|
|
253
260
|
existsSync(path) {
|
|
261
|
+
if (!/\//gm.test(path)) return import_fs.default.existsSync((0, import_path.resolve)((0, import_path.join)(this.cwd, path)));
|
|
254
262
|
return import_fs.default.existsSync((0, import_path.relative)(this.cwd ?? process.cwd(), path));
|
|
255
263
|
}
|
|
256
264
|
pathHandler(path) {
|
|
@@ -313,18 +321,11 @@ var Fs = class {
|
|
|
313
321
|
}
|
|
314
322
|
}, "writeFileAsync");
|
|
315
323
|
fileToBuffer = /* @__PURE__ */ __name((path) => Buffer.from(
|
|
316
|
-
|
|
317
|
-
import_fs.default.readFileSync((0, import_path.relative)(this.cwd ?? process.cwd(), path)).toJSON().data
|
|
318
|
-
)
|
|
324
|
+
import_fs.default.readFileSync((0, import_path.relative)(this.cwd ?? process.cwd(), path)).toJSON().data
|
|
319
325
|
), "fileToBuffer");
|
|
320
326
|
dirContainsDir(readDir, targetDir, options) {
|
|
321
327
|
return this.readDir(readDir, options).filter((t) => t.split(".").length === 1).includes(targetDir);
|
|
322
328
|
}
|
|
323
|
-
parseJsonBuffer(p) {
|
|
324
|
-
return JSON.parse(
|
|
325
|
-
Buffer.from(Buffer.from(p).toJSON().data).toString("utf-8")
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
329
|
/* begin url */
|
|
329
330
|
isServerSide() {
|
|
330
331
|
return typeof window === "undefined";
|
|
@@ -361,20 +362,43 @@ var Fs = class {
|
|
|
361
362
|
};
|
|
362
363
|
}
|
|
363
364
|
/* end url */
|
|
365
|
+
get cjsVal() {
|
|
366
|
+
return ["application/node", "text/javascript"].reduce(
|
|
367
|
+
(union) => union
|
|
368
|
+
);
|
|
369
|
+
}
|
|
364
370
|
get gzVal() {
|
|
365
371
|
return ["application/x-gzip", "application/gzip"].reduce(
|
|
366
|
-
(
|
|
372
|
+
(union) => union
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
get jsVal() {
|
|
376
|
+
return ["application/node", "text/javascript"].reduce(
|
|
377
|
+
(union) => union
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
get objVal() {
|
|
381
|
+
return ["application/octet-stream", "text/plain", "model/obj"].reduce((union) => union);
|
|
382
|
+
}
|
|
383
|
+
get tsVal() {
|
|
384
|
+
return ["text/typescript", "video/mp2t", "video/vnd.dlna.mpeg-tts"].reduce((union) => union);
|
|
385
|
+
}
|
|
386
|
+
get ttfVal() {
|
|
387
|
+
return ["application/font-sfnt", "font/ttf"].reduce(
|
|
388
|
+
(union) => union
|
|
367
389
|
);
|
|
368
390
|
}
|
|
369
391
|
get zipVal() {
|
|
370
|
-
return ["application/zip", "application/x-zip-compressed"].reduce((
|
|
392
|
+
return ["application/zip", "application/x-zip-compressed"].reduce((union) => union);
|
|
371
393
|
}
|
|
372
394
|
get mimeTypeObj() {
|
|
373
395
|
return {
|
|
374
396
|
aac: "audio/aac",
|
|
375
397
|
abw: "application/x-abiword",
|
|
398
|
+
aces: "image/aces",
|
|
376
399
|
apng: "image/apng",
|
|
377
400
|
arc: "application/x-freearc",
|
|
401
|
+
avci: "image/avci",
|
|
378
402
|
avif: "image/avif",
|
|
379
403
|
avi: "video/x-msvideo",
|
|
380
404
|
azw: "application/vnd.amazon.ebook",
|
|
@@ -383,27 +407,36 @@ var Fs = class {
|
|
|
383
407
|
bz: "application/x-bzip",
|
|
384
408
|
bz2: "application/x-bzip2",
|
|
385
409
|
cda: "application/x-cdf",
|
|
386
|
-
cjs:
|
|
410
|
+
cjs: this.cjsVal,
|
|
387
411
|
csh: "application/x-csh",
|
|
388
412
|
css: "text/css",
|
|
389
413
|
csv: "text/csv",
|
|
390
414
|
doc: "application/msword",
|
|
391
415
|
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
416
|
+
dpx: "image/dpx",
|
|
417
|
+
emf: "image/emf",
|
|
392
418
|
eot: "application/vnd.ms-fontobject",
|
|
393
419
|
epub: "application/epub+zip",
|
|
394
420
|
gif: "image/gif",
|
|
421
|
+
glb: "model/gltf-binary",
|
|
422
|
+
gltf: "model/gltf+json",
|
|
395
423
|
gz: this.gzVal,
|
|
424
|
+
hjif: "haptics/hjif",
|
|
425
|
+
hmpg: "haptics/hmpg",
|
|
396
426
|
htm: "text/html",
|
|
397
427
|
html: "text/html",
|
|
398
428
|
ico: "image/vnd.microsoft.icon",
|
|
399
429
|
ics: "text/calendar",
|
|
430
|
+
ivs: "haptics/ivs",
|
|
400
431
|
jar: "application/java-archive",
|
|
401
432
|
jpeg: "image/jpeg",
|
|
402
433
|
jpg: "image/jpeg",
|
|
403
|
-
js:
|
|
434
|
+
js: this.jsVal,
|
|
404
435
|
json: "application/json",
|
|
405
436
|
jsonld: "application/ld+json",
|
|
406
437
|
m3u8: "application/vnd.apple.mpegurl",
|
|
438
|
+
m4a: "audio/mp4",
|
|
439
|
+
m4v: "video/mp4",
|
|
407
440
|
md: "text/markdown",
|
|
408
441
|
mdx: "application/x-mdx",
|
|
409
442
|
mid: "audio/midi",
|
|
@@ -414,10 +447,12 @@ var Fs = class {
|
|
|
414
447
|
mpeg: "video/mpeg",
|
|
415
448
|
mpkg: "application/vnd.apple.installer+xml",
|
|
416
449
|
ndjson: "application/x-ndjson",
|
|
450
|
+
obj: this.objVal,
|
|
417
451
|
odp: "application/vnd.oasis.opendocument.presentation",
|
|
418
452
|
ods: "application/vnd.oasis.opendocument.spreadsheet",
|
|
419
453
|
odt: "application/vnd.oasis.opendocument.text",
|
|
420
454
|
oga: "audio/ogg",
|
|
455
|
+
ogg: "audio/ogg",
|
|
421
456
|
ogv: "video/ogg",
|
|
422
457
|
ogx: "application/ogg",
|
|
423
458
|
opus: "audio/ogg",
|
|
@@ -428,17 +463,24 @@ var Fs = class {
|
|
|
428
463
|
pkpass: "application/vnd.apple.pkpass",
|
|
429
464
|
ppt: "application/vnd.ms-powerpoint",
|
|
430
465
|
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
466
|
+
py: "text/x-python",
|
|
467
|
+
pyc: "application/x-python-code",
|
|
431
468
|
rar: "application/vnd.rar",
|
|
432
469
|
rtf: "application/rtf",
|
|
433
470
|
sh: "application/x-sh",
|
|
471
|
+
sql: "application/sql",
|
|
434
472
|
svg: "image/svg+xml",
|
|
435
473
|
tar: "application/x-tar",
|
|
436
474
|
tif: "image/tiff",
|
|
437
475
|
tiff: "image/tiff",
|
|
438
|
-
|
|
439
|
-
|
|
476
|
+
toml: "application/toml",
|
|
477
|
+
ts: this.tsVal,
|
|
478
|
+
ttf: this.ttfVal,
|
|
440
479
|
txt: "text/plain",
|
|
480
|
+
usdz: "model/vnd.usdz+zip",
|
|
441
481
|
vsd: "application/vnd.visio",
|
|
482
|
+
vtt: "text/vtt",
|
|
483
|
+
wasm: "application/wasm",
|
|
442
484
|
wav: "audio/wav",
|
|
443
485
|
weba: "video/webm",
|
|
444
486
|
webp: "image/webp",
|
|
@@ -449,6 +491,8 @@ var Fs = class {
|
|
|
449
491
|
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
450
492
|
xml: "application/xml",
|
|
451
493
|
xul: "application/vnd.mozilla.xul+xml",
|
|
494
|
+
yaml: "application/yaml",
|
|
495
|
+
yml: "application/yaml",
|
|
452
496
|
zip: this.zipVal,
|
|
453
497
|
"3gp": "video/3gpp",
|
|
454
498
|
"3g2": "video/3gpp2",
|
|
@@ -456,18 +500,20 @@ var Fs = class {
|
|
|
456
500
|
};
|
|
457
501
|
}
|
|
458
502
|
assetType(url) {
|
|
459
|
-
|
|
503
|
+
const u = this.parseUrl(url);
|
|
504
|
+
return u.pathname?.split(/([.])/gim)?.reverse()?.[0];
|
|
460
505
|
}
|
|
461
506
|
getMime(input) {
|
|
462
507
|
return this.mimeTypeObj[input];
|
|
463
508
|
}
|
|
509
|
+
hmm = /* @__PURE__ */ __name((input) => {
|
|
510
|
+
return this.mimeTypeObj[input];
|
|
511
|
+
}, "hmm");
|
|
464
512
|
async assetToBuffer(path) {
|
|
465
513
|
const [fetcher] = await Promise.all([
|
|
466
514
|
fetch(path).then((t) => t.arrayBuffer())
|
|
467
515
|
]);
|
|
468
|
-
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(
|
|
469
|
-
Buffer.from(fetcher).toJSON().data
|
|
470
|
-
).toString("base64")}`;
|
|
516
|
+
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(fetcher).toString("base64")}`;
|
|
471
517
|
const extension = this.assetType(path);
|
|
472
518
|
return {
|
|
473
519
|
b64encodedData,
|
|
@@ -475,27 +521,40 @@ var Fs = class {
|
|
|
475
521
|
};
|
|
476
522
|
}
|
|
477
523
|
async assetToBufferView(path) {
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
524
|
+
const p = this.parseUrl(path);
|
|
525
|
+
const doesUrlPathContainFileExtension = /\./g.test(
|
|
526
|
+
p.pathname.split(/\//g).reverse()[0] ?? ""
|
|
527
|
+
);
|
|
528
|
+
if (doesUrlPathContainFileExtension === false)
|
|
529
|
+
console.warn(`no file extension detected in input url ${path}, attempting fetch`);
|
|
530
|
+
const response = await fetch(path);
|
|
531
|
+
if (!response.ok) {
|
|
532
|
+
throw new Error(`Failed to fetch asset: ${response.statusText}`);
|
|
533
|
+
}
|
|
534
|
+
const reader = response.body?.getReader();
|
|
535
|
+
if (reader) {
|
|
536
|
+
const chunks = [];
|
|
537
|
+
while (true) {
|
|
538
|
+
const { done, value } = await reader.read();
|
|
539
|
+
if (done) break;
|
|
540
|
+
if (value) chunks.push(value);
|
|
486
541
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
b64encodedData,
|
|
497
|
-
|
|
498
|
-
|
|
542
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
543
|
+
const completeBuffer = new Uint8Array(totalLength);
|
|
544
|
+
let offset = 0;
|
|
545
|
+
for (const chunk of chunks) {
|
|
546
|
+
completeBuffer.set(chunk, offset);
|
|
547
|
+
offset += chunk.length;
|
|
548
|
+
}
|
|
549
|
+
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(completeBuffer).toString("base64")}`;
|
|
550
|
+
const extension = this.assetType(path);
|
|
551
|
+
return { b64encodedData, extension };
|
|
552
|
+
} else {
|
|
553
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
554
|
+
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(arrayBuffer).toString("base64")}`;
|
|
555
|
+
const extension = this.assetType(path);
|
|
556
|
+
return { b64encodedData, extension };
|
|
557
|
+
}
|
|
499
558
|
}
|
|
500
559
|
formatHelper(f) {
|
|
501
560
|
if (/([A-Za-z]+-[A-Za-z]+)/g.test(f) === true) {
|
|
@@ -504,7 +563,7 @@ var Fs = class {
|
|
|
504
563
|
} else return f.substring(0, 1).toUpperCase().concat(f.substring(1));
|
|
505
564
|
}
|
|
506
565
|
range(from, to) {
|
|
507
|
-
const values =
|
|
566
|
+
const values = Array.of();
|
|
508
567
|
for (let i = from; i < to; i++) {
|
|
509
568
|
values.push(i);
|
|
510
569
|
}
|
|
@@ -544,10 +603,9 @@ var Fs = class {
|
|
|
544
603
|
{
|
|
545
604
|
const sliceSize = 512;
|
|
546
605
|
const typeMatch = b64Data.match(
|
|
547
|
-
/^data:(image|application|video|text|font)\/[A-Za-z0-9+-.]
|
|
606
|
+
/^data:(?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i
|
|
548
607
|
);
|
|
549
608
|
const type = typeMatch?.[1];
|
|
550
|
-
console.log(type ?? "");
|
|
551
609
|
if (!typeMatch) {
|
|
552
610
|
throw new Error(`${b64Data} is not a valid data Url`);
|
|
553
611
|
}
|
|
@@ -567,6 +625,108 @@ var Fs = class {
|
|
|
567
625
|
return blob;
|
|
568
626
|
}
|
|
569
627
|
}
|
|
628
|
+
cleanDataUrl(props) {
|
|
629
|
+
return props.replace(
|
|
630
|
+
/^data:(?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i,
|
|
631
|
+
""
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* public cleanDataUrl<const C extends string>(props: C) {
|
|
636
|
+
return props.replace(
|
|
637
|
+
/^data:(?:image|application|video|text|font|model|audio|haptics|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i,
|
|
638
|
+
""
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
*/
|
|
643
|
+
/**
|
|
644
|
+
*
|
|
645
|
+
* @param inputUrl remote url to fetch data from
|
|
646
|
+
* @param outputPath desired output path relative to the cwd
|
|
647
|
+
* @param useDetectedExtension optional, defaults to true
|
|
648
|
+
*
|
|
649
|
+
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
650
|
+
*
|
|
651
|
+
* 🚫 'public/assets/image-1'
|
|
652
|
+
*
|
|
653
|
+
* ✅ 'public/assets/image-1.png'
|
|
654
|
+
*/
|
|
655
|
+
async fetchRemoteWriteLocal(inputUrl, outputPath, useDetectedExtension = true) {
|
|
656
|
+
try {
|
|
657
|
+
const result = await this.assetToBufferView(inputUrl);
|
|
658
|
+
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
659
|
+
const formattedPath = useDetectedExtension ? `${outputPath}.${result.extension}` : outputPath;
|
|
660
|
+
if (/\./g.test(formattedPath) === false) {
|
|
661
|
+
throw new Error(
|
|
662
|
+
"either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension) or provide an output path without a file extension"
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
666
|
+
} catch (err) {
|
|
667
|
+
return console.error(err);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
// USE fluent-ffmpeg for video/animated image transforms (apng, etc)
|
|
671
|
+
// https://www.npmjs.com/package/fluent-ffmpeg
|
|
672
|
+
// https://www.npmjs.com/package/@types/fluent-ffmpeg
|
|
673
|
+
async imageTransform({
|
|
674
|
+
format,
|
|
675
|
+
target,
|
|
676
|
+
quality = 80,
|
|
677
|
+
tint,
|
|
678
|
+
resize
|
|
679
|
+
}) {
|
|
680
|
+
if (tint && !resize) {
|
|
681
|
+
return await (0, import_sharp.default)(target).toFormat(format, { quality }).tint(tint).toBuffer();
|
|
682
|
+
} else if (!tint && resize) {
|
|
683
|
+
return await (0, import_sharp.default)(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
|
|
684
|
+
} else if (tint && resize) {
|
|
685
|
+
return await (0, import_sharp.default)(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
|
|
686
|
+
} else return await (0, import_sharp.default)(target).toFormat(format, { quality }).toBuffer();
|
|
687
|
+
}
|
|
688
|
+
// public async convertImage<
|
|
689
|
+
// const L extends "local" | "remote",
|
|
690
|
+
// const F extends "webp" | "avif" | "jpg" | "png",
|
|
691
|
+
// const I extends string,
|
|
692
|
+
// const O extends string
|
|
693
|
+
// >(isLocal: L, inputUrl: I, outputPath: O, useDetectedExtension = true) {
|
|
694
|
+
// if (isLocal === "remote") {
|
|
695
|
+
// try {
|
|
696
|
+
// const result = await this.assetToBufferView(inputUrl);
|
|
697
|
+
// const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
698
|
+
// const imageBuffer = Buffer.from(cleanData, "base64");
|
|
699
|
+
// const s = this.imageTransform({format: "webp", target: imageBuffer, quality: 100, resize: {options: {width: 1.2, height: 1.2}}} )
|
|
700
|
+
// const formattedPath = useDetectedExtension
|
|
701
|
+
// ? `${outputPath}.${result.extension}`
|
|
702
|
+
// : outputPath;
|
|
703
|
+
// if (/\./g.test(formattedPath) === false) {
|
|
704
|
+
// throw new Error(
|
|
705
|
+
// "either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension)"
|
|
706
|
+
// );
|
|
707
|
+
// }
|
|
708
|
+
// this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
709
|
+
// } catch (err) {
|
|
710
|
+
// return console.error(err);
|
|
711
|
+
// }
|
|
712
|
+
// } else {
|
|
713
|
+
// try {
|
|
714
|
+
// const result = await this.assetToBufferView(inputUrl);
|
|
715
|
+
// const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
716
|
+
// const formattedPath = useDetectedExtension
|
|
717
|
+
// ? `${outputPath}.${result.extension}`
|
|
718
|
+
// : outputPath;
|
|
719
|
+
// if (/\./g.test(formattedPath) === false) {
|
|
720
|
+
// throw new Error(
|
|
721
|
+
// "either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension)"
|
|
722
|
+
// );
|
|
723
|
+
// }
|
|
724
|
+
// this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
725
|
+
// } catch (err) {
|
|
726
|
+
// return console.error(err);
|
|
727
|
+
// }
|
|
728
|
+
// }
|
|
729
|
+
// }
|
|
570
730
|
};
|
|
571
731
|
// Annotate the CommonJS export names for ESM import in node:
|
|
572
732
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
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
|
+
import 'sharp';
|
|
4
5
|
import 'stream';
|
|
5
6
|
import 'buffer';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
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
|
+
import 'sharp';
|
|
4
5
|
import 'stream';
|
|
5
6
|
import 'buffer';
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0paminedriven/fs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "convenient fs helpers",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"./types": "./dist/types/index.js"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"dotenv": "^16.
|
|
38
|
+
"dotenv": "^16.5.0",
|
|
39
|
+
"sharp": "^0.34.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@microsoft/api-extractor": "^7.52.
|
|
42
|
-
"@swc/core": "^1.11.
|
|
43
|
-
"@swc/wasm": "^1.11.
|
|
44
|
-
"@types/node": "^22.
|
|
42
|
+
"@microsoft/api-extractor": "^7.52.3",
|
|
43
|
+
"@swc/core": "^1.11.21",
|
|
44
|
+
"@swc/wasm": "^1.11.21",
|
|
45
|
+
"@types/node": "^22.14.1",
|
|
45
46
|
"chokidar": "^4.0.3",
|
|
46
|
-
"dotenv": "^16.4.7",
|
|
47
47
|
"dotenv-cli": "^8.0.0",
|
|
48
48
|
"dotenv-expand": "^12.0.1",
|
|
49
49
|
"eslint": "latest",
|