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