@d0paminedriven/fs 4.1.0 → 6.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/README.md +105 -0
- package/dist/chunk-7QVYU63E.js +7 -0
- package/dist/chunk-EHOBCDHE.js +161 -0
- package/dist/chunk-KZWE4E4I.js +328 -0
- package/dist/chunk-QMN5ZCE4.js +131 -0
- package/dist/chunk-XHN56MDK.js +30 -0
- package/dist/fs/index.cjs +207 -493
- package/dist/fs/index.d.cts +14 -382
- package/dist/fs/index.d.ts +14 -382
- package/dist/fs/index.js +4 -2
- package/dist/index.cjs +340 -496
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +16 -7
- package/dist/mime/index.cjs +204 -0
- package/dist/mime/index.d.cts +238 -0
- package/dist/mime/index.d.ts +238 -0
- package/dist/mime/index.js +11 -0
- package/dist/types/index.d.cts +8 -8
- package/dist/types/index.d.ts +8 -8
- package/dist/types/index.js +0 -6
- package/dist/url/index.cjs +51 -0
- package/dist/url/index.d.cts +28 -0
- package/dist/url/index.d.ts +28 -0
- package/dist/url/index.js +8 -0
- package/dist/utils/index.cjs +152 -0
- package/dist/utils/index.d.cts +29 -0
- package/dist/utils/index.d.ts +29 -0
- package/dist/utils/index.js +8 -0
- package/package.json +29 -17
- package/dist/chunk-ELR74GDM.js +0 -774
- package/dist/chunk-I6PDZOED.js +0 -44
package/dist/chunk-ELR74GDM.js
DELETED
|
@@ -1,774 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__commonJS,
|
|
3
|
-
__name,
|
|
4
|
-
__toESM,
|
|
5
|
-
init_esm_shims
|
|
6
|
-
} from "./chunk-I6PDZOED.js";
|
|
7
|
-
|
|
8
|
-
// ../../node_modules/dotenv-expand/lib/main.js
|
|
9
|
-
var require_main = __commonJS({
|
|
10
|
-
"../../node_modules/dotenv-expand/lib/main.js"(exports, module) {
|
|
11
|
-
"use strict";
|
|
12
|
-
init_esm_shims();
|
|
13
|
-
function _resolveEscapeSequences(value) {
|
|
14
|
-
return value.replace(/\\\$/g, "$");
|
|
15
|
-
}
|
|
16
|
-
__name(_resolveEscapeSequences, "_resolveEscapeSequences");
|
|
17
|
-
function expandValue(value, processEnv, runningParsed) {
|
|
18
|
-
const env = { ...runningParsed, ...processEnv };
|
|
19
|
-
const regex = /(?<!\\)\${([^{}]+)}|(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
20
|
-
let result = value;
|
|
21
|
-
let match;
|
|
22
|
-
const seen = /* @__PURE__ */ new Set();
|
|
23
|
-
while ((match = regex.exec(result)) !== null) {
|
|
24
|
-
seen.add(result);
|
|
25
|
-
const [template, bracedExpression, unbracedExpression] = match;
|
|
26
|
-
const expression = bracedExpression || unbracedExpression;
|
|
27
|
-
const opRegex = /(:\+|\+|:-|-)/;
|
|
28
|
-
const opMatch = expression.match(opRegex);
|
|
29
|
-
const splitter = opMatch ? opMatch[0] : null;
|
|
30
|
-
const r = expression.split(splitter);
|
|
31
|
-
let defaultValue;
|
|
32
|
-
let value2;
|
|
33
|
-
const key = r.shift();
|
|
34
|
-
if ([":+", "+"].includes(splitter)) {
|
|
35
|
-
defaultValue = env[key] ? r.join(splitter) : "";
|
|
36
|
-
value2 = null;
|
|
37
|
-
} else {
|
|
38
|
-
defaultValue = r.join(splitter);
|
|
39
|
-
value2 = env[key];
|
|
40
|
-
}
|
|
41
|
-
if (value2) {
|
|
42
|
-
if (seen.has(value2)) {
|
|
43
|
-
result = result.replace(template, defaultValue);
|
|
44
|
-
} else {
|
|
45
|
-
result = result.replace(template, value2);
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
result = result.replace(template, defaultValue);
|
|
49
|
-
}
|
|
50
|
-
if (result === runningParsed[key]) {
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
regex.lastIndex = 0;
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
__name(expandValue, "expandValue");
|
|
58
|
-
function expand2(options) {
|
|
59
|
-
const runningParsed = {};
|
|
60
|
-
let processEnv = process.env;
|
|
61
|
-
if (options && options.processEnv != null) {
|
|
62
|
-
processEnv = options.processEnv;
|
|
63
|
-
}
|
|
64
|
-
for (const key in options.parsed) {
|
|
65
|
-
let value = options.parsed[key];
|
|
66
|
-
if (processEnv[key] && processEnv[key] !== value) {
|
|
67
|
-
value = processEnv[key];
|
|
68
|
-
} else {
|
|
69
|
-
value = expandValue(value, processEnv, runningParsed);
|
|
70
|
-
}
|
|
71
|
-
options.parsed[key] = _resolveEscapeSequences(value);
|
|
72
|
-
runningParsed[key] = _resolveEscapeSequences(value);
|
|
73
|
-
}
|
|
74
|
-
for (const processKey in options.parsed) {
|
|
75
|
-
processEnv[processKey] = options.parsed[processKey];
|
|
76
|
-
}
|
|
77
|
-
return options;
|
|
78
|
-
}
|
|
79
|
-
__name(expand2, "expand");
|
|
80
|
-
module.exports.expand = expand2;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// src/fs/index.ts
|
|
85
|
-
init_esm_shims();
|
|
86
|
-
var import_dotenv_expand = __toESM(require_main(), 1);
|
|
87
|
-
import { execSync } from "child_process";
|
|
88
|
-
import fsSync from "fs";
|
|
89
|
-
import fsAsync from "fs/promises";
|
|
90
|
-
import { join, relative, resolve } from "path";
|
|
91
|
-
import * as dotenv from "dotenv";
|
|
92
|
-
import sharp from "sharp";
|
|
93
|
-
dotenv.config();
|
|
94
|
-
var Fs = class {
|
|
95
|
-
constructor(cwd) {
|
|
96
|
-
this.cwd = cwd;
|
|
97
|
-
}
|
|
98
|
-
static {
|
|
99
|
-
__name(this, "Fs");
|
|
100
|
-
}
|
|
101
|
-
extractTuple(obj, props) {
|
|
102
|
-
return [props, obj[props]];
|
|
103
|
-
}
|
|
104
|
-
sort(obj, order) {
|
|
105
|
-
return Object.fromEntries(
|
|
106
|
-
Object.entries(obj).sort(
|
|
107
|
-
([a, _aa], [b, _bb]) => order === "DESC" ? b.localeCompare(a) - a.localeCompare(b) : a.localeCompare(b) - b.localeCompare(a)
|
|
108
|
-
)
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
excludeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
|
|
112
|
-
const resolve2 = Object.fromEntries(
|
|
113
|
-
Object.entries(obj).map(([key, val]) => {
|
|
114
|
-
if (props.includes(key)) {
|
|
115
|
-
return ["omit", "omit"];
|
|
116
|
-
} else return [key, val];
|
|
117
|
-
}).filter(([t, _v]) => /omit/.test(t) === false)
|
|
118
|
-
);
|
|
119
|
-
return typeof sort !== "undefined" ? this.sort(resolve2, sort) : resolve2;
|
|
120
|
-
}, "excludeTargeted");
|
|
121
|
-
includeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
|
|
122
|
-
const resolve2 = Object.fromEntries(
|
|
123
|
-
props.map((val) => this.extractTuple(obj, val))
|
|
124
|
-
);
|
|
125
|
-
return typeof sort !== "undefined" ? this.sort(resolve2, sort) : resolve2;
|
|
126
|
-
}, "includeTargeted");
|
|
127
|
-
get myEnv() {
|
|
128
|
-
return dotenv.config({ processEnv: {} });
|
|
129
|
-
}
|
|
130
|
-
parseDotEnv() {
|
|
131
|
-
return import_dotenv_expand.default.expand(this.myEnv);
|
|
132
|
-
}
|
|
133
|
-
omitFields(target, keys) {
|
|
134
|
-
let obj = target;
|
|
135
|
-
keys.forEach((t) => {
|
|
136
|
-
if (t in obj) {
|
|
137
|
-
delete obj[t];
|
|
138
|
-
return obj;
|
|
139
|
-
} else {
|
|
140
|
-
return obj;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
return obj;
|
|
144
|
-
}
|
|
145
|
-
omitTargetedFields(targ, keys) {
|
|
146
|
-
return { ...this.omitFields(targ, keys) };
|
|
147
|
-
}
|
|
148
|
-
exists(target) {
|
|
149
|
-
if (!/\//gm.test(target))
|
|
150
|
-
return fsSync.existsSync(resolve(join(this.cwd, target)));
|
|
151
|
-
return fsSync.existsSync(relative(this.cwd ?? process.cwd(), target));
|
|
152
|
-
}
|
|
153
|
-
arrToArrOfArrs = /* @__PURE__ */ __name(({
|
|
154
|
-
arrToFragment = Array.of(),
|
|
155
|
-
arrOfArrsAggregator = Array.of(),
|
|
156
|
-
interval
|
|
157
|
-
}) => new Promise(
|
|
158
|
-
(resolve2, _reject) => resolve2(
|
|
159
|
-
((interval2) => {
|
|
160
|
-
for (let i = 0; i <= arrToFragment.length; i++) {
|
|
161
|
-
if ((i % interval2 === 0 || i === 0) && i <= arrToFragment.length) {
|
|
162
|
-
let segment = arrToFragment.slice(i, i + interval2);
|
|
163
|
-
arrOfArrsAggregator.push(segment);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
})(interval)
|
|
167
|
-
)
|
|
168
|
-
).then((_) => arrOfArrsAggregator), "arrToArrOfArrs");
|
|
169
|
-
wait(ms) {
|
|
170
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
171
|
-
}
|
|
172
|
-
countsSorter = /* @__PURE__ */ __name(({
|
|
173
|
-
counter,
|
|
174
|
-
keySort,
|
|
175
|
-
valSort
|
|
176
|
-
}) => Object.fromEntries(
|
|
177
|
-
Object.entries(counter).sort(
|
|
178
|
-
([aStr, _aNum], [bStr, _bNum]) => keySort === "DESC" ? bStr.localeCompare(aStr) - aStr.localeCompare(bStr) : aStr.localeCompare(bStr) - bStr.localeCompare(aStr)
|
|
179
|
-
).sort(
|
|
180
|
-
([_aStr, aNum], [_bStr, bNum]) => valSort === "ASC" ? aNum - bNum : bNum - aNum
|
|
181
|
-
)
|
|
182
|
-
), "countsSorter");
|
|
183
|
-
handleBuffStrArrUnion(arr) {
|
|
184
|
-
return arr.map(
|
|
185
|
-
(v) => Buffer.isBuffer(v) ? Buffer.from(v).toString("utf-8") : v
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
isRootPathTargeted(path) {
|
|
189
|
-
if (/^(?:\.\/|\.|\/|root|\.\.\/|~\/\.?|cwd|\.\/\.)$/g.test(path)) {
|
|
190
|
-
return true;
|
|
191
|
-
} else return false;
|
|
192
|
-
}
|
|
193
|
-
readDir(path, options) {
|
|
194
|
-
if (this.isRootPathTargeted(path)) {
|
|
195
|
-
return this.handleBuffStrArrUnion(
|
|
196
|
-
fsSync.readdirSync(resolve(join(this.cwd, "./")), options)
|
|
197
|
-
);
|
|
198
|
-
} else
|
|
199
|
-
return this.handleBuffStrArrUnion(
|
|
200
|
-
fsSync.readdirSync(
|
|
201
|
-
relative(this.cwd ??= process.cwd(), path),
|
|
202
|
-
options
|
|
203
|
-
)
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
executeCommand = /* @__PURE__ */ __name(({
|
|
207
|
-
command,
|
|
208
|
-
...options
|
|
209
|
-
}) => Buffer.from(execSync(command, { ...options }).toJSON().data).toString(
|
|
210
|
-
"utf-8"
|
|
211
|
-
), "executeCommand");
|
|
212
|
-
fileGenTimestamp(d) {
|
|
213
|
-
const date = d.toISOString();
|
|
214
|
-
return `/* file-autogenerated by @d0paminedriven/fs on ${date.split(/([T])/gm)?.[0]} at ${date.split(/([T])/gm)[2]?.split(/([Z])/gm)?.[0]} UTC */`;
|
|
215
|
-
}
|
|
216
|
-
configFileGenTimestamp(d) {
|
|
217
|
-
return this.fileGenTimestamp(d).replace("/*", "#").replace("*/", "");
|
|
218
|
-
}
|
|
219
|
-
mdFileGenTimestamp(d) {
|
|
220
|
-
return this.fileGenTimestamp(d).replace("/*", "<!--").replace("*/", "-->");
|
|
221
|
-
}
|
|
222
|
-
existsSync(path) {
|
|
223
|
-
if (!/\//gm.test(path))
|
|
224
|
-
return fsSync.existsSync(resolve(join(this.cwd, path)));
|
|
225
|
-
return fsSync.existsSync(relative(this.cwd ?? process.cwd(), path));
|
|
226
|
-
}
|
|
227
|
-
pathHandler(path) {
|
|
228
|
-
return /\//g.test(path) === true ? path.split(/([/])/gim).reverse().slice(2).reverse().join("") : path;
|
|
229
|
-
}
|
|
230
|
-
mkdirSync(path, options) {
|
|
231
|
-
return fsSync.mkdirSync(relative(this.cwd ?? process.cwd(), path), options);
|
|
232
|
-
}
|
|
233
|
-
fileSizeMb(path) {
|
|
234
|
-
return fsSync.statSync(relative(this.cwd ?? process.cwd(), path)).size / (1024 * 1024);
|
|
235
|
-
}
|
|
236
|
-
generateDirIfDNE(path, options) {
|
|
237
|
-
const doesExist = this.existsSync(path);
|
|
238
|
-
if (doesExist === true) return;
|
|
239
|
-
else {
|
|
240
|
-
return this.mkdirSync(path, options);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
withWs(path, data, options) {
|
|
244
|
-
try {
|
|
245
|
-
if (/\//g.test(path) === true) {
|
|
246
|
-
return this.generateDirIfDNE(this.pathHandler(path), {
|
|
247
|
-
recursive: true
|
|
248
|
-
});
|
|
249
|
-
} else return path;
|
|
250
|
-
} catch (error) {
|
|
251
|
-
console.error(
|
|
252
|
-
`[withWs error]: `.concat(
|
|
253
|
-
typeof error === "string" ? error : JSON.stringify(error, null, 2)
|
|
254
|
-
)
|
|
255
|
-
);
|
|
256
|
-
} finally {
|
|
257
|
-
return fsSync.createWriteStream(
|
|
258
|
-
relative(this.cwd ?? process.cwd(), path),
|
|
259
|
-
typeof options !== "undefined" ? typeof options === "object" ? options : options : { autoClose: true }
|
|
260
|
-
).write(Buffer.from(Buffer.from(data).toJSON().data));
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
writeFileAsync = /* @__PURE__ */ __name(async (path, data, options) => {
|
|
264
|
-
try {
|
|
265
|
-
if (/\//g.test(path) === true)
|
|
266
|
-
return this.generateDirIfDNE(this.pathHandler(path), {
|
|
267
|
-
recursive: true
|
|
268
|
-
});
|
|
269
|
-
else return path;
|
|
270
|
-
} catch (error) {
|
|
271
|
-
console.error(
|
|
272
|
-
`[writeFileAsync error]: `.concat(
|
|
273
|
-
error instanceof Error ? error.message : typeof error === "string" ? error : JSON.stringify(error, null, 2)
|
|
274
|
-
)
|
|
275
|
-
);
|
|
276
|
-
} finally {
|
|
277
|
-
return await fsAsync.writeFile(
|
|
278
|
-
relative(this.cwd ?? process.cwd(), path),
|
|
279
|
-
Buffer.from(
|
|
280
|
-
Buffer.from(data).toJSON().data
|
|
281
|
-
),
|
|
282
|
-
options
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
}, "writeFileAsync");
|
|
286
|
-
dirExists(dir) {
|
|
287
|
-
const resolved = relative(this.cwd, dir);
|
|
288
|
-
try {
|
|
289
|
-
return fsSync.statSync(resolved).isDirectory();
|
|
290
|
-
} catch {
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
async unlink(path) {
|
|
295
|
-
if (this.existsSync(path)) {
|
|
296
|
-
return await fsAsync.unlink(relative(this.cwd, path));
|
|
297
|
-
} else {
|
|
298
|
-
throw new Error(`input path ${path} does not exist`);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
async rmdir(dir, options) {
|
|
302
|
-
const resolved = relative(this.cwd, dir);
|
|
303
|
-
if (this.dirExists(dir)) {
|
|
304
|
-
return fsAsync.rmdir(relative(this.cwd, dir), options);
|
|
305
|
-
} else {
|
|
306
|
-
throw new Error(`directory ${resolved} does not exist`);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
rm(dir) {
|
|
310
|
-
const resolved = resolve(this.cwd, dir);
|
|
311
|
-
if (this.dirExists(dir)) {
|
|
312
|
-
return fsSync.rm(resolved, { force: true, recursive: true }, (err) => {
|
|
313
|
-
if (err?.message) {
|
|
314
|
-
console.error(err?.message);
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
} else {
|
|
318
|
-
throw new Error(`directory ${resolved} does not exist`);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
fileToBuffer = /* @__PURE__ */ __name((path) => Buffer.from(
|
|
322
|
-
fsSync.readFileSync(relative(this.cwd ?? process.cwd(), path)).toJSON().data
|
|
323
|
-
), "fileToBuffer");
|
|
324
|
-
dirContainsDir(readDir, targetDir, options) {
|
|
325
|
-
return this.readDir(readDir, options).filter((t) => t.split(".").length === 1).includes(targetDir);
|
|
326
|
-
}
|
|
327
|
-
/* begin url */
|
|
328
|
-
isServerSide() {
|
|
329
|
-
return typeof window === "undefined";
|
|
330
|
-
}
|
|
331
|
-
isBase64(str) {
|
|
332
|
-
if (!str) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
return /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?\n?$/.test(
|
|
336
|
-
str.replace(/\n/g, "")
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
previewRegex = /\/preview(\/\w|\?)/;
|
|
340
|
-
isPreviewPath(uri) {
|
|
341
|
-
if (typeof uri === "string") {
|
|
342
|
-
return this.previewRegex.test(uri);
|
|
343
|
-
}
|
|
344
|
-
return false;
|
|
345
|
-
}
|
|
346
|
-
// eslint-disable-next-line @typescript-eslint/class-literal-property-style
|
|
347
|
-
get URL_REGEX() {
|
|
348
|
-
return /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
349
|
-
}
|
|
350
|
-
parseUrl(url) {
|
|
351
|
-
const parsed = this.URL_REGEX.exec(url);
|
|
352
|
-
return {
|
|
353
|
-
href: parsed[0],
|
|
354
|
-
protocol: parsed[1] ?? "",
|
|
355
|
-
baseUrl: `${parsed[1]}${parsed[3]}`,
|
|
356
|
-
host: parsed[4] ?? "",
|
|
357
|
-
pathname: parsed[5] ?? "",
|
|
358
|
-
search: parsed[6] ?? "",
|
|
359
|
-
hash: parsed[8] ?? ""
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
/* end url */
|
|
363
|
-
get cjsVal() {
|
|
364
|
-
return ["application/node", "text/javascript"].reduce(
|
|
365
|
-
(union) => union
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
get gzVal() {
|
|
369
|
-
return ["application/x-gzip", "application/gzip"].reduce(
|
|
370
|
-
(union) => union
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
get jsVal() {
|
|
374
|
-
return ["application/node", "text/javascript"].reduce(
|
|
375
|
-
(union) => union
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
get objVal() {
|
|
379
|
-
return ["application/octet-stream", "text/plain", "model/obj"].reduce((union) => union);
|
|
380
|
-
}
|
|
381
|
-
get tsVal() {
|
|
382
|
-
return ["text/typescript", "video/mp2t", "video/vnd.dlna.mpeg-tts"].reduce((union) => union);
|
|
383
|
-
}
|
|
384
|
-
get ttfVal() {
|
|
385
|
-
return ["application/font-sfnt", "font/ttf"].reduce(
|
|
386
|
-
(union) => union
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
get zipVal() {
|
|
390
|
-
return ["application/zip", "application/x-zip-compressed"].reduce((union) => union);
|
|
391
|
-
}
|
|
392
|
-
get mimeTypeObj() {
|
|
393
|
-
return {
|
|
394
|
-
aac: "audio/aac",
|
|
395
|
-
abw: "application/x-abiword",
|
|
396
|
-
aces: "image/aces",
|
|
397
|
-
apng: "image/apng",
|
|
398
|
-
arc: "application/x-freearc",
|
|
399
|
-
avci: "image/avci",
|
|
400
|
-
avif: "image/avif",
|
|
401
|
-
avi: "video/x-msvideo",
|
|
402
|
-
azw: "application/vnd.amazon.ebook",
|
|
403
|
-
bin: "application/octet-stream",
|
|
404
|
-
bmp: "image/bmp",
|
|
405
|
-
bz: "application/x-bzip",
|
|
406
|
-
bz2: "application/x-bzip2",
|
|
407
|
-
cda: "application/x-cdf",
|
|
408
|
-
cjs: this.cjsVal,
|
|
409
|
-
csh: "application/x-csh",
|
|
410
|
-
css: "text/css",
|
|
411
|
-
csv: "text/csv",
|
|
412
|
-
doc: "application/msword",
|
|
413
|
-
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
414
|
-
dpx: "image/dpx",
|
|
415
|
-
emf: "image/emf",
|
|
416
|
-
eot: "application/vnd.ms-fontobject",
|
|
417
|
-
epub: "application/epub+zip",
|
|
418
|
-
gif: "image/gif",
|
|
419
|
-
glb: "model/gltf-binary",
|
|
420
|
-
gltf: "model/gltf+json",
|
|
421
|
-
gz: this.gzVal,
|
|
422
|
-
hjif: "haptics/hjif",
|
|
423
|
-
hmpg: "haptics/hmpg",
|
|
424
|
-
htm: "text/html",
|
|
425
|
-
html: "text/html",
|
|
426
|
-
ico: "image/vnd.microsoft.icon",
|
|
427
|
-
ics: "text/calendar",
|
|
428
|
-
ivs: "haptics/ivs",
|
|
429
|
-
jar: "application/java-archive",
|
|
430
|
-
jpeg: "image/jpeg",
|
|
431
|
-
jpg: "image/jpeg",
|
|
432
|
-
js: this.jsVal,
|
|
433
|
-
json: "application/json",
|
|
434
|
-
jsonld: "application/ld+json",
|
|
435
|
-
ktx: "image/ktx",
|
|
436
|
-
ktx2: "image/ktx2",
|
|
437
|
-
m3u8: "application/vnd.apple.mpegurl",
|
|
438
|
-
m4a: "audio/mp4",
|
|
439
|
-
m4v: "video/mp4",
|
|
440
|
-
md: "text/markdown",
|
|
441
|
-
mdx: "application/x-mdx",
|
|
442
|
-
mid: "audio/midi",
|
|
443
|
-
midi: "audio/x-midi",
|
|
444
|
-
mjs: "text/javascript",
|
|
445
|
-
mp3: "audio/mpeg",
|
|
446
|
-
mp4: "video/mp4",
|
|
447
|
-
mpeg: "video/mpeg",
|
|
448
|
-
mpkg: "application/vnd.apple.installer+xml",
|
|
449
|
-
ndjson: "application/x-ndjson",
|
|
450
|
-
obj: this.objVal,
|
|
451
|
-
odp: "application/vnd.oasis.opendocument.presentation",
|
|
452
|
-
ods: "application/vnd.oasis.opendocument.spreadsheet",
|
|
453
|
-
odt: "application/vnd.oasis.opendocument.text",
|
|
454
|
-
oga: "audio/ogg",
|
|
455
|
-
ogg: "audio/ogg",
|
|
456
|
-
ogv: "video/ogg",
|
|
457
|
-
ogx: "application/ogg",
|
|
458
|
-
opus: "audio/ogg",
|
|
459
|
-
otf: "font/otf",
|
|
460
|
-
png: "image/png",
|
|
461
|
-
pdf: "application/pdf",
|
|
462
|
-
php: "application/x-httpd-php",
|
|
463
|
-
pkpass: "application/vnd.apple.pkpass",
|
|
464
|
-
ppt: "application/vnd.ms-powerpoint",
|
|
465
|
-
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
466
|
-
py: "text/x-python",
|
|
467
|
-
pyc: "application/x-python-code",
|
|
468
|
-
rar: "application/vnd.rar",
|
|
469
|
-
rtf: "application/rtf",
|
|
470
|
-
sh: "application/x-sh",
|
|
471
|
-
sql: "application/sql",
|
|
472
|
-
svg: "image/svg+xml",
|
|
473
|
-
tar: "application/x-tar",
|
|
474
|
-
tif: "image/tiff",
|
|
475
|
-
tiff: "image/tiff",
|
|
476
|
-
toml: "application/toml",
|
|
477
|
-
ts: this.tsVal,
|
|
478
|
-
ttf: this.ttfVal,
|
|
479
|
-
txt: "text/plain",
|
|
480
|
-
usdz: "model/vnd.usdz+zip",
|
|
481
|
-
vsd: "application/vnd.visio",
|
|
482
|
-
vtt: "text/vtt",
|
|
483
|
-
wasm: "application/wasm",
|
|
484
|
-
wav: "audio/wav",
|
|
485
|
-
weba: "video/webm",
|
|
486
|
-
webp: "image/webp",
|
|
487
|
-
woff: "font/woff",
|
|
488
|
-
woff2: "font/woff2",
|
|
489
|
-
xhtml: "application/xhtml+xml",
|
|
490
|
-
xls: "application/vnd.ms-excel",
|
|
491
|
-
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
492
|
-
xml: "application/xml",
|
|
493
|
-
xul: "application/vnd.mozilla.xul+xml",
|
|
494
|
-
yaml: "application/yaml",
|
|
495
|
-
yml: "application/yaml",
|
|
496
|
-
zip: this.zipVal,
|
|
497
|
-
"3gp": "video/3gpp",
|
|
498
|
-
"3g2": "video/3gpp2",
|
|
499
|
-
"7z": "application/x-7z-compressed"
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
assetType(url) {
|
|
503
|
-
const u = this.parseUrl(url);
|
|
504
|
-
return u.pathname?.split(/([.])/gim)?.reverse()?.[0];
|
|
505
|
-
}
|
|
506
|
-
getMime(input) {
|
|
507
|
-
return this.mimeTypeObj[input];
|
|
508
|
-
}
|
|
509
|
-
hmm = /* @__PURE__ */ __name((input) => {
|
|
510
|
-
return this.mimeTypeObj[input];
|
|
511
|
-
}, "hmm");
|
|
512
|
-
async assetToBuffer(path) {
|
|
513
|
-
const [fetcher] = await Promise.all([
|
|
514
|
-
fetch(path).then((t) => t.arrayBuffer())
|
|
515
|
-
]);
|
|
516
|
-
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(fetcher).toString("base64")}`;
|
|
517
|
-
const extension = this.assetType(path);
|
|
518
|
-
return {
|
|
519
|
-
b64encodedData,
|
|
520
|
-
extension
|
|
521
|
-
};
|
|
522
|
-
}
|
|
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(
|
|
530
|
-
`no file extension detected in input url ${path}, attempting fetch`
|
|
531
|
-
);
|
|
532
|
-
const response = await fetch(path);
|
|
533
|
-
if (!response.ok) {
|
|
534
|
-
throw new Error(`Failed to fetch asset: ${response.statusText}`);
|
|
535
|
-
}
|
|
536
|
-
const reader = response.body?.getReader();
|
|
537
|
-
if (reader) {
|
|
538
|
-
const chunks = [];
|
|
539
|
-
while (true) {
|
|
540
|
-
const { done, value } = await reader.read();
|
|
541
|
-
if (done) break;
|
|
542
|
-
if (value) chunks.push(value);
|
|
543
|
-
}
|
|
544
|
-
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
545
|
-
const completeBuffer = new Uint8Array(totalLength);
|
|
546
|
-
let offset = 0;
|
|
547
|
-
for (const chunk of chunks) {
|
|
548
|
-
completeBuffer.set(chunk, offset);
|
|
549
|
-
offset += chunk.length;
|
|
550
|
-
}
|
|
551
|
-
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(completeBuffer).toString("base64")}`;
|
|
552
|
-
const extension = this.assetType(path);
|
|
553
|
-
return { b64encodedData, extension };
|
|
554
|
-
} else {
|
|
555
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
556
|
-
const b64encodedData = `data:${this.getMime(this.assetType(path))};base64, ${Buffer.from(arrayBuffer).toString("base64")}`;
|
|
557
|
-
const extension = this.assetType(path);
|
|
558
|
-
return { b64encodedData, extension };
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
formatHelper(f) {
|
|
562
|
-
if (/([A-Za-z]+-[A-Za-z]+)/g.test(f) === true) {
|
|
563
|
-
const formatting = f.split(/-/g).map((v) => v.substring(0, 1).toUpperCase().concat(v.substring(1))).join(" ");
|
|
564
|
-
return formatting;
|
|
565
|
-
} else return f.substring(0, 1).toUpperCase().concat(f.substring(1));
|
|
566
|
-
}
|
|
567
|
-
range(from, to) {
|
|
568
|
-
const values = Array.of();
|
|
569
|
-
for (let i = from; i < to; i++) {
|
|
570
|
-
values.push(i);
|
|
571
|
-
}
|
|
572
|
-
return values;
|
|
573
|
-
}
|
|
574
|
-
isPrimeNumber = /* @__PURE__ */ __name((n) => {
|
|
575
|
-
for (let i = 2; n > i; i++) {
|
|
576
|
-
if (n % i === 0) {
|
|
577
|
-
return false;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return n > 1;
|
|
581
|
-
}, "isPrimeNumber");
|
|
582
|
-
acceptor = /* @__PURE__ */ __name((num) => [...Array(num !== 0 ? num : this.range(num = -101, num = 101)).keys()].reverse().filter(this.isPrimeNumber), "acceptor");
|
|
583
|
-
chunkArray(arr, maxChunkLength) {
|
|
584
|
-
const chunks = Array.of();
|
|
585
|
-
let currentChunkLength = 0;
|
|
586
|
-
let currentChunk = Array.of();
|
|
587
|
-
for (const [index, val] of arr.entries()) {
|
|
588
|
-
if (val.length + currentChunkLength >= maxChunkLength) {
|
|
589
|
-
if (currentChunk.length) {
|
|
590
|
-
chunks.push(currentChunk);
|
|
591
|
-
}
|
|
592
|
-
currentChunkLength = val.length;
|
|
593
|
-
currentChunk = [val];
|
|
594
|
-
} else {
|
|
595
|
-
currentChunk.push(val);
|
|
596
|
-
currentChunkLength += val.length + 1;
|
|
597
|
-
}
|
|
598
|
-
if (arr.length === index + 1) {
|
|
599
|
-
chunks.push(currentChunk);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return chunks.length ? chunks : [arr];
|
|
603
|
-
}
|
|
604
|
-
b64ToBlob(b64Data) {
|
|
605
|
-
{
|
|
606
|
-
const sliceSize = 512;
|
|
607
|
-
const typeMatch = b64Data.match(
|
|
608
|
-
/^data:(?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i
|
|
609
|
-
);
|
|
610
|
-
const type = typeMatch?.[1];
|
|
611
|
-
if (!typeMatch) {
|
|
612
|
-
throw new Error(`${b64Data} is not a valid data Url`);
|
|
613
|
-
}
|
|
614
|
-
const byteCharacters = Buffer.from(b64Data, "base64").toString("utf-8");
|
|
615
|
-
const byteArrays = Array.of();
|
|
616
|
-
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
|
617
|
-
const slice = byteCharacters.slice(offset, offset + sliceSize);
|
|
618
|
-
const byteNumbers = Array.of();
|
|
619
|
-
byteNumbers.push(slice.length);
|
|
620
|
-
for (let i = 0; i < slice.length; i++) {
|
|
621
|
-
byteNumbers[i] = slice.charCodeAt(i);
|
|
622
|
-
}
|
|
623
|
-
const byteArray = new Uint8Array(byteNumbers);
|
|
624
|
-
byteArrays.push(byteArray);
|
|
625
|
-
}
|
|
626
|
-
const blob = new Blob(byteArrays, { type });
|
|
627
|
-
return blob;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
cleanDataUrl(props) {
|
|
631
|
-
return props.replace(
|
|
632
|
-
/^data:(?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i,
|
|
633
|
-
""
|
|
634
|
-
);
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* public cleanDataUrl<const C extends string>(props: C) {
|
|
638
|
-
return props.replace(
|
|
639
|
-
/^data:(?:image|application|video|text|font|model|audio|haptics|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i,
|
|
640
|
-
""
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
*/
|
|
645
|
-
/**
|
|
646
|
-
*
|
|
647
|
-
* @param inputUrl remote url to fetch data from
|
|
648
|
-
* @param outputPath desired output path relative to the cwd
|
|
649
|
-
* @param useDetectedExtension optional, defaults to true
|
|
650
|
-
*
|
|
651
|
-
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
652
|
-
*
|
|
653
|
-
* 🚫 'public/assets/image-1'
|
|
654
|
-
*
|
|
655
|
-
* ✅ 'public/assets/image-1.png'
|
|
656
|
-
*/
|
|
657
|
-
async fetchRemoteWriteLocal(inputUrl, outputPath, useDetectedExtension = true) {
|
|
658
|
-
try {
|
|
659
|
-
const result = await this.assetToBufferView(inputUrl);
|
|
660
|
-
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
661
|
-
const formattedPath = useDetectedExtension ? `${outputPath}.${result.extension}` : outputPath;
|
|
662
|
-
if (/\./g.test(formattedPath) === false) {
|
|
663
|
-
throw new Error(
|
|
664
|
-
"either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension) or provide an output path without a file extension"
|
|
665
|
-
);
|
|
666
|
-
}
|
|
667
|
-
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
668
|
-
} catch (err) {
|
|
669
|
-
return console.error(err);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
async fetchRemoteWriteLocalLargeFiles(inputUrl, outputPath, useDetectedExtension = true) {
|
|
673
|
-
const MAX_SAFE_IN_MEMORY_MB = 100;
|
|
674
|
-
try {
|
|
675
|
-
const head = await fetch(inputUrl, { method: "HEAD" });
|
|
676
|
-
const contentLength = head.headers.get("content-length");
|
|
677
|
-
const fileSizeMb = contentLength ? parseInt(contentLength, 10) / (1024 * 1024) : null;
|
|
678
|
-
const formattedPath = useDetectedExtension ? `${outputPath}.${this.assetType(inputUrl)}` : outputPath;
|
|
679
|
-
this.generateDirIfDNE(this.pathHandler(formattedPath), {
|
|
680
|
-
recursive: true
|
|
681
|
-
});
|
|
682
|
-
if (fileSizeMb !== null && fileSizeMb > MAX_SAFE_IN_MEMORY_MB) {
|
|
683
|
-
const res = await fetch(inputUrl);
|
|
684
|
-
if (!res.ok || !res.body) {
|
|
685
|
-
throw new Error(`Failed to fetch asset: ${res.statusText}`);
|
|
686
|
-
}
|
|
687
|
-
const writeStream = fsSync.createWriteStream(
|
|
688
|
-
relative(this.cwd ?? process.cwd(), formattedPath)
|
|
689
|
-
);
|
|
690
|
-
const reader = res.body.getReader();
|
|
691
|
-
const pump = /* @__PURE__ */ __name(async () => {
|
|
692
|
-
while (true) {
|
|
693
|
-
const { done, value } = await reader.read();
|
|
694
|
-
if (done) break;
|
|
695
|
-
writeStream.write(value);
|
|
696
|
-
}
|
|
697
|
-
writeStream.end();
|
|
698
|
-
}, "pump");
|
|
699
|
-
await pump();
|
|
700
|
-
return;
|
|
701
|
-
}
|
|
702
|
-
const result = await this.assetToBufferView(inputUrl);
|
|
703
|
-
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
704
|
-
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
705
|
-
} catch (err) {
|
|
706
|
-
console.error(`[fetchRemoteWriteLocal error]:`, err);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
// USE fluent-ffmpeg for video/animated image transforms (apng, etc)
|
|
710
|
-
// https://www.npmjs.com/package/fluent-ffmpeg
|
|
711
|
-
// https://www.npmjs.com/package/@types/fluent-ffmpeg
|
|
712
|
-
async imageTransform({
|
|
713
|
-
format,
|
|
714
|
-
target,
|
|
715
|
-
quality = 80,
|
|
716
|
-
tint,
|
|
717
|
-
resize
|
|
718
|
-
}) {
|
|
719
|
-
if (tint && !resize) {
|
|
720
|
-
return await sharp(target).toFormat(format, { quality }).tint(tint).toBuffer();
|
|
721
|
-
} else if (!tint && resize) {
|
|
722
|
-
return await sharp(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
|
|
723
|
-
} else if (tint && resize) {
|
|
724
|
-
return await sharp(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
|
|
725
|
-
} else return await sharp(target).toFormat(format, { quality }).toBuffer();
|
|
726
|
-
}
|
|
727
|
-
// public async convertImage<
|
|
728
|
-
// const L extends "local" | "remote",
|
|
729
|
-
// const F extends "webp" | "avif" | "jpg" | "png",
|
|
730
|
-
// const I extends string,
|
|
731
|
-
// const O extends string
|
|
732
|
-
// >(isLocal: L, inputUrl: I, outputPath: O, useDetectedExtension = true) {
|
|
733
|
-
// if (isLocal === "remote") {
|
|
734
|
-
// try {
|
|
735
|
-
// const result = await this.assetToBufferView(inputUrl);
|
|
736
|
-
// const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
737
|
-
// const imageBuffer = Buffer.from(cleanData, "base64");
|
|
738
|
-
// const s = this.imageTransform({format: "webp", target: imageBuffer, quality: 100, resize: {options: {width: 1.2, height: 1.2}}} )
|
|
739
|
-
// const formattedPath = useDetectedExtension
|
|
740
|
-
// ? `${outputPath}.${result.extension}`
|
|
741
|
-
// : outputPath;
|
|
742
|
-
// if (/\./g.test(formattedPath) === false) {
|
|
743
|
-
// throw new Error(
|
|
744
|
-
// "either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension)"
|
|
745
|
-
// );
|
|
746
|
-
// }
|
|
747
|
-
// this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
748
|
-
// } catch (err) {
|
|
749
|
-
// return console.error(err);
|
|
750
|
-
// }
|
|
751
|
-
// } else {
|
|
752
|
-
// try {
|
|
753
|
-
// const result = await this.assetToBufferView(inputUrl);
|
|
754
|
-
// const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
755
|
-
// const formattedPath = useDetectedExtension
|
|
756
|
-
// ? `${outputPath}.${result.extension}`
|
|
757
|
-
// : outputPath;
|
|
758
|
-
// if (/\./g.test(formattedPath) === false) {
|
|
759
|
-
// throw new Error(
|
|
760
|
-
// "either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension)"
|
|
761
|
-
// );
|
|
762
|
-
// }
|
|
763
|
-
// this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
764
|
-
// } catch (err) {
|
|
765
|
-
// return console.error(err);
|
|
766
|
-
// }
|
|
767
|
-
// }
|
|
768
|
-
// }
|
|
769
|
-
};
|
|
770
|
-
|
|
771
|
-
export {
|
|
772
|
-
Fs
|
|
773
|
-
};
|
|
774
|
-
//# sourceMappingURL=chunk-ELR74GDM.js.map
|