@d0paminedriven/fs 1.0.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-MFKSUNKN.js → chunk-J3NUWUIN.js} +123 -25
- package/dist/fs/index.cjs +121 -23
- package/dist/fs/index.d.cts +74 -10
- package/dist/fs/index.d.ts +74 -10
- package/dist/fs/index.js +1 -1
- package/dist/index.cjs +121 -23
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +9 -9
package/dist/fs/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import expand from 'dotenv-expand';
|
|
2
|
+
import sharp from 'sharp';
|
|
2
3
|
import { RemoveFields, Unenumerate, ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, ParsedUrlInfo } from '../types/index.js';
|
|
3
4
|
import 'stream';
|
|
4
5
|
import 'buffer';
|
|
@@ -33,6 +34,7 @@ declare class Fs {
|
|
|
33
34
|
[k: string]: number;
|
|
34
35
|
};
|
|
35
36
|
handleBuffStrArrUnion<const T extends (string | Buffer)[] | readonly (string | Buffer)[]>(arr: T): string[];
|
|
37
|
+
isRootPathTargeted<const T extends string>(path: T): boolean;
|
|
36
38
|
readDir<const T extends string>(path: T, options?: ReadDirOptions): string[];
|
|
37
39
|
executeCommand: <const T extends string>({ command, ...options }: ExecuteCommandProps<T>) => string;
|
|
38
40
|
fileGenTimestamp<T extends InstanceType<typeof Date> = InstanceType<typeof Date>>(d: T): `/* file-autogenerated by @d0paminedriven/fs on undefined at ${string} UTC */` | `/* file-autogenerated by @d0paminedriven/fs on ${string} at undefined UTC */` | `/* file-autogenerated by @d0paminedriven/fs on ${string} at ${string} UTC */`;
|
|
@@ -47,14 +49,15 @@ declare class Fs {
|
|
|
47
49
|
writeFileAsync: <const T extends string>(path: T, data: WriteFileAsyncDataUnion, options?: WriteFileAsyncOptions) => Promise<string | void>;
|
|
48
50
|
fileToBuffer: <const T extends string>(path: T) => Buffer<ArrayBuffer>;
|
|
49
51
|
dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
|
|
50
|
-
parseJsonBuffer(p: Buffer): unknown;
|
|
51
52
|
isServerSide(): boolean;
|
|
52
53
|
isBase64(str: string): boolean;
|
|
53
54
|
previewRegex: RegExp;
|
|
54
55
|
isPreviewPath(uri: string): boolean;
|
|
55
56
|
get URL_REGEX(): RegExp;
|
|
56
57
|
parseUrl(url: string): ParsedUrlInfo;
|
|
58
|
+
get cjsVal(): "application/node" | "text/javascript";
|
|
57
59
|
get gzVal(): "application/x-gzip" | "application/gzip";
|
|
60
|
+
get jsVal(): "application/node" | "text/javascript";
|
|
58
61
|
get objVal(): "application/octet-stream" | "text/plain" | "model/obj";
|
|
59
62
|
get tsVal(): "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts";
|
|
60
63
|
get ttfVal(): "application/font-sfnt" | "font/ttf";
|
|
@@ -62,8 +65,10 @@ declare class Fs {
|
|
|
62
65
|
get mimeTypeObj(): {
|
|
63
66
|
readonly aac: "audio/aac";
|
|
64
67
|
readonly abw: "application/x-abiword";
|
|
68
|
+
readonly aces: "image/aces";
|
|
65
69
|
readonly apng: "image/apng";
|
|
66
70
|
readonly arc: "application/x-freearc";
|
|
71
|
+
readonly avci: "image/avci";
|
|
67
72
|
readonly avif: "image/avif";
|
|
68
73
|
readonly avi: "video/x-msvideo";
|
|
69
74
|
readonly azw: "application/vnd.amazon.ebook";
|
|
@@ -72,26 +77,31 @@ declare class Fs {
|
|
|
72
77
|
readonly bz: "application/x-bzip";
|
|
73
78
|
readonly bz2: "application/x-bzip2";
|
|
74
79
|
readonly cda: "application/x-cdf";
|
|
75
|
-
readonly cjs: "application/javascript";
|
|
80
|
+
readonly cjs: "application/node" | "text/javascript";
|
|
76
81
|
readonly csh: "application/x-csh";
|
|
77
82
|
readonly css: "text/css";
|
|
78
83
|
readonly csv: "text/csv";
|
|
79
84
|
readonly doc: "application/msword";
|
|
80
85
|
readonly docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
86
|
+
readonly dpx: "image/dpx";
|
|
87
|
+
readonly emf: "image/emf";
|
|
81
88
|
readonly eot: "application/vnd.ms-fontobject";
|
|
82
89
|
readonly epub: "application/epub+zip";
|
|
83
90
|
readonly gif: "image/gif";
|
|
84
91
|
readonly glb: "model/gltf-binary";
|
|
85
92
|
readonly gltf: "model/gltf+json";
|
|
86
93
|
readonly gz: "application/x-gzip" | "application/gzip";
|
|
94
|
+
readonly hjif: "haptics/hjif";
|
|
95
|
+
readonly hmpg: "haptics/hmpg";
|
|
87
96
|
readonly htm: "text/html";
|
|
88
97
|
readonly html: "text/html";
|
|
89
98
|
readonly ico: "image/vnd.microsoft.icon";
|
|
90
99
|
readonly ics: "text/calendar";
|
|
100
|
+
readonly ivs: "haptics/ivs";
|
|
91
101
|
readonly jar: "application/java-archive";
|
|
92
102
|
readonly jpeg: "image/jpeg";
|
|
93
103
|
readonly jpg: "image/jpeg";
|
|
94
|
-
readonly js: "text/javascript";
|
|
104
|
+
readonly js: "application/node" | "text/javascript";
|
|
95
105
|
readonly json: "application/json";
|
|
96
106
|
readonly jsonld: "application/ld+json";
|
|
97
107
|
readonly m3u8: "application/vnd.apple.mpegurl";
|
|
@@ -128,13 +138,16 @@ declare class Fs {
|
|
|
128
138
|
readonly rar: "application/vnd.rar";
|
|
129
139
|
readonly rtf: "application/rtf";
|
|
130
140
|
readonly sh: "application/x-sh";
|
|
141
|
+
readonly sql: "application/sql";
|
|
131
142
|
readonly svg: "image/svg+xml";
|
|
132
143
|
readonly tar: "application/x-tar";
|
|
133
144
|
readonly tif: "image/tiff";
|
|
134
145
|
readonly tiff: "image/tiff";
|
|
146
|
+
readonly toml: "application/toml";
|
|
135
147
|
readonly ts: "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts";
|
|
136
148
|
readonly ttf: "application/font-sfnt" | "font/ttf";
|
|
137
149
|
readonly txt: "text/plain";
|
|
150
|
+
readonly usdz: "model/vnd.usdz+zip";
|
|
138
151
|
readonly vsd: "application/vnd.visio";
|
|
139
152
|
readonly vtt: "text/vtt";
|
|
140
153
|
readonly wasm: "application/wasm";
|
|
@@ -148,6 +161,8 @@ declare class Fs {
|
|
|
148
161
|
readonly xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
149
162
|
readonly xml: "application/xml";
|
|
150
163
|
readonly xul: "application/vnd.mozilla.xul+xml";
|
|
164
|
+
readonly yaml: "application/yaml";
|
|
165
|
+
readonly yml: "application/yaml";
|
|
151
166
|
readonly zip: "application/zip" | "application/x-zip-compressed";
|
|
152
167
|
readonly "3gp": "video/3gpp";
|
|
153
168
|
readonly "3g2": "video/3gpp2";
|
|
@@ -157,8 +172,10 @@ declare class Fs {
|
|
|
157
172
|
getMime<const S extends ReturnType<typeof this.assetType>>(input: S): {
|
|
158
173
|
readonly aac: "audio/aac";
|
|
159
174
|
readonly abw: "application/x-abiword";
|
|
175
|
+
readonly aces: "image/aces";
|
|
160
176
|
readonly apng: "image/apng";
|
|
161
177
|
readonly arc: "application/x-freearc";
|
|
178
|
+
readonly avci: "image/avci";
|
|
162
179
|
readonly avif: "image/avif";
|
|
163
180
|
readonly avi: "video/x-msvideo";
|
|
164
181
|
readonly azw: "application/vnd.amazon.ebook";
|
|
@@ -167,26 +184,31 @@ declare class Fs {
|
|
|
167
184
|
readonly bz: "application/x-bzip";
|
|
168
185
|
readonly bz2: "application/x-bzip2";
|
|
169
186
|
readonly cda: "application/x-cdf";
|
|
170
|
-
readonly cjs: "application/javascript";
|
|
187
|
+
readonly cjs: "application/node" | "text/javascript";
|
|
171
188
|
readonly csh: "application/x-csh";
|
|
172
189
|
readonly css: "text/css";
|
|
173
190
|
readonly csv: "text/csv";
|
|
174
191
|
readonly doc: "application/msword";
|
|
175
192
|
readonly docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
193
|
+
readonly dpx: "image/dpx";
|
|
194
|
+
readonly emf: "image/emf";
|
|
176
195
|
readonly eot: "application/vnd.ms-fontobject";
|
|
177
196
|
readonly epub: "application/epub+zip";
|
|
178
197
|
readonly gif: "image/gif";
|
|
179
198
|
readonly glb: "model/gltf-binary";
|
|
180
199
|
readonly gltf: "model/gltf+json";
|
|
181
200
|
readonly gz: "application/x-gzip" | "application/gzip";
|
|
201
|
+
readonly hjif: "haptics/hjif";
|
|
202
|
+
readonly hmpg: "haptics/hmpg";
|
|
182
203
|
readonly htm: "text/html";
|
|
183
204
|
readonly html: "text/html";
|
|
184
205
|
readonly ico: "image/vnd.microsoft.icon";
|
|
185
206
|
readonly ics: "text/calendar";
|
|
207
|
+
readonly ivs: "haptics/ivs";
|
|
186
208
|
readonly jar: "application/java-archive";
|
|
187
209
|
readonly jpeg: "image/jpeg";
|
|
188
210
|
readonly jpg: "image/jpeg";
|
|
189
|
-
readonly js: "text/javascript";
|
|
211
|
+
readonly js: "application/node" | "text/javascript";
|
|
190
212
|
readonly json: "application/json";
|
|
191
213
|
readonly jsonld: "application/ld+json";
|
|
192
214
|
readonly m3u8: "application/vnd.apple.mpegurl";
|
|
@@ -223,13 +245,16 @@ declare class Fs {
|
|
|
223
245
|
readonly rar: "application/vnd.rar";
|
|
224
246
|
readonly rtf: "application/rtf";
|
|
225
247
|
readonly sh: "application/x-sh";
|
|
248
|
+
readonly sql: "application/sql";
|
|
226
249
|
readonly svg: "image/svg+xml";
|
|
227
250
|
readonly tar: "application/x-tar";
|
|
228
251
|
readonly tif: "image/tiff";
|
|
229
252
|
readonly tiff: "image/tiff";
|
|
253
|
+
readonly toml: "application/toml";
|
|
230
254
|
readonly ts: "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts";
|
|
231
255
|
readonly ttf: "application/font-sfnt" | "font/ttf";
|
|
232
256
|
readonly txt: "text/plain";
|
|
257
|
+
readonly usdz: "model/vnd.usdz+zip";
|
|
233
258
|
readonly vsd: "application/vnd.visio";
|
|
234
259
|
readonly vtt: "text/vtt";
|
|
235
260
|
readonly wasm: "application/wasm";
|
|
@@ -243,6 +268,8 @@ declare class Fs {
|
|
|
243
268
|
readonly xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
244
269
|
readonly xml: "application/xml";
|
|
245
270
|
readonly xul: "application/vnd.mozilla.xul+xml";
|
|
271
|
+
readonly yaml: "application/yaml";
|
|
272
|
+
readonly yml: "application/yaml";
|
|
246
273
|
readonly zip: "application/zip" | "application/x-zip-compressed";
|
|
247
274
|
readonly "3gp": "video/3gpp";
|
|
248
275
|
readonly "3g2": "video/3gpp2";
|
|
@@ -251,8 +278,10 @@ declare class Fs {
|
|
|
251
278
|
hmm: <const T extends ReturnType<typeof this.assetType>>(input: T) => {
|
|
252
279
|
readonly aac: "audio/aac";
|
|
253
280
|
readonly abw: "application/x-abiword";
|
|
281
|
+
readonly aces: "image/aces";
|
|
254
282
|
readonly apng: "image/apng";
|
|
255
283
|
readonly arc: "application/x-freearc";
|
|
284
|
+
readonly avci: "image/avci";
|
|
256
285
|
readonly avif: "image/avif";
|
|
257
286
|
readonly avi: "video/x-msvideo";
|
|
258
287
|
readonly azw: "application/vnd.amazon.ebook";
|
|
@@ -261,26 +290,31 @@ declare class Fs {
|
|
|
261
290
|
readonly bz: "application/x-bzip";
|
|
262
291
|
readonly bz2: "application/x-bzip2";
|
|
263
292
|
readonly cda: "application/x-cdf";
|
|
264
|
-
readonly cjs: "application/javascript";
|
|
293
|
+
readonly cjs: "application/node" | "text/javascript";
|
|
265
294
|
readonly csh: "application/x-csh";
|
|
266
295
|
readonly css: "text/css";
|
|
267
296
|
readonly csv: "text/csv";
|
|
268
297
|
readonly doc: "application/msword";
|
|
269
298
|
readonly docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
299
|
+
readonly dpx: "image/dpx";
|
|
300
|
+
readonly emf: "image/emf";
|
|
270
301
|
readonly eot: "application/vnd.ms-fontobject";
|
|
271
302
|
readonly epub: "application/epub+zip";
|
|
272
303
|
readonly gif: "image/gif";
|
|
273
304
|
readonly glb: "model/gltf-binary";
|
|
274
305
|
readonly gltf: "model/gltf+json";
|
|
275
306
|
readonly gz: "application/x-gzip" | "application/gzip";
|
|
307
|
+
readonly hjif: "haptics/hjif";
|
|
308
|
+
readonly hmpg: "haptics/hmpg";
|
|
276
309
|
readonly htm: "text/html";
|
|
277
310
|
readonly html: "text/html";
|
|
278
311
|
readonly ico: "image/vnd.microsoft.icon";
|
|
279
312
|
readonly ics: "text/calendar";
|
|
313
|
+
readonly ivs: "haptics/ivs";
|
|
280
314
|
readonly jar: "application/java-archive";
|
|
281
315
|
readonly jpeg: "image/jpeg";
|
|
282
316
|
readonly jpg: "image/jpeg";
|
|
283
|
-
readonly js: "text/javascript";
|
|
317
|
+
readonly js: "application/node" | "text/javascript";
|
|
284
318
|
readonly json: "application/json";
|
|
285
319
|
readonly jsonld: "application/ld+json";
|
|
286
320
|
readonly m3u8: "application/vnd.apple.mpegurl";
|
|
@@ -317,13 +351,16 @@ declare class Fs {
|
|
|
317
351
|
readonly rar: "application/vnd.rar";
|
|
318
352
|
readonly rtf: "application/rtf";
|
|
319
353
|
readonly sh: "application/x-sh";
|
|
354
|
+
readonly sql: "application/sql";
|
|
320
355
|
readonly svg: "image/svg+xml";
|
|
321
356
|
readonly tar: "application/x-tar";
|
|
322
357
|
readonly tif: "image/tiff";
|
|
323
358
|
readonly tiff: "image/tiff";
|
|
359
|
+
readonly toml: "application/toml";
|
|
324
360
|
readonly ts: "text/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts";
|
|
325
361
|
readonly ttf: "application/font-sfnt" | "font/ttf";
|
|
326
362
|
readonly txt: "text/plain";
|
|
363
|
+
readonly usdz: "model/vnd.usdz+zip";
|
|
327
364
|
readonly vsd: "application/vnd.visio";
|
|
328
365
|
readonly vtt: "text/vtt";
|
|
329
366
|
readonly wasm: "application/wasm";
|
|
@@ -337,18 +374,20 @@ declare class Fs {
|
|
|
337
374
|
readonly xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
338
375
|
readonly xml: "application/xml";
|
|
339
376
|
readonly xul: "application/vnd.mozilla.xul+xml";
|
|
377
|
+
readonly yaml: "application/yaml";
|
|
378
|
+
readonly yml: "application/yaml";
|
|
340
379
|
readonly zip: "application/zip" | "application/x-zip-compressed";
|
|
341
380
|
readonly "3gp": "video/3gpp";
|
|
342
381
|
readonly "3g2": "video/3gpp2";
|
|
343
382
|
readonly "7z": "application/x-7z-compressed";
|
|
344
383
|
}[T];
|
|
345
384
|
assetToBuffer<const T extends string>(path: T): Promise<{
|
|
346
|
-
readonly b64encodedData: `data:application/x-gzip;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:application/octet-stream;base64, ${string}` | `data:text/plain;base64, ${string}` | `data:model/obj;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:application/zip;base64, ${string}` | `data:application/x-zip-compressed;base64, ${string}` | `data:audio/aac;base64, ${string}` | `data:application/x-abiword;base64, ${string}` | `data:image/apng;base64, ${string}` | `data:application/x-freearc;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/
|
|
347
|
-
readonly extension: "aac" | "abw" | "apng" | "arc" | "avif" | "avi" | "azw" | "bin" | "bmp" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "doc" | "docx" | "eot" | "epub" | "gif" | "glb" | "gltf" | "gz" | "htm" | "html" | "ico" | "ics" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "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" | "svg" | "tar" | "tif" | "tiff" | "ts" | "ttf" | "txt" | "vsd" | "vtt" | "wasm" | "wav" | "weba" | "webp" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "zip" | "3gp" | "3g2" | "7z";
|
|
385
|
+
readonly b64encodedData: `data:application/node;base64, ${string}` | `data:text/javascript;base64, ${string}` | `data:application/x-gzip;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:application/octet-stream;base64, ${string}` | `data:text/plain;base64, ${string}` | `data:model/obj;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:application/zip;base64, ${string}` | `data:application/x-zip-compressed;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/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: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: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: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: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:video/3gpp;base64, ${string}` | `data:video/3gpp2;base64, ${string}` | `data:application/x-7z-compressed;base64, ${string}`;
|
|
386
|
+
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" | "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";
|
|
348
387
|
}>;
|
|
349
388
|
assetToBufferView<const T extends string>(path: T): Promise<{
|
|
350
389
|
readonly b64encodedData: string;
|
|
351
|
-
readonly extension: "aac" | "abw" | "apng" | "arc" | "avif" | "avi" | "azw" | "bin" | "bmp" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "doc" | "docx" | "eot" | "epub" | "gif" | "glb" | "gltf" | "gz" | "htm" | "html" | "ico" | "ics" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "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" | "svg" | "tar" | "tif" | "tiff" | "ts" | "ttf" | "txt" | "vsd" | "vtt" | "wasm" | "wav" | "weba" | "webp" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "zip" | "3gp" | "3g2" | "7z";
|
|
390
|
+
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" | "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";
|
|
352
391
|
}>;
|
|
353
392
|
formatHelper<const T extends string>(f: T): string;
|
|
354
393
|
range(from: number, to: number): number[];
|
|
@@ -357,6 +396,15 @@ declare class Fs {
|
|
|
357
396
|
chunkArray<T extends number>(arr: string[], maxChunkLength: T): string[][];
|
|
358
397
|
b64ToBlob<const T extends string>(b64Data: T): Blob;
|
|
359
398
|
cleanDataUrl<const C extends string>(props: C): string;
|
|
399
|
+
/**
|
|
400
|
+
* public cleanDataUrl<const C extends string>(props: C) {
|
|
401
|
+
return props.replace(
|
|
402
|
+
/^data:(?:image|application|video|text|font|model|audio|haptics|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i,
|
|
403
|
+
""
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
*/
|
|
360
408
|
/**
|
|
361
409
|
*
|
|
362
410
|
* @param inputUrl remote url to fetch data from
|
|
@@ -370,6 +418,22 @@ declare class Fs {
|
|
|
370
418
|
* ✅ 'public/assets/image-1.png'
|
|
371
419
|
*/
|
|
372
420
|
fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
421
|
+
imageTransform<const F extends "webp" | "avif" | "jpg" | "png" | "tif" | "tiff" | "jp2" | "jpeg">({ format, target, quality, tint, resize }: {
|
|
422
|
+
format: F;
|
|
423
|
+
target: Buffer<ArrayBuffer>;
|
|
424
|
+
quality?: number;
|
|
425
|
+
tint?: string | {
|
|
426
|
+
r?: number | undefined;
|
|
427
|
+
g?: number | undefined;
|
|
428
|
+
b?: number | undefined;
|
|
429
|
+
alpha?: number | undefined;
|
|
430
|
+
};
|
|
431
|
+
resize?: {
|
|
432
|
+
widthOrOptions?: number | sharp.ResizeOptions | null;
|
|
433
|
+
height?: number | null;
|
|
434
|
+
options?: sharp.ResizeOptions;
|
|
435
|
+
};
|
|
436
|
+
}): Promise<Buffer<ArrayBufferLike>>;
|
|
373
437
|
}
|
|
374
438
|
|
|
375
439
|
export { Fs as default };
|
package/dist/fs/index.js
CHANGED
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,11 +362,21 @@ 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
|
|
367
373
|
);
|
|
368
374
|
}
|
|
375
|
+
get jsVal() {
|
|
376
|
+
return ["application/node", "text/javascript"].reduce(
|
|
377
|
+
(union) => union
|
|
378
|
+
);
|
|
379
|
+
}
|
|
369
380
|
get objVal() {
|
|
370
381
|
return ["application/octet-stream", "text/plain", "model/obj"].reduce((union) => union);
|
|
371
382
|
}
|
|
@@ -384,8 +395,10 @@ var Fs = class {
|
|
|
384
395
|
return {
|
|
385
396
|
aac: "audio/aac",
|
|
386
397
|
abw: "application/x-abiword",
|
|
398
|
+
aces: "image/aces",
|
|
387
399
|
apng: "image/apng",
|
|
388
400
|
arc: "application/x-freearc",
|
|
401
|
+
avci: "image/avci",
|
|
389
402
|
avif: "image/avif",
|
|
390
403
|
avi: "video/x-msvideo",
|
|
391
404
|
azw: "application/vnd.amazon.ebook",
|
|
@@ -394,26 +407,31 @@ var Fs = class {
|
|
|
394
407
|
bz: "application/x-bzip",
|
|
395
408
|
bz2: "application/x-bzip2",
|
|
396
409
|
cda: "application/x-cdf",
|
|
397
|
-
cjs:
|
|
410
|
+
cjs: this.cjsVal,
|
|
398
411
|
csh: "application/x-csh",
|
|
399
412
|
css: "text/css",
|
|
400
413
|
csv: "text/csv",
|
|
401
414
|
doc: "application/msword",
|
|
402
415
|
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
416
|
+
dpx: "image/dpx",
|
|
417
|
+
emf: "image/emf",
|
|
403
418
|
eot: "application/vnd.ms-fontobject",
|
|
404
419
|
epub: "application/epub+zip",
|
|
405
420
|
gif: "image/gif",
|
|
406
421
|
glb: "model/gltf-binary",
|
|
407
422
|
gltf: "model/gltf+json",
|
|
408
423
|
gz: this.gzVal,
|
|
424
|
+
hjif: "haptics/hjif",
|
|
425
|
+
hmpg: "haptics/hmpg",
|
|
409
426
|
htm: "text/html",
|
|
410
427
|
html: "text/html",
|
|
411
428
|
ico: "image/vnd.microsoft.icon",
|
|
412
429
|
ics: "text/calendar",
|
|
430
|
+
ivs: "haptics/ivs",
|
|
413
431
|
jar: "application/java-archive",
|
|
414
432
|
jpeg: "image/jpeg",
|
|
415
433
|
jpg: "image/jpeg",
|
|
416
|
-
js:
|
|
434
|
+
js: this.jsVal,
|
|
417
435
|
json: "application/json",
|
|
418
436
|
jsonld: "application/ld+json",
|
|
419
437
|
m3u8: "application/vnd.apple.mpegurl",
|
|
@@ -450,13 +468,16 @@ var Fs = class {
|
|
|
450
468
|
rar: "application/vnd.rar",
|
|
451
469
|
rtf: "application/rtf",
|
|
452
470
|
sh: "application/x-sh",
|
|
471
|
+
sql: "application/sql",
|
|
453
472
|
svg: "image/svg+xml",
|
|
454
473
|
tar: "application/x-tar",
|
|
455
474
|
tif: "image/tiff",
|
|
456
475
|
tiff: "image/tiff",
|
|
476
|
+
toml: "application/toml",
|
|
457
477
|
ts: this.tsVal,
|
|
458
478
|
ttf: this.ttfVal,
|
|
459
479
|
txt: "text/plain",
|
|
480
|
+
usdz: "model/vnd.usdz+zip",
|
|
460
481
|
vsd: "application/vnd.visio",
|
|
461
482
|
vtt: "text/vtt",
|
|
462
483
|
wasm: "application/wasm",
|
|
@@ -470,6 +491,8 @@ var Fs = class {
|
|
|
470
491
|
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
471
492
|
xml: "application/xml",
|
|
472
493
|
xul: "application/vnd.mozilla.xul+xml",
|
|
494
|
+
yaml: "application/yaml",
|
|
495
|
+
yml: "application/yaml",
|
|
473
496
|
zip: this.zipVal,
|
|
474
497
|
"3gp": "video/3gpp",
|
|
475
498
|
"3g2": "video/3gpp2",
|
|
@@ -498,6 +521,12 @@ var Fs = class {
|
|
|
498
521
|
};
|
|
499
522
|
}
|
|
500
523
|
async assetToBufferView(path) {
|
|
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`);
|
|
501
530
|
const response = await fetch(path);
|
|
502
531
|
if (!response.ok) {
|
|
503
532
|
throw new Error(`Failed to fetch asset: ${response.statusText}`);
|
|
@@ -574,7 +603,7 @@ var Fs = class {
|
|
|
574
603
|
{
|
|
575
604
|
const sliceSize = 512;
|
|
576
605
|
const typeMatch = b64Data.match(
|
|
577
|
-
/^data:(image|application|video|text|model|
|
|
606
|
+
/^data:(?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i
|
|
578
607
|
);
|
|
579
608
|
const type = typeMatch?.[1];
|
|
580
609
|
if (!typeMatch) {
|
|
@@ -598,10 +627,19 @@ var Fs = class {
|
|
|
598
627
|
}
|
|
599
628
|
cleanDataUrl(props) {
|
|
600
629
|
return props.replace(
|
|
601
|
-
/^data:(image|application|video|text|font|model|audio)\/[A-Za-z0-9+-.]
|
|
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,
|
|
602
638
|
""
|
|
603
639
|
);
|
|
604
640
|
}
|
|
641
|
+
|
|
642
|
+
*/
|
|
605
643
|
/**
|
|
606
644
|
*
|
|
607
645
|
* @param inputUrl remote url to fetch data from
|
|
@@ -621,7 +659,7 @@ var Fs = class {
|
|
|
621
659
|
const formattedPath = useDetectedExtension ? `${outputPath}.${result.extension}` : outputPath;
|
|
622
660
|
if (/\./g.test(formattedPath) === false) {
|
|
623
661
|
throw new Error(
|
|
624
|
-
"either add false as the third argument in `fetchRemoteWriteLocal`
|
|
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"
|
|
625
663
|
);
|
|
626
664
|
}
|
|
627
665
|
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
@@ -629,6 +667,66 @@ var Fs = class {
|
|
|
629
667
|
return console.error(err);
|
|
630
668
|
}
|
|
631
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
|
+
// }
|
|
632
730
|
};
|
|
633
731
|
// Annotate the CommonJS export names for ESM import in node:
|
|
634
732
|
0 && (module.exports = {
|