@putkoff/abstract-utilities 1.0.134 → 1.0.139

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