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