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