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