@d0paminedriven/fs 4.0.0 → 5.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.
@@ -0,0 +1,7 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ export {
5
+ __name
6
+ };
7
+ //# sourceMappingURL=chunk-7QVYU63E.js.map
@@ -0,0 +1,161 @@
1
+ import {
2
+ UrlService
3
+ } from "./chunk-XHN56MDK.js";
4
+ import {
5
+ __name
6
+ } from "./chunk-7QVYU63E.js";
7
+
8
+ // src/mime/index.ts
9
+ var extMimeMap = {
10
+ aac: ["audio/aac"],
11
+ abw: ["application/x-abiword"],
12
+ aces: ["image/aces"],
13
+ apng: ["image/apng"],
14
+ arc: ["application/x-freearc"],
15
+ avci: ["image/avci"],
16
+ avif: ["image/avif"],
17
+ avi: ["video/x-msvideo"],
18
+ azw: ["application/vnd.amazon.ebook"],
19
+ bin: ["application/octet-stream"],
20
+ bmp: ["image/bmp"],
21
+ bz: ["application/x-bzip"],
22
+ bz2: ["application/x-bzip2"],
23
+ cda: ["application/x-cdf"],
24
+ cjs: ["application/node", "text/javascript"],
25
+ csh: ["application/x-csh"],
26
+ css: ["text/css"],
27
+ csv: ["text/csv"],
28
+ doc: ["application/msword"],
29
+ docx: [
30
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
31
+ ],
32
+ dpx: ["image/dpx"],
33
+ emf: ["image/emf"],
34
+ eot: ["application/vnd.ms-fontobject"],
35
+ epub: ["application/epub+zip"],
36
+ gif: ["image/gif"],
37
+ glb: ["model/gltf-binary"],
38
+ gltf: ["model/gltf+json"],
39
+ gz: ["application/x-gzip", "application/gzip"],
40
+ hjif: ["haptics/hjif"],
41
+ hmpg: ["haptics/hmpg"],
42
+ htm: ["text/html"],
43
+ html: ["text/html"],
44
+ ico: ["image/vnd.microsoft.icon"],
45
+ ics: ["text/calendar"],
46
+ ivs: ["haptics/ivs"],
47
+ jar: ["application/java-archive"],
48
+ jpeg: ["image/jpeg"],
49
+ jpg: ["image/jpeg"],
50
+ js: ["application/node", "text/javascript"],
51
+ json: ["application/json"],
52
+ jsonld: ["application/ld+json"],
53
+ ktx: ["image/ktx"],
54
+ ktx2: ["image/ktx2"],
55
+ m3u8: ["application/vnd.apple.mpegurl"],
56
+ m4a: ["audio/mp4"],
57
+ m4v: ["video/mp4"],
58
+ md: ["text/markdown"],
59
+ mdx: ["application/x-mdx"],
60
+ mid: ["audio/midi"],
61
+ midi: ["audio/x-midi"],
62
+ mjs: ["text/javascript"],
63
+ mp3: ["audio/mpeg"],
64
+ mp4: ["video/mp4"],
65
+ mpeg: ["video/mpeg"],
66
+ mpkg: ["application/vnd.apple.installer+xml"],
67
+ ndjson: ["application/x-ndjson"],
68
+ obj: ["application/octet-stream", "text/plain", "model/obj"],
69
+ odp: ["application/vnd.oasis.opendocument.presentation"],
70
+ ods: ["application/vnd.oasis.opendocument.spreadsheet"],
71
+ odt: ["application/vnd.oasis.opendocument.text"],
72
+ oga: ["audio/ogg"],
73
+ ogg: ["audio/ogg"],
74
+ ogv: ["video/ogg"],
75
+ ogx: ["application/ogg"],
76
+ opus: ["audio/ogg"],
77
+ otf: ["font/otf"],
78
+ png: ["image/png"],
79
+ pdf: ["application/pdf"],
80
+ php: ["application/x-httpd-php"],
81
+ pkpass: ["application/vnd.apple.pkpass"],
82
+ ppt: ["application/vnd.ms-powerpoint"],
83
+ pptx: [
84
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation"
85
+ ],
86
+ py: ["text/x-python"],
87
+ pyc: ["application/x-python-code"],
88
+ rar: ["application/vnd.rar"],
89
+ rtf: ["application/rtf"],
90
+ sh: ["application/x-sh"],
91
+ sql: ["application/sql"],
92
+ svg: ["image/svg+xml"],
93
+ tar: ["application/x-tar"],
94
+ tif: ["image/tiff"],
95
+ tiff: ["image/tiff"],
96
+ toml: ["application/toml"],
97
+ ts: ["text/typescript", "video/mp2t", "video/vnd.dlna.mpeg-tts"],
98
+ ttf: ["application/font-sfnt", "font/ttf"],
99
+ txt: ["text/plain"],
100
+ usdz: ["model/vnd.usdz+zip"],
101
+ vsd: ["application/vnd.visio"],
102
+ vtt: ["text/vtt"],
103
+ wasm: ["application/wasm"],
104
+ wav: ["audio/wav"],
105
+ weba: ["video/webm"],
106
+ webp: ["image/webp"],
107
+ woff: ["font/woff"],
108
+ woff2: ["font/woff2"],
109
+ xhtml: ["application/xhtml+xml"],
110
+ xls: ["application/vnd.ms-excel"],
111
+ xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
112
+ xml: ["application/xml"],
113
+ xul: ["application/vnd.mozilla.xul+xml"],
114
+ yaml: ["application/yaml"],
115
+ yml: ["application/yaml"],
116
+ zip: ["application/zip", "application/x-zip-compressed"],
117
+ "3gp": ["video/3gpp"],
118
+ "3g2": ["video/3gpp2"],
119
+ "7z": ["application/x-7z-compressed"]
120
+ };
121
+ var MimeService = class extends UrlService {
122
+ static {
123
+ __name(this, "MimeService");
124
+ }
125
+ constructor() {
126
+ super();
127
+ }
128
+ mimeTypeObj = extMimeMap;
129
+ assetType(url) {
130
+ const parsed = this.parseUrl(url);
131
+ if (!parsed) return void 0;
132
+ const ext = parsed.pathname.split(/([.])/g)?.reverse()?.[0]?.toLowerCase();
133
+ return ext && ext in this.mimeTypeObj ? ext : void 0;
134
+ }
135
+ getMimes(ext) {
136
+ return this.mimeTypeObj[ext];
137
+ }
138
+ getMimeFor(ext, opts) {
139
+ const mimes = this.getMimes(ext);
140
+ if (mimes.length === 1) return mimes[0];
141
+ if (opts?.type) {
142
+ const found = mimes.find((mime) => mime.startsWith(opts.type + "/"));
143
+ return found ?? mimes[0];
144
+ }
145
+ return mimes[0];
146
+ }
147
+ isMimeFor(ext, mime) {
148
+ return this.getMimes(ext).find((s) => s === mime);
149
+ }
150
+ getMimeTypeForPath(path, opts) {
151
+ const ext = this.assetType(path);
152
+ if (!ext) return "application/octet-stream";
153
+ return this.getMimeFor(ext, opts);
154
+ }
155
+ };
156
+
157
+ export {
158
+ extMimeMap,
159
+ MimeService
160
+ };
161
+ //# sourceMappingURL=chunk-EHOBCDHE.js.map
@@ -0,0 +1,322 @@
1
+ import {
2
+ MimeService
3
+ } from "./chunk-EHOBCDHE.js";
4
+ import {
5
+ __name
6
+ } from "./chunk-7QVYU63E.js";
7
+
8
+ // src/fs/index.ts
9
+ import { execSync } from "child_process";
10
+ import fsSync from "fs";
11
+ import fsAsync from "fs/promises";
12
+ import { join, relative, resolve } from "path";
13
+ import * as dotenv from "dotenv";
14
+ import expand from "dotenv-expand";
15
+ import sharp from "sharp";
16
+ dotenv.config();
17
+ var Fs = class extends MimeService {
18
+ constructor(cwd) {
19
+ super();
20
+ this.cwd = cwd;
21
+ }
22
+ static {
23
+ __name(this, "Fs");
24
+ }
25
+ get myEnv() {
26
+ return dotenv.config({ processEnv: {} });
27
+ }
28
+ parseDotEnv() {
29
+ return expand.expand(this.myEnv);
30
+ }
31
+ exists(target) {
32
+ if (!/\//gm.test(target))
33
+ return fsSync.existsSync(resolve(join(this.cwd, target)));
34
+ return fsSync.existsSync(relative(this.cwd ?? process.cwd(), target));
35
+ }
36
+ wait(ms) {
37
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
38
+ }
39
+ handleBuffStrArrUnion(arr) {
40
+ return arr.map(
41
+ (v) => Buffer.isBuffer(v) ? Buffer.from(v).toString("utf-8") : v
42
+ );
43
+ }
44
+ isRootPathTargeted(path) {
45
+ if (/^(?:\.\/|\.|\/|root|\.\.\/|~\/\.?|cwd|\.\/\.)$/g.test(path)) {
46
+ return true;
47
+ } else return false;
48
+ }
49
+ readDir(path, options) {
50
+ if (this.isRootPathTargeted(path)) {
51
+ return this.handleBuffStrArrUnion(
52
+ fsSync.readdirSync(resolve(join(this.cwd, "./")), options)
53
+ );
54
+ } else {
55
+ return this.handleBuffStrArrUnion(
56
+ fsSync.readdirSync(
57
+ relative(this.cwd ??= process.cwd(), path),
58
+ options
59
+ )
60
+ );
61
+ }
62
+ }
63
+ executeCommand = /* @__PURE__ */ __name(({
64
+ command,
65
+ ...options
66
+ }) => Buffer.from(execSync(command, { ...options }).toJSON().data).toString(
67
+ "utf-8"
68
+ ), "executeCommand");
69
+ existsSync(path) {
70
+ if (!/\//gm.test(path))
71
+ return fsSync.existsSync(resolve(join(this.cwd, path)));
72
+ return fsSync.existsSync(relative(this.cwd ?? process.cwd(), path));
73
+ }
74
+ pathHandler(path) {
75
+ return /\//g.test(path) === true ? path.split(/([/])/gim).reverse().slice(2).reverse().join("") : path;
76
+ }
77
+ mkdirSync(path, options) {
78
+ return fsSync.mkdirSync(relative(this.cwd ?? process.cwd(), path), options);
79
+ }
80
+ fileSizeMb(path) {
81
+ return fsSync.statSync(relative(this.cwd ?? process.cwd(), path)).size / (1024 * 1024);
82
+ }
83
+ generateDirIfDNE(path, options) {
84
+ const doesExist = this.existsSync(path);
85
+ if (doesExist === true) return;
86
+ else {
87
+ return this.mkdirSync(path, options);
88
+ }
89
+ }
90
+ withWs(path, data, options) {
91
+ try {
92
+ if (/\//g.test(path) === true) {
93
+ return this.generateDirIfDNE(this.pathHandler(path), {
94
+ recursive: true
95
+ });
96
+ } else return path;
97
+ } catch (error) {
98
+ console.error(
99
+ `[withWs error]: `.concat(
100
+ typeof error === "string" ? error : JSON.stringify(error, null, 2)
101
+ )
102
+ );
103
+ } finally {
104
+ return fsSync.createWriteStream(
105
+ relative(this.cwd ?? process.cwd(), path),
106
+ typeof options !== "undefined" ? typeof options === "object" ? options : options : { autoClose: true }
107
+ ).write(Buffer.from(Buffer.from(data).toJSON().data));
108
+ }
109
+ }
110
+ writeFileAsync = /* @__PURE__ */ __name(async (path, data, options) => {
111
+ try {
112
+ if (/\//g.test(path) === true)
113
+ return this.generateDirIfDNE(this.pathHandler(path), {
114
+ recursive: true
115
+ });
116
+ else return path;
117
+ } catch (error) {
118
+ console.error(
119
+ `[writeFileAsync error]: `.concat(
120
+ error instanceof Error ? error.message : typeof error === "string" ? error : JSON.stringify(error, null, 2)
121
+ )
122
+ );
123
+ } finally {
124
+ return await fsAsync.writeFile(
125
+ relative(this.cwd ?? process.cwd(), path),
126
+ Buffer.from(Buffer.from(data).toJSON().data),
127
+ options
128
+ );
129
+ }
130
+ }, "writeFileAsync");
131
+ dirExists(dir) {
132
+ const resolved = relative(this.cwd, dir);
133
+ try {
134
+ return fsSync.statSync(resolved).isDirectory();
135
+ } catch {
136
+ return false;
137
+ }
138
+ }
139
+ async unlink(path) {
140
+ if (this.existsSync(path)) {
141
+ return await fsAsync.unlink(relative(this.cwd, path));
142
+ } else {
143
+ throw new Error(`input path ${path} does not exist`);
144
+ }
145
+ }
146
+ rmFile(filePath) {
147
+ if (this.existsSync(filePath)) {
148
+ if (this.isRootPathTargeted(filePath)) {
149
+ fsSync.rmSync(resolve(join(this.cwd, filePath)));
150
+ } else fsSync.rmSync(resolve(this.cwd, filePath));
151
+ } else return;
152
+ }
153
+ async rmdir(dir, options) {
154
+ const resolved = relative(this.cwd, dir);
155
+ if (this.dirExists(dir)) {
156
+ return fsAsync.rmdir(relative(this.cwd, dir), options);
157
+ } else {
158
+ throw new Error(`directory ${resolved} does not exist`);
159
+ }
160
+ }
161
+ rmDirSync(dir) {
162
+ const resolved = resolve(this.cwd, dir);
163
+ if (this.dirExists(dir)) {
164
+ return fsSync.rm(resolved, { force: true, recursive: true }, (err) => {
165
+ if (err?.message) {
166
+ console.error(err?.message);
167
+ }
168
+ });
169
+ } else {
170
+ throw new Error(`directory ${resolved} does not exist`);
171
+ }
172
+ }
173
+ fileToBuffer = /* @__PURE__ */ __name((path) => Buffer.from(
174
+ fsSync.readFileSync(relative(this.cwd ?? process.cwd(), path)).toJSON().data
175
+ ), "fileToBuffer");
176
+ dirContainsDir(readDir, targetDir, options) {
177
+ return this.readDir(readDir, options).filter((t) => t.split(".").length === 1).includes(targetDir);
178
+ }
179
+ async assetToBuffer(path) {
180
+ const [fetcher] = await Promise.all([
181
+ fetch(path).then((t) => t.arrayBuffer())
182
+ ]);
183
+ const mime = this.getMimeTypeForPath(path);
184
+ const b64encodedData = `data:${mime};base64, ${Buffer.from(fetcher).toString("base64")}`;
185
+ const extension = this.assetType(path) ?? "txt";
186
+ return {
187
+ b64encodedData,
188
+ extension
189
+ };
190
+ }
191
+ async assetToBufferView(path) {
192
+ const response = await fetch(path);
193
+ if (!response.ok) {
194
+ throw new Error(`Failed to fetch asset: ${response.statusText}`);
195
+ }
196
+ const reader = response.body?.getReader();
197
+ if (reader) {
198
+ const chunks = Array.of();
199
+ while (true) {
200
+ const { done, value } = await reader.read();
201
+ if (done) break;
202
+ if (value) chunks.push(value);
203
+ }
204
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
205
+ const completeBuffer = new Uint8Array(totalLength);
206
+ let offset = 0;
207
+ for (const chunk of chunks) {
208
+ completeBuffer.set(chunk, offset);
209
+ offset += chunk.length;
210
+ }
211
+ const mime = this.getMimeTypeForPath(path);
212
+ const b64encodedData = `data:${mime};base64, ${Buffer.from(completeBuffer).toString("base64")}`;
213
+ const extension = this.assetType(path);
214
+ return { b64encodedData, extension };
215
+ } else {
216
+ const arrayBuffer = await response.arrayBuffer();
217
+ const mime = this.getMimeTypeForPath(path);
218
+ const b64encodedData = `data:${mime};base64, ${Buffer.from(arrayBuffer).toString("base64")}`;
219
+ const extension = this.assetType(path);
220
+ return { b64encodedData, extension };
221
+ }
222
+ }
223
+ formatHelper(f) {
224
+ if (/([A-Za-z]+-[A-Za-z]+)/g.test(f) === true) {
225
+ const formatting = f.split(/-/g).map((v) => v.substring(0, 1).toUpperCase().concat(v.substring(1))).join(" ");
226
+ return formatting;
227
+ } else return f.substring(0, 1).toUpperCase().concat(f.substring(1));
228
+ }
229
+ cleanDataUrl(props) {
230
+ return props.replace(
231
+ /^data:(?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i,
232
+ ""
233
+ );
234
+ }
235
+ /**
236
+ *
237
+ * @param inputUrl remote url to fetch data from
238
+ * @param outputPath desired output path relative to the cwd
239
+ * @param useDetectedExtension optional, defaults to true
240
+ *
241
+ * if `useDetectedExtension` is false you must include the file extension in your output path →
242
+ *
243
+ * 🚫 'public/assets/image-1'
244
+ *
245
+ * ✅ 'public/assets/image-1.png'
246
+ */
247
+ async fetchRemoteWriteLocal(inputUrl, outputPath, useDetectedExtension = true) {
248
+ try {
249
+ const result = await this.assetToBufferView(inputUrl);
250
+ const cleanData = this.cleanDataUrl(result.b64encodedData);
251
+ const formattedPath = useDetectedExtension ? `${outputPath}.${result.extension}` : outputPath;
252
+ if (/\./g.test(formattedPath) === false) {
253
+ throw new Error(
254
+ "either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension) or provide an output path without a file extension"
255
+ );
256
+ }
257
+ this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
258
+ } catch (err) {
259
+ return console.error(err);
260
+ }
261
+ }
262
+ async fetchRemoteWriteLocalLargeFiles(inputUrl, outputPath, useDetectedExtension = true) {
263
+ const MAX_SAFE_IN_MEMORY_MB = 100;
264
+ try {
265
+ const head = await fetch(inputUrl, { method: "HEAD" });
266
+ const contentLength = head.headers.get("content-length");
267
+ const fileSizeMb = contentLength ? parseInt(contentLength, 10) / (1024 * 1024) : null;
268
+ const formattedPath = useDetectedExtension ? `${outputPath}.${this.assetType(inputUrl)}` : outputPath;
269
+ this.generateDirIfDNE(this.pathHandler(formattedPath), {
270
+ recursive: true
271
+ });
272
+ if (fileSizeMb !== null && fileSizeMb > MAX_SAFE_IN_MEMORY_MB) {
273
+ const res = await fetch(inputUrl);
274
+ if (!res.ok || !res.body) {
275
+ throw new Error(`Failed to fetch asset: ${res.statusText}`);
276
+ }
277
+ const writeStream = fsSync.createWriteStream(
278
+ relative(this.cwd ?? process.cwd(), formattedPath)
279
+ );
280
+ const reader = res.body.getReader();
281
+ const pump = /* @__PURE__ */ __name(async () => {
282
+ while (true) {
283
+ const { done, value } = await reader.read();
284
+ if (done) break;
285
+ writeStream.write(value);
286
+ }
287
+ writeStream.end();
288
+ }, "pump");
289
+ await pump();
290
+ return;
291
+ }
292
+ const result = await this.assetToBufferView(inputUrl);
293
+ const cleanData = this.cleanDataUrl(result.b64encodedData);
294
+ this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
295
+ } catch (err) {
296
+ console.error(`[fetchRemoteWriteLocal error]:`, err);
297
+ }
298
+ }
299
+ // USE fluent-ffmpeg for video/animated image transforms (apng, etc)
300
+ // https://www.npmjs.com/package/fluent-ffmpeg
301
+ // https://www.npmjs.com/package/@types/fluent-ffmpeg
302
+ async imageTransform({
303
+ format,
304
+ target,
305
+ quality = 80,
306
+ tint,
307
+ resize
308
+ }) {
309
+ if (tint && !resize) {
310
+ return await sharp(target).toFormat(format, { quality }).tint(tint).toBuffer();
311
+ } else if (!tint && resize) {
312
+ return await sharp(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
313
+ } else if (tint && resize) {
314
+ return await sharp(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
315
+ } else return await sharp(target).toFormat(format, { quality }).toBuffer();
316
+ }
317
+ };
318
+
319
+ export {
320
+ Fs
321
+ };
322
+ //# sourceMappingURL=chunk-HWF53VET.js.map
@@ -0,0 +1,131 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-7QVYU63E.js";
4
+
5
+ // src/utils/index.ts
6
+ var UtilsService = class {
7
+ static {
8
+ __name(this, "UtilsService");
9
+ }
10
+ chunkArray(arr, maxChunkLength) {
11
+ const chunks = Array.of();
12
+ let currentChunkLength = 0;
13
+ let currentChunk = Array.of();
14
+ for (const [index, val] of arr.entries()) {
15
+ if (val.length + currentChunkLength >= maxChunkLength) {
16
+ if (currentChunk.length) {
17
+ chunks.push(currentChunk);
18
+ }
19
+ currentChunkLength = val.length;
20
+ currentChunk = [val];
21
+ } else {
22
+ currentChunk.push(val);
23
+ currentChunkLength += val.length + 1;
24
+ }
25
+ if (arr.length === index + 1) {
26
+ chunks.push(currentChunk);
27
+ }
28
+ }
29
+ return chunks.length ? chunks : [arr];
30
+ }
31
+ b64ToBlob(b64Data) {
32
+ {
33
+ const sliceSize = 512;
34
+ const typeMatch = b64Data.match(
35
+ /^data:(?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i
36
+ );
37
+ const type = typeMatch?.[1];
38
+ if (!typeMatch) {
39
+ throw new Error(`${b64Data} is not a valid data Url`);
40
+ }
41
+ const byteCharacters = Buffer.from(b64Data, "base64").toString("utf-8");
42
+ const byteArrays = Array.of();
43
+ for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
44
+ const slice = byteCharacters.slice(offset, offset + sliceSize);
45
+ const byteNumbers = Array.of();
46
+ byteNumbers.push(slice.length);
47
+ for (let i = 0; i < slice.length; i++) {
48
+ byteNumbers[i] = slice.charCodeAt(i);
49
+ }
50
+ const byteArray = new Uint8Array(byteNumbers);
51
+ byteArrays.push(byteArray);
52
+ }
53
+ const blob = new Blob(byteArrays, { type });
54
+ return blob;
55
+ }
56
+ }
57
+ arrToArrOfArrs = /* @__PURE__ */ __name(({
58
+ arrToFragment = Array.of(),
59
+ arrOfArrsAggregator = Array.of(),
60
+ interval
61
+ }) => new Promise(
62
+ (resolve, _reject) => resolve(
63
+ ((interval2) => {
64
+ for (let i = 0; i <= arrToFragment.length; i++) {
65
+ if ((i % interval2 === 0 || i === 0) && i <= arrToFragment.length) {
66
+ let segment = arrToFragment.slice(i, i + interval2);
67
+ arrOfArrsAggregator.push(segment);
68
+ }
69
+ }
70
+ })(interval)
71
+ )
72
+ ).then((_) => arrOfArrsAggregator), "arrToArrOfArrs");
73
+ extractTuple(obj, props) {
74
+ return [props, obj[props]];
75
+ }
76
+ sort(obj, order) {
77
+ return Object.fromEntries(
78
+ Object.entries(obj).sort(
79
+ ([a, _aa], [b, _bb]) => order === "DESC" ? b.localeCompare(a) - a.localeCompare(b) : a.localeCompare(b) - b.localeCompare(a)
80
+ )
81
+ );
82
+ }
83
+ excludeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
84
+ const resolve = Object.fromEntries(
85
+ Object.entries(obj).map(([key, val]) => {
86
+ if (props.includes(key)) {
87
+ return ["omit", "omit"];
88
+ } else return [key, val];
89
+ }).filter(([t, _v]) => /omit/.test(t) === false)
90
+ );
91
+ return typeof sort !== "undefined" ? this.sort(resolve, sort) : resolve;
92
+ }, "excludeTargeted");
93
+ includeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
94
+ const resolve = Object.fromEntries(
95
+ props.map((val) => this.extractTuple(obj, val))
96
+ );
97
+ return typeof sort !== "undefined" ? this.sort(resolve, sort) : resolve;
98
+ }, "includeTargeted");
99
+ countsSorter = /* @__PURE__ */ __name(({
100
+ counter,
101
+ keySort,
102
+ valSort
103
+ }) => Object.fromEntries(
104
+ Object.entries(counter).sort(
105
+ ([aStr, _aNum], [bStr, _bNum]) => keySort === "DESC" ? bStr.localeCompare(aStr) - aStr.localeCompare(bStr) : aStr.localeCompare(bStr) - bStr.localeCompare(aStr)
106
+ ).sort(
107
+ ([_aStr, aNum], [_bStr, bNum]) => valSort === "ASC" ? aNum - bNum : bNum - aNum
108
+ )
109
+ ), "countsSorter");
110
+ range(from, to) {
111
+ const values = Array.of();
112
+ for (let i = from; i < to; i++) {
113
+ values.push(i);
114
+ }
115
+ return values;
116
+ }
117
+ isPrimeNumber = /* @__PURE__ */ __name((n) => {
118
+ for (let i = 2; n > i; i++) {
119
+ if (n % i === 0) {
120
+ return false;
121
+ }
122
+ }
123
+ return n > 1;
124
+ }, "isPrimeNumber");
125
+ acceptor = /* @__PURE__ */ __name((num) => [...Array(num !== 0 ? num : this.range(num = -101, num = 101)).keys()].reverse().filter(this.isPrimeNumber), "acceptor");
126
+ };
127
+
128
+ export {
129
+ UtilsService
130
+ };
131
+ //# sourceMappingURL=chunk-QMN5ZCE4.js.map
@@ -0,0 +1,30 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-7QVYU63E.js";
4
+
5
+ // src/url/index.ts
6
+ var UrlService = class {
7
+ static {
8
+ __name(this, "UrlService");
9
+ }
10
+ URL_REGEX = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
11
+ parseUrl(url) {
12
+ const parsed = this.URL_REGEX.exec(url);
13
+ if (parsed) {
14
+ return {
15
+ href: parsed[0],
16
+ protocol: parsed[1] ?? "",
17
+ baseUrl: `${parsed[1]}${parsed[3]}`,
18
+ host: parsed[4] ?? "",
19
+ pathname: parsed[5] ?? "",
20
+ search: parsed[6] ?? "",
21
+ hash: parsed[8] ?? ""
22
+ };
23
+ } else return null;
24
+ }
25
+ };
26
+
27
+ export {
28
+ UrlService
29
+ };
30
+ //# sourceMappingURL=chunk-XHN56MDK.js.map