@putkoff/abstract-utilities 1.0.103 → 1.0.124

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