@putkoff/abstract-utilities 1.0.126 → 1.0.128

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,947 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+ var fsp = require('node:fs/promises');
5
+ var path$1 = require('node:path');
6
+
7
+ function _interopNamespaceDefault(e) {
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
25
+ var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
26
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
27
+
28
+ /** True if token is structurally bad or its exp ≤ now. */
29
+ function isTokenExpired(token) {
30
+ try {
31
+ const payload = decodeJwt(token);
32
+ return Date.now() / 1000 >= payload.exp;
33
+ }
34
+ catch {
35
+ return true; // treat malformed token as expired
36
+ }
37
+ }
38
+ /* ------------------------------------------------------------------ */
39
+ /* internals */
40
+ /* ------------------------------------------------------------------ */
41
+ function decodeJwt(token) {
42
+ const [header, payload, signature] = token.split(".");
43
+ if (!header || !payload || !signature) {
44
+ throw new Error("Malformed JWT");
45
+ }
46
+ // Handle URL-safe Base64
47
+ let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
48
+ // Add padding if necessary
49
+ b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
50
+ const jsonText = atob(b64);
51
+ return JSON.parse(jsonText);
52
+ }
53
+
54
+ function getDefaultExportFromCjs (x) {
55
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
56
+ }
57
+
58
+ function assertPath(path) {
59
+ if (typeof path !== 'string') {
60
+ throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
61
+ }
62
+ }
63
+
64
+ // Resolves . and .. elements in a path with directory names
65
+ function normalizeStringPosix(path, allowAboveRoot) {
66
+ var res = '';
67
+ var lastSegmentLength = 0;
68
+ var lastSlash = -1;
69
+ var dots = 0;
70
+ var code;
71
+ for (var i = 0; i <= path.length; ++i) {
72
+ if (i < path.length)
73
+ code = path.charCodeAt(i);
74
+ else if (code === 47 /*/*/)
75
+ break;
76
+ else
77
+ code = 47 /*/*/;
78
+ if (code === 47 /*/*/) {
79
+ if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
80
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
81
+ if (res.length > 2) {
82
+ var lastSlashIndex = res.lastIndexOf('/');
83
+ if (lastSlashIndex !== res.length - 1) {
84
+ if (lastSlashIndex === -1) {
85
+ res = '';
86
+ lastSegmentLength = 0;
87
+ } else {
88
+ res = res.slice(0, lastSlashIndex);
89
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
90
+ }
91
+ lastSlash = i;
92
+ dots = 0;
93
+ continue;
94
+ }
95
+ } else if (res.length === 2 || res.length === 1) {
96
+ res = '';
97
+ lastSegmentLength = 0;
98
+ lastSlash = i;
99
+ dots = 0;
100
+ continue;
101
+ }
102
+ }
103
+ if (allowAboveRoot) {
104
+ if (res.length > 0)
105
+ res += '/..';
106
+ else
107
+ res = '..';
108
+ lastSegmentLength = 2;
109
+ }
110
+ } else {
111
+ if (res.length > 0)
112
+ res += '/' + path.slice(lastSlash + 1, i);
113
+ else
114
+ res = path.slice(lastSlash + 1, i);
115
+ lastSegmentLength = i - lastSlash - 1;
116
+ }
117
+ lastSlash = i;
118
+ dots = 0;
119
+ } else if (code === 46 /*.*/ && dots !== -1) {
120
+ ++dots;
121
+ } else {
122
+ dots = -1;
123
+ }
124
+ }
125
+ return res;
126
+ }
127
+
128
+ function _format(sep, pathObject) {
129
+ var dir = pathObject.dir || pathObject.root;
130
+ var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
131
+ if (!dir) {
132
+ return base;
133
+ }
134
+ if (dir === pathObject.root) {
135
+ return dir + base;
136
+ }
137
+ return dir + sep + base;
138
+ }
139
+
140
+ var posix = {
141
+ // path.resolve([from ...], to)
142
+ resolve: function resolve() {
143
+ var resolvedPath = '';
144
+ var resolvedAbsolute = false;
145
+ var cwd;
146
+
147
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
148
+ var path;
149
+ if (i >= 0)
150
+ path = arguments[i];
151
+ else {
152
+ if (cwd === undefined)
153
+ cwd = process.cwd();
154
+ path = cwd;
155
+ }
156
+
157
+ assertPath(path);
158
+
159
+ // Skip empty entries
160
+ if (path.length === 0) {
161
+ continue;
162
+ }
163
+
164
+ resolvedPath = path + '/' + resolvedPath;
165
+ resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
166
+ }
167
+
168
+ // At this point the path should be resolved to a full absolute path, but
169
+ // handle relative paths to be safe (might happen when process.cwd() fails)
170
+
171
+ // Normalize the path
172
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
173
+
174
+ if (resolvedAbsolute) {
175
+ if (resolvedPath.length > 0)
176
+ return '/' + resolvedPath;
177
+ else
178
+ return '/';
179
+ } else if (resolvedPath.length > 0) {
180
+ return resolvedPath;
181
+ } else {
182
+ return '.';
183
+ }
184
+ },
185
+
186
+ normalize: function normalize(path) {
187
+ assertPath(path);
188
+
189
+ if (path.length === 0) return '.';
190
+
191
+ var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
192
+ var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
193
+
194
+ // Normalize the path
195
+ path = normalizeStringPosix(path, !isAbsolute);
196
+
197
+ if (path.length === 0 && !isAbsolute) path = '.';
198
+ if (path.length > 0 && trailingSeparator) path += '/';
199
+
200
+ if (isAbsolute) return '/' + path;
201
+ return path;
202
+ },
203
+
204
+ isAbsolute: function isAbsolute(path) {
205
+ assertPath(path);
206
+ return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
207
+ },
208
+
209
+ join: function join() {
210
+ if (arguments.length === 0)
211
+ return '.';
212
+ var joined;
213
+ for (var i = 0; i < arguments.length; ++i) {
214
+ var arg = arguments[i];
215
+ assertPath(arg);
216
+ if (arg.length > 0) {
217
+ if (joined === undefined)
218
+ joined = arg;
219
+ else
220
+ joined += '/' + arg;
221
+ }
222
+ }
223
+ if (joined === undefined)
224
+ return '.';
225
+ return posix.normalize(joined);
226
+ },
227
+
228
+ relative: function relative(from, to) {
229
+ assertPath(from);
230
+ assertPath(to);
231
+
232
+ if (from === to) return '';
233
+
234
+ from = posix.resolve(from);
235
+ to = posix.resolve(to);
236
+
237
+ if (from === to) return '';
238
+
239
+ // Trim any leading backslashes
240
+ var fromStart = 1;
241
+ for (; fromStart < from.length; ++fromStart) {
242
+ if (from.charCodeAt(fromStart) !== 47 /*/*/)
243
+ break;
244
+ }
245
+ var fromEnd = from.length;
246
+ var fromLen = fromEnd - fromStart;
247
+
248
+ // Trim any leading backslashes
249
+ var toStart = 1;
250
+ for (; toStart < to.length; ++toStart) {
251
+ if (to.charCodeAt(toStart) !== 47 /*/*/)
252
+ break;
253
+ }
254
+ var toEnd = to.length;
255
+ var toLen = toEnd - toStart;
256
+
257
+ // Compare paths to find the longest common path from root
258
+ var length = fromLen < toLen ? fromLen : toLen;
259
+ var lastCommonSep = -1;
260
+ var i = 0;
261
+ for (; i <= length; ++i) {
262
+ if (i === length) {
263
+ if (toLen > length) {
264
+ if (to.charCodeAt(toStart + i) === 47 /*/*/) {
265
+ // We get here if `from` is the exact base path for `to`.
266
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
267
+ return to.slice(toStart + i + 1);
268
+ } else if (i === 0) {
269
+ // We get here if `from` is the root
270
+ // For example: from='/'; to='/foo'
271
+ return to.slice(toStart + i);
272
+ }
273
+ } else if (fromLen > length) {
274
+ if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
275
+ // We get here if `to` is the exact base path for `from`.
276
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
277
+ lastCommonSep = i;
278
+ } else if (i === 0) {
279
+ // We get here if `to` is the root.
280
+ // For example: from='/foo'; to='/'
281
+ lastCommonSep = 0;
282
+ }
283
+ }
284
+ break;
285
+ }
286
+ var fromCode = from.charCodeAt(fromStart + i);
287
+ var toCode = to.charCodeAt(toStart + i);
288
+ if (fromCode !== toCode)
289
+ break;
290
+ else if (fromCode === 47 /*/*/)
291
+ lastCommonSep = i;
292
+ }
293
+
294
+ var out = '';
295
+ // Generate the relative path based on the path difference between `to`
296
+ // and `from`
297
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
298
+ if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
299
+ if (out.length === 0)
300
+ out += '..';
301
+ else
302
+ out += '/..';
303
+ }
304
+ }
305
+
306
+ // Lastly, append the rest of the destination (`to`) path that comes after
307
+ // the common path parts
308
+ if (out.length > 0)
309
+ return out + to.slice(toStart + lastCommonSep);
310
+ else {
311
+ toStart += lastCommonSep;
312
+ if (to.charCodeAt(toStart) === 47 /*/*/)
313
+ ++toStart;
314
+ return to.slice(toStart);
315
+ }
316
+ },
317
+
318
+ _makeLong: function _makeLong(path) {
319
+ return path;
320
+ },
321
+
322
+ dirname: function dirname(path) {
323
+ assertPath(path);
324
+ if (path.length === 0) return '.';
325
+ var code = path.charCodeAt(0);
326
+ var hasRoot = code === 47 /*/*/;
327
+ var end = -1;
328
+ var matchedSlash = true;
329
+ for (var i = path.length - 1; i >= 1; --i) {
330
+ code = path.charCodeAt(i);
331
+ if (code === 47 /*/*/) {
332
+ if (!matchedSlash) {
333
+ end = i;
334
+ break;
335
+ }
336
+ } else {
337
+ // We saw the first non-path separator
338
+ matchedSlash = false;
339
+ }
340
+ }
341
+
342
+ if (end === -1) return hasRoot ? '/' : '.';
343
+ if (hasRoot && end === 1) return '//';
344
+ return path.slice(0, end);
345
+ },
346
+
347
+ basename: function basename(path, ext) {
348
+ if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
349
+ assertPath(path);
350
+
351
+ var start = 0;
352
+ var end = -1;
353
+ var matchedSlash = true;
354
+ var i;
355
+
356
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
357
+ if (ext.length === path.length && ext === path) return '';
358
+ var extIdx = ext.length - 1;
359
+ var firstNonSlashEnd = -1;
360
+ for (i = path.length - 1; i >= 0; --i) {
361
+ var code = path.charCodeAt(i);
362
+ if (code === 47 /*/*/) {
363
+ // If we reached a path separator that was not part of a set of path
364
+ // separators at the end of the string, stop now
365
+ if (!matchedSlash) {
366
+ start = i + 1;
367
+ break;
368
+ }
369
+ } else {
370
+ if (firstNonSlashEnd === -1) {
371
+ // We saw the first non-path separator, remember this index in case
372
+ // we need it if the extension ends up not matching
373
+ matchedSlash = false;
374
+ firstNonSlashEnd = i + 1;
375
+ }
376
+ if (extIdx >= 0) {
377
+ // Try to match the explicit extension
378
+ if (code === ext.charCodeAt(extIdx)) {
379
+ if (--extIdx === -1) {
380
+ // We matched the extension, so mark this as the end of our path
381
+ // component
382
+ end = i;
383
+ }
384
+ } else {
385
+ // Extension does not match, so our result is the entire path
386
+ // component
387
+ extIdx = -1;
388
+ end = firstNonSlashEnd;
389
+ }
390
+ }
391
+ }
392
+ }
393
+
394
+ if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
395
+ return path.slice(start, end);
396
+ } else {
397
+ for (i = path.length - 1; i >= 0; --i) {
398
+ if (path.charCodeAt(i) === 47 /*/*/) {
399
+ // If we reached a path separator that was not part of a set of path
400
+ // separators at the end of the string, stop now
401
+ if (!matchedSlash) {
402
+ start = i + 1;
403
+ break;
404
+ }
405
+ } else if (end === -1) {
406
+ // We saw the first non-path separator, mark this as the end of our
407
+ // path component
408
+ matchedSlash = false;
409
+ end = i + 1;
410
+ }
411
+ }
412
+
413
+ if (end === -1) return '';
414
+ return path.slice(start, end);
415
+ }
416
+ },
417
+
418
+ extname: function extname(path) {
419
+ assertPath(path);
420
+ var startDot = -1;
421
+ var startPart = 0;
422
+ var end = -1;
423
+ var matchedSlash = true;
424
+ // Track the state of characters (if any) we see before our first dot and
425
+ // after any path separator we find
426
+ var preDotState = 0;
427
+ for (var i = path.length - 1; i >= 0; --i) {
428
+ var code = path.charCodeAt(i);
429
+ if (code === 47 /*/*/) {
430
+ // If we reached a path separator that was not part of a set of path
431
+ // separators at the end of the string, stop now
432
+ if (!matchedSlash) {
433
+ startPart = i + 1;
434
+ break;
435
+ }
436
+ continue;
437
+ }
438
+ if (end === -1) {
439
+ // We saw the first non-path separator, mark this as the end of our
440
+ // extension
441
+ matchedSlash = false;
442
+ end = i + 1;
443
+ }
444
+ if (code === 46 /*.*/) {
445
+ // If this is our first dot, mark it as the start of our extension
446
+ if (startDot === -1)
447
+ startDot = i;
448
+ else if (preDotState !== 1)
449
+ preDotState = 1;
450
+ } else if (startDot !== -1) {
451
+ // We saw a non-dot and non-path separator before our dot, so we should
452
+ // have a good chance at having a non-empty extension
453
+ preDotState = -1;
454
+ }
455
+ }
456
+
457
+ if (startDot === -1 || end === -1 ||
458
+ // We saw a non-dot character immediately before the dot
459
+ preDotState === 0 ||
460
+ // The (right-most) trimmed path component is exactly '..'
461
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
462
+ return '';
463
+ }
464
+ return path.slice(startDot, end);
465
+ },
466
+
467
+ format: function format(pathObject) {
468
+ if (pathObject === null || typeof pathObject !== 'object') {
469
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
470
+ }
471
+ return _format('/', pathObject);
472
+ },
473
+
474
+ parse: function parse(path) {
475
+ assertPath(path);
476
+
477
+ var ret = { root: '', dir: '', base: '', ext: '', name: '' };
478
+ if (path.length === 0) return ret;
479
+ var code = path.charCodeAt(0);
480
+ var isAbsolute = code === 47 /*/*/;
481
+ var start;
482
+ if (isAbsolute) {
483
+ ret.root = '/';
484
+ start = 1;
485
+ } else {
486
+ start = 0;
487
+ }
488
+ var startDot = -1;
489
+ var startPart = 0;
490
+ var end = -1;
491
+ var matchedSlash = true;
492
+ var i = path.length - 1;
493
+
494
+ // Track the state of characters (if any) we see before our first dot and
495
+ // after any path separator we find
496
+ var preDotState = 0;
497
+
498
+ // Get non-dir info
499
+ for (; i >= start; --i) {
500
+ code = path.charCodeAt(i);
501
+ if (code === 47 /*/*/) {
502
+ // If we reached a path separator that was not part of a set of path
503
+ // separators at the end of the string, stop now
504
+ if (!matchedSlash) {
505
+ startPart = i + 1;
506
+ break;
507
+ }
508
+ continue;
509
+ }
510
+ if (end === -1) {
511
+ // We saw the first non-path separator, mark this as the end of our
512
+ // extension
513
+ matchedSlash = false;
514
+ end = i + 1;
515
+ }
516
+ if (code === 46 /*.*/) {
517
+ // If this is our first dot, mark it as the start of our extension
518
+ if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
519
+ } else if (startDot !== -1) {
520
+ // We saw a non-dot and non-path separator before our dot, so we should
521
+ // have a good chance at having a non-empty extension
522
+ preDotState = -1;
523
+ }
524
+ }
525
+
526
+ if (startDot === -1 || end === -1 ||
527
+ // We saw a non-dot character immediately before the dot
528
+ preDotState === 0 ||
529
+ // The (right-most) trimmed path component is exactly '..'
530
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
531
+ if (end !== -1) {
532
+ if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
533
+ }
534
+ } else {
535
+ if (startPart === 0 && isAbsolute) {
536
+ ret.name = path.slice(1, startDot);
537
+ ret.base = path.slice(1, end);
538
+ } else {
539
+ ret.name = path.slice(startPart, startDot);
540
+ ret.base = path.slice(startPart, end);
541
+ }
542
+ ret.ext = path.slice(startDot, end);
543
+ }
544
+
545
+ if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
546
+
547
+ return ret;
548
+ },
549
+
550
+ sep: '/',
551
+ delimiter: ':',
552
+ win32: null,
553
+ posix: null
554
+ };
555
+
556
+ posix.posix = posix;
557
+
558
+ var pathBrowserify = posix;
559
+
560
+ var path = /*@__PURE__*/getDefaultExportFromCjs(pathBrowserify);
561
+
562
+ // mediaTypes.ts
563
+ /** ---- Data: large but explicit, mirrors your Python mapping ---- */
564
+ const MIME_TYPES = {
565
+ image: {
566
+ ".jpg": "image/jpeg",
567
+ ".jpeg": "image/jpeg",
568
+ ".png": "image/png",
569
+ ".gif": "image/gif",
570
+ ".bmp": "image/bmp",
571
+ ".tiff": "image/tiff",
572
+ ".webp": "image/webp",
573
+ ".svg": "image/svg+xml",
574
+ ".ico": "image/vnd.microsoft.icon",
575
+ ".heic": "image/heic",
576
+ ".psd": "image/vnd.adobe.photoshop",
577
+ ".raw": "image/x-raw",
578
+ },
579
+ video: {
580
+ ".mp4": "video/mp4",
581
+ ".webm": "video/webm",
582
+ ".ogg": "video/ogg",
583
+ ".mov": "video/quicktime",
584
+ ".avi": "video/x-msvideo",
585
+ ".mkv": "video/x-matroska",
586
+ ".flv": "video/x-flv",
587
+ ".wmv": "video/x-ms-wmv",
588
+ ".3gp": "video/3gpp",
589
+ ".ts": "video/mp2t",
590
+ ".mpeg": "video/mpeg",
591
+ ".mpg": "video/mpg",
592
+ },
593
+ audio: {
594
+ ".mp3": "audio/mpeg",
595
+ ".wav": "audio/wav",
596
+ ".flac": "audio/flac",
597
+ ".aac": "audio/aac",
598
+ ".ogg": "audio/ogg",
599
+ ".m4a": "audio/mp4",
600
+ ".opus": "audio/opus",
601
+ },
602
+ document: {
603
+ ".pdf": "application/pdf",
604
+ ".doc": "application/msword",
605
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
606
+ ".odt": "application/vnd.oasis.opendocument.text",
607
+ ".txt": "text/plain",
608
+ ".rtf": "application/rtf",
609
+ ".md": "text/markdown",
610
+ ".markdown": "text/markdown",
611
+ ".tex": "application/x-tex",
612
+ ".log": "text/plain",
613
+ ".json": "application/json",
614
+ ".xml": "application/xml",
615
+ ".yaml": "application/x-yaml",
616
+ ".yml": "application/x-yaml",
617
+ ".ini": "text/plain",
618
+ ".cfg": "text/plain",
619
+ ".toml": "application/toml",
620
+ ".csv": "text/csv",
621
+ ".tsv": "text/tab-separated-values",
622
+ },
623
+ presentation: {
624
+ ".ppt": "application/vnd.ms-powerpoint",
625
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
626
+ ".odp": "application/vnd.oasis.opendocument.presentation",
627
+ },
628
+ spreadsheet: {
629
+ ".xls": "application/vnd.ms-excel",
630
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
631
+ ".ods": "application/vnd.oasis.opendocument.spreadsheet",
632
+ ".csv": "text/csv",
633
+ ".tsv": "text/tab-separated-values",
634
+ },
635
+ code: {
636
+ ".py": "text/x-python",
637
+ ".java": "text/x-java-source",
638
+ ".c": "text/x-c",
639
+ ".cpp": "text/x-c++",
640
+ ".h": "text/x-c",
641
+ ".hpp": "text/x-c++",
642
+ ".js": "application/javascript",
643
+ ".cjs": "application/javascript",
644
+ ".mjs": "application/javascript",
645
+ ".jsx": "application/javascript",
646
+ ".ts": "application/typescript",
647
+ ".tsx": "application/typescript",
648
+ ".rb": "text/x-ruby",
649
+ ".php": "application/x-php",
650
+ ".go": "text/x-go",
651
+ ".rs": "text/rust",
652
+ ".swift": "text/x-swift",
653
+ ".kt": "text/x-kotlin",
654
+ ".sh": "application/x-shellscript",
655
+ ".bash": "application/x-shellscript",
656
+ ".ps1": "application/x-powershell",
657
+ ".sql": "application/sql",
658
+ ".yml": "application/x-yaml",
659
+ ".coffee": "text/coffeescript",
660
+ ".lua": "text/x-lua",
661
+ },
662
+ archive: {
663
+ ".zip": "application/zip",
664
+ ".tar": "application/x-tar",
665
+ ".gz": "application/gzip",
666
+ ".tgz": "application/gzip",
667
+ ".bz2": "application/x-bzip2",
668
+ ".xz": "application/x-xz",
669
+ ".rar": "application/vnd.rar",
670
+ ".7z": "application/x-7z-compressed",
671
+ ".iso": "application/x-iso9660-image",
672
+ ".dmg": "application/x-apple-diskimage",
673
+ ".jar": "application/java-archive",
674
+ ".war": "application/java-archive",
675
+ ".whl": "application/python-wheel",
676
+ ".egg": "application/python-egg",
677
+ },
678
+ font: {
679
+ ".ttf": "font/ttf",
680
+ ".otf": "font/otf",
681
+ ".woff": "font/woff",
682
+ ".woff2": "font/woff2",
683
+ ".eot": "application/vnd.ms-fontobject",
684
+ },
685
+ executable: {
686
+ ".exe": "application/vnd.microsoft.portable-executable",
687
+ ".dll": "application/vnd.microsoft.portable-executable",
688
+ ".bin": "application/octet-stream",
689
+ ".deb": "application/vnd.debian.binary-package",
690
+ ".rpm": "application/x-rpm",
691
+ },
692
+ };
693
+ /** Mirror of MEDIA_TYPES in Python: category -> Set of extensions */
694
+ const MEDIA_TYPES = Object.fromEntries(Object.entries(MIME_TYPES).map(([cat, mapping]) => [
695
+ cat,
696
+ new Set(Object.keys(mapping)),
697
+ ]));
698
+ /** ---- Helpers ---- */
699
+ function toCategorySet(categories) {
700
+ const allCats = new Set(Object.keys(MIME_TYPES));
701
+ if (!categories) {
702
+ // all categories
703
+ return new Set(allCats);
704
+ }
705
+ const out = new Set();
706
+ for (const c of categories) {
707
+ const key = String(c);
708
+ if (allCats.has(key))
709
+ out.add(key);
710
+ }
711
+ return out.size ? out : new Set(allCats);
712
+ }
713
+ function normalizeCategories(categories, opts) {
714
+ const selected = categories ?? opts?.media_types ?? null;
715
+ return toCategorySet(selected);
716
+ }
717
+ function extOf(input) {
718
+ // Behaves like pathlib.Path(...).suffix.lower(): last extension only; lowercased.
719
+ let ext = path__namespace.extname(input || "");
720
+ if (!ext && input && input.startsWith(".")) {
721
+ // user passed ".jpg" directly
722
+ ext = input;
723
+ }
724
+ return (ext || "").toLowerCase();
725
+ }
726
+ function unionExts(categories) {
727
+ const out = new Set();
728
+ for (const c of categories) {
729
+ const set = MEDIA_TYPES[c];
730
+ for (const e of set)
731
+ out.add(e);
732
+ }
733
+ return out;
734
+ }
735
+ /** ---- API (Python parity) ---- */
736
+ /**
737
+ * Return a sub-map of MEDIA_TYPES for the given categories.
738
+ * If categories is falsy, returns all categories.
739
+ */
740
+ function getMediaMap(categories, opts) {
741
+ const cats = normalizeCategories(categories, opts);
742
+ const result = {};
743
+ for (const c of cats)
744
+ result[c] = new Set(MEDIA_TYPES[c]);
745
+ return result;
746
+ }
747
+ /**
748
+ * Return a flat, sorted list of all extensions for the given categories.
749
+ */
750
+ function getMediaExts(categories, opts) {
751
+ const cats = normalizeCategories(categories, opts);
752
+ return Array.from(unionExts(cats)).sort();
753
+ }
754
+ /**
755
+ * Given a file path or extension, return its media category (e.g. "image") or null.
756
+ * Mirrors Python's confirm_type.
757
+ */
758
+ function confirmType(pathOrExt, categories, opts) {
759
+ const cats = normalizeCategories(categories, opts);
760
+ const ext = extOf(pathOrExt);
761
+ // Preserve object insertion order like Python dict iteration
762
+ for (const [category, exts] of Object.entries(MEDIA_TYPES)) {
763
+ if (!cats.has(category))
764
+ continue;
765
+ if (ext && exts.has(ext))
766
+ return category;
767
+ }
768
+ return null;
769
+ }
770
+ /**
771
+ * True if the given file path or extension belongs to one of the categories.
772
+ */
773
+ function isMediaType(pathOrExt, categories, opts) {
774
+ return confirmType(pathOrExt, categories, opts) !== null;
775
+ }
776
+ /**
777
+ * Look up the MIME type by extension; fall back to 'application/octet-stream'.
778
+ */
779
+ function getMimeType(pathOrExt) {
780
+ const ext = extOf(pathOrExt);
781
+ for (const mapping of Object.values(MIME_TYPES)) {
782
+ if (ext && mapping[ext]) {
783
+ return mapping[ext];
784
+ }
785
+ }
786
+ return "application/octet-stream";
787
+ }
788
+ function getAllFileTypesSync(directory, categories, opts) {
789
+ // 🧩 Skip entirely if fs isn't available
790
+ if (!fs__namespace || !path__namespace)
791
+ return [];
792
+ try {
793
+ const stat = fs__namespace.statSync(directory);
794
+ if (!stat.isDirectory())
795
+ return [];
796
+ const cats = normalizeCategories(categories, opts);
797
+ const wanted = unionExts(cats);
798
+ const results = [];
799
+ function walkSync(dir) {
800
+ const entries = fs__namespace.readdirSync(dir, { withFileTypes: true });
801
+ for (const ent of entries) {
802
+ const full = path__namespace.join(dir, ent.name);
803
+ if (ent.isDirectory()) {
804
+ walkSync(full);
805
+ }
806
+ else if (ent.isFile()) {
807
+ const ext = path__namespace.extname(ent.name).toLowerCase();
808
+ if (wanted.has(ext))
809
+ results.push(full);
810
+ }
811
+ }
812
+ }
813
+ walkSync(directory);
814
+ return results;
815
+ }
816
+ catch {
817
+ return [];
818
+ }
819
+ }
820
+ async function getAllFileTypes(directory, categories, opts) {
821
+ // 🧩 Skip entirely if fsp isn't available
822
+ if (!fsp__namespace || !path__namespace)
823
+ return [];
824
+ try {
825
+ const stat = await fsp__namespace.stat(directory);
826
+ if (!stat.isDirectory())
827
+ return [];
828
+ const cats = normalizeCategories(categories, opts);
829
+ const wanted = unionExts(cats);
830
+ const results = [];
831
+ async function walkAsync(dir) {
832
+ const entries = await fsp__namespace.readdir(dir, { withFileTypes: true });
833
+ for (const ent of entries) {
834
+ const full = path__namespace.join(dir, ent.name);
835
+ if (ent.isDirectory()) {
836
+ await walkAsync(full);
837
+ }
838
+ else if (ent.isFile()) {
839
+ const ext = path__namespace.extname(ent.name).toLowerCase();
840
+ if (wanted.has(ext))
841
+ results.push(full);
842
+ }
843
+ }
844
+ }
845
+ await walkAsync(directory);
846
+ return results;
847
+ }
848
+ catch {
849
+ return [];
850
+ }
851
+ }
852
+ /** Optional convenience re-exports that mirror your Python names */
853
+ const get_all_file_types = getAllFileTypes;
854
+ const get_media_map = getMediaMap;
855
+ const get_media_exts = getMediaExts;
856
+ const confirm_type = confirmType;
857
+ const is_media_type = isMediaType;
858
+ const get_mime_type = getMimeType;
859
+
860
+ /**
861
+ * Safely walk `globalThis` (or window/document) by a chain of property names.
862
+ * Returns `undefined` if any step is missing.
863
+ */
864
+ function safeGlobalProp(...path) {
865
+ let obj = globalThis;
866
+ for (const key of path) {
867
+ if (obj == null || typeof obj !== "object" || !(key in obj)) {
868
+ return undefined;
869
+ }
870
+ obj = obj[key];
871
+ }
872
+ return obj;
873
+ }
874
+
875
+ /**
876
+ * Returns `window` if running in a browser, otherwise `undefined`.
877
+ */
878
+ function getSafeLocalStorage() {
879
+ if (typeof window === 'undefined')
880
+ return undefined;
881
+ try {
882
+ return window.localStorage;
883
+ }
884
+ catch {
885
+ return undefined; // e.g. Safari private-mode block
886
+ }
887
+ }
888
+ /**
889
+ * Call a Storage method by name, silencing any errors or missing storage.
890
+ *
891
+ * @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
892
+ * @param args The arguments you’d normally pass to that method.
893
+ * @returns The method’s return value, or undefined if storage/method isn’t available.
894
+ */
895
+ function callStorage(method, ...args) {
896
+ const storage = getSafeLocalStorage();
897
+ if (!storage)
898
+ return undefined;
899
+ const fn = storage[method];
900
+ if (typeof fn !== 'function')
901
+ return undefined;
902
+ try {
903
+ return fn.apply(storage, args);
904
+ }
905
+ catch {
906
+ return undefined;
907
+ }
908
+ }
909
+ /**
910
+ * Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
911
+ * Returns `undefined` on any error.
912
+ */
913
+ function safeStorage(storageName, method, ...args) {
914
+ try {
915
+ const store = safeGlobalProp(storageName);
916
+ if (!store || typeof store[method] !== "function")
917
+ return undefined;
918
+ return store[method](...args);
919
+ }
920
+ catch {
921
+ return undefined;
922
+ }
923
+ }
924
+
925
+ exports.MEDIA_TYPES = MEDIA_TYPES;
926
+ exports.MIME_TYPES = MIME_TYPES;
927
+ exports.callStorage = callStorage;
928
+ exports.confirmType = confirmType;
929
+ exports.confirm_type = confirm_type;
930
+ exports.decodeJwt = decodeJwt;
931
+ exports.getAllFileTypes = getAllFileTypes;
932
+ exports.getAllFileTypesSync = getAllFileTypesSync;
933
+ exports.getMediaExts = getMediaExts;
934
+ exports.getMediaMap = getMediaMap;
935
+ exports.getMimeType = getMimeType;
936
+ exports.getSafeLocalStorage = getSafeLocalStorage;
937
+ exports.get_all_file_types = get_all_file_types;
938
+ exports.get_media_exts = get_media_exts;
939
+ exports.get_media_map = get_media_map;
940
+ exports.get_mime_type = get_mime_type;
941
+ exports.isMediaType = isMediaType;
942
+ exports.isTokenExpired = isTokenExpired;
943
+ exports.is_media_type = is_media_type;
944
+ exports.path = path;
945
+ exports.safeGlobalProp = safeGlobalProp;
946
+ exports.safeStorage = safeStorage;
947
+ //# sourceMappingURL=safe_storage-BSCV5flZ.js.map