@putkoff/abstract-utilities 0.1.216 → 0.1.219
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/index.cjs +5877 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +5762 -0
- package/dist/index.js.map +1 -0
- package/dist/types/functions/path_utils/src/path_utils.browser.d.ts +2 -0
- package/dist/types/functions/path_utils/src/path_utils.node.d.ts +2 -0
- package/dist/types/functions/read_utils/src/read_utils.browser.d.ts +1 -0
- package/dist/types/functions/read_utils/src/utils.browser.d.ts +3 -0
- package/package.json +19 -7
- package/dist/cjs/index.js +0 -1744
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/index.js +0 -1613
- package/dist/esm/index.js.map +0 -1
- package/dist/index.d.ts +0 -378
package/dist/esm/index.js
DELETED
|
@@ -1,1613 +0,0 @@
|
|
|
1
|
-
export { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
function getSafeDocument() {
|
|
5
|
-
return typeof document !== 'undefined' ? document : undefined;
|
|
6
|
-
}
|
|
7
|
-
function getDocumentProp(...keys) {
|
|
8
|
-
let obj = getSafeDocument();
|
|
9
|
-
for (const k of keys) {
|
|
10
|
-
if (obj == null || typeof obj !== 'object')
|
|
11
|
-
return undefined;
|
|
12
|
-
obj = obj[k];
|
|
13
|
-
}
|
|
14
|
-
return obj;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
19
|
-
* Returns `undefined` if any step is missing.
|
|
20
|
-
*/
|
|
21
|
-
function safeGlobalProp(...path) {
|
|
22
|
-
let obj = globalThis;
|
|
23
|
-
for (const key of path) {
|
|
24
|
-
if (obj == null || typeof obj !== "object" || !(key in obj)) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
obj = obj[key];
|
|
28
|
-
}
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns `window` if running in a browser, otherwise `undefined`.
|
|
34
|
-
*/
|
|
35
|
-
function getSafeLocalStorage() {
|
|
36
|
-
if (typeof window === 'undefined')
|
|
37
|
-
return undefined;
|
|
38
|
-
try {
|
|
39
|
-
return window.localStorage;
|
|
40
|
-
}
|
|
41
|
-
catch (_a) {
|
|
42
|
-
return undefined; // e.g. Safari private-mode block
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Call a Storage method by name, silencing any errors or missing storage.
|
|
47
|
-
*
|
|
48
|
-
* @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
|
|
49
|
-
* @param args The arguments you’d normally pass to that method.
|
|
50
|
-
* @returns The method’s return value, or undefined if storage/method isn’t available.
|
|
51
|
-
*/
|
|
52
|
-
function callStorage(method, ...args) {
|
|
53
|
-
const storage = getSafeLocalStorage();
|
|
54
|
-
if (!storage)
|
|
55
|
-
return undefined;
|
|
56
|
-
const fn = storage[method];
|
|
57
|
-
if (typeof fn !== 'function')
|
|
58
|
-
return undefined;
|
|
59
|
-
try {
|
|
60
|
-
// @ts-ignore – TS can’t infer that this is callable
|
|
61
|
-
return fn.apply(storage, args);
|
|
62
|
-
}
|
|
63
|
-
catch (_a) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
|
|
69
|
-
* Returns `undefined` on any error.
|
|
70
|
-
*/
|
|
71
|
-
function safeStorage(storageName, method, ...args) {
|
|
72
|
-
try {
|
|
73
|
-
const store = safeGlobalProp(storageName);
|
|
74
|
-
if (!store || typeof store[method] !== "function")
|
|
75
|
-
return undefined;
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
return store[method](...args);
|
|
78
|
-
}
|
|
79
|
-
catch (_a) {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Returns the global window object if it exists, otherwise undefined.
|
|
86
|
-
*/
|
|
87
|
-
function getSafeWindow() {
|
|
88
|
-
return typeof window !== 'undefined' ? window : undefined;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Safely call a method on window by name.
|
|
92
|
-
*
|
|
93
|
-
* @param method The Window method to call (e.g. "alert", "open", etc.).
|
|
94
|
-
* @param args Arguments to pass to that method.
|
|
95
|
-
* @returns The method’s return value, or undefined if
|
|
96
|
-
* window/method isn’t available or throws.
|
|
97
|
-
*/
|
|
98
|
-
function callWindowMethod(method, ...args) {
|
|
99
|
-
const w = getSafeWindow();
|
|
100
|
-
if (!w)
|
|
101
|
-
return undefined;
|
|
102
|
-
const fn = w[method];
|
|
103
|
-
if (typeof fn !== 'function')
|
|
104
|
-
return undefined;
|
|
105
|
-
try {
|
|
106
|
-
// cast to any so TS doesn’t complain about apply/invoke
|
|
107
|
-
return fn(...args);
|
|
108
|
-
}
|
|
109
|
-
catch (_a) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/** implementation */
|
|
114
|
-
function getWindowProp(...keys) {
|
|
115
|
-
let obj = getSafeWindow();
|
|
116
|
-
for (const k of keys) {
|
|
117
|
-
if (obj == null || typeof obj !== 'object')
|
|
118
|
-
return undefined;
|
|
119
|
-
obj = obj[k];
|
|
120
|
-
}
|
|
121
|
-
return obj;
|
|
122
|
-
}
|
|
123
|
-
function getWindowHost() {
|
|
124
|
-
return getWindowProp('location', 'host');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
***Changes**:
|
|
129
|
-
*- Updated import path for `InputProps` to `../../types/interfaces`.
|
|
130
|
-
*
|
|
131
|
-
*3. **Token Utilities** (`src/functions/auth/token_utils.ts`):
|
|
132
|
-
* Copy from `/var/www/abstractendeavors/my-login-app/src/functions/auth_utils/token_utils.ts`.
|
|
133
|
-
*
|
|
134
|
-
*/
|
|
135
|
-
/** Read raw JWT from LocalStorage (or null if absent) */
|
|
136
|
-
function getToken() {
|
|
137
|
-
return callStorage('getItem', 'token');
|
|
138
|
-
}
|
|
139
|
-
function isLoggedIn() {
|
|
140
|
-
const tok = getToken();
|
|
141
|
-
return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
|
|
142
|
-
}
|
|
143
|
-
function removeToken() {
|
|
144
|
-
let is_logged = isLoggedIn();
|
|
145
|
-
if (is_logged) {
|
|
146
|
-
callStorage('removeItem', "token");
|
|
147
|
-
}
|
|
148
|
-
is_logged = isLoggedIn();
|
|
149
|
-
if (is_logged) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Add a Bearer Authorization header.
|
|
156
|
-
* A shallow copy of headers is returned so callers can keep chaining.
|
|
157
|
-
*/
|
|
158
|
-
function getAuthorizationHeader(headers = {}, token = null) {
|
|
159
|
-
token = token !== null && token !== void 0 ? token : getToken();
|
|
160
|
-
headers = headers || {};
|
|
161
|
-
if (token)
|
|
162
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
163
|
-
return Object.assign({}, headers);
|
|
164
|
-
}
|
|
165
|
-
/** Throw + redirect if there’s no valid token; otherwise return it. */
|
|
166
|
-
function requireToken() {
|
|
167
|
-
const tok = getToken();
|
|
168
|
-
if (!tok || isTokenExpired(tok)) {
|
|
169
|
-
console.warn("→ No token or expired token, redirecting to login…");
|
|
170
|
-
removeToken();
|
|
171
|
-
window.location.href = '/';
|
|
172
|
-
throw new Error("Redirecting to login…");
|
|
173
|
-
}
|
|
174
|
-
return tok;
|
|
175
|
-
}
|
|
176
|
-
/** True if token is structurally bad or its exp ≤ now. */
|
|
177
|
-
function isTokenExpired(token) {
|
|
178
|
-
try {
|
|
179
|
-
const payload = decodeJwt(token);
|
|
180
|
-
return Date.now() / 1000 >= payload.exp;
|
|
181
|
-
}
|
|
182
|
-
catch (_a) {
|
|
183
|
-
return true; // treat malformed token as expired
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
/** Convenience wrapper: return username from the JWT (or null). */
|
|
187
|
-
function currentUsername() {
|
|
188
|
-
const token = getToken();
|
|
189
|
-
let uName = null;
|
|
190
|
-
if (token) {
|
|
191
|
-
const decodedJwt = decodeJwt(token) || {};
|
|
192
|
-
uName = (decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.username) || null;
|
|
193
|
-
}
|
|
194
|
-
return uName;
|
|
195
|
-
}
|
|
196
|
-
function currentUsernames() {
|
|
197
|
-
var _a;
|
|
198
|
-
const tok = getToken();
|
|
199
|
-
if (!tok)
|
|
200
|
-
return null;
|
|
201
|
-
try {
|
|
202
|
-
const parts = tok.split(".");
|
|
203
|
-
if (parts.length !== 3)
|
|
204
|
-
return null;
|
|
205
|
-
let b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
206
|
-
b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
|
|
207
|
-
const jsonText = atob(b64);
|
|
208
|
-
const payload = JSON.parse(jsonText);
|
|
209
|
-
return (_a = payload.username) !== null && _a !== void 0 ? _a : null;
|
|
210
|
-
}
|
|
211
|
-
catch (_b) {
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/* ------------------------------------------------------------------ */
|
|
216
|
-
/* internals */
|
|
217
|
-
/* ------------------------------------------------------------------ */
|
|
218
|
-
function decodeJwt(token) {
|
|
219
|
-
const [header, payload, signature] = token.split(".");
|
|
220
|
-
if (!header || !payload || !signature) {
|
|
221
|
-
throw new Error("Malformed JWT");
|
|
222
|
-
}
|
|
223
|
-
// Handle URL-safe Base64
|
|
224
|
-
let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
225
|
-
// Add padding if necessary
|
|
226
|
-
b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
|
|
227
|
-
const jsonText = atob(b64);
|
|
228
|
-
return JSON.parse(jsonText);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const PROTOCOL = 'https://';
|
|
232
|
-
const DOMAIN_NAME = 'abstractendeavors';
|
|
233
|
-
const BASE_URL = `${PROTOCOL}${DOMAIN_NAME}.com`;
|
|
234
|
-
const SUB_DIR = 'secure-files';
|
|
235
|
-
const PROD_PREFIX = `/${SUB_DIR}/`;
|
|
236
|
-
const API_PREFIX = `/${SUB_DIR}/api`;
|
|
237
|
-
const DEV_PREFIX = `/${SUB_DIR}-dev/`;
|
|
238
|
-
|
|
239
|
-
function get_window() {
|
|
240
|
-
try {
|
|
241
|
-
if (typeof window !== 'undefined') {
|
|
242
|
-
return window;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
catch (err) {
|
|
246
|
-
alert(err);
|
|
247
|
-
}
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
function get_window_location() {
|
|
251
|
-
try {
|
|
252
|
-
const Window = get_window();
|
|
253
|
-
if (!Window) {
|
|
254
|
-
return BASE_URL;
|
|
255
|
-
}
|
|
256
|
-
return Window.location;
|
|
257
|
-
}
|
|
258
|
-
catch (err) {
|
|
259
|
-
alert(err);
|
|
260
|
-
}
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
function get_window_pathname() {
|
|
264
|
-
try {
|
|
265
|
-
const Window = get_window();
|
|
266
|
-
if (!Window) {
|
|
267
|
-
return DEV_PREFIX;
|
|
268
|
-
}
|
|
269
|
-
return Window.location.pathname;
|
|
270
|
-
}
|
|
271
|
-
catch (err) {
|
|
272
|
-
alert(err);
|
|
273
|
-
}
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
function get_window_parts() {
|
|
277
|
-
try {
|
|
278
|
-
return get_window_location();
|
|
279
|
-
}
|
|
280
|
-
catch (err) {
|
|
281
|
-
alert(err);
|
|
282
|
-
}
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/******************************************************************************
|
|
287
|
-
Copyright (c) Microsoft Corporation.
|
|
288
|
-
|
|
289
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
290
|
-
purpose with or without fee is hereby granted.
|
|
291
|
-
|
|
292
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
293
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
294
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
295
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
296
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
297
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
298
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
299
|
-
***************************************************************************** */
|
|
300
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
function __rest(s, e) {
|
|
304
|
-
var t = {};
|
|
305
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
306
|
-
t[p] = s[p];
|
|
307
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
308
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
309
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
310
|
-
t[p[i]] = s[p[i]];
|
|
311
|
-
}
|
|
312
|
-
return t;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
316
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
317
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
318
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
319
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
320
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
321
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
326
|
-
var e = new Error(message);
|
|
327
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// src/functions/read_utils/src/read_utils.ts
|
|
331
|
-
/**
|
|
332
|
-
* Reads a JSON file, either via Node’s fs (if available)
|
|
333
|
-
* or via window.fetch in the browser. Never throws — returns
|
|
334
|
-
* the parsed object or null on any error.
|
|
335
|
-
*/
|
|
336
|
-
function readJsonFile(relativeOrAbsolutePath) {
|
|
337
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
338
|
-
if (typeof window === 'undefined') {
|
|
339
|
-
// Node environment
|
|
340
|
-
try {
|
|
341
|
-
const { readFile } = yield import('fs/promises');
|
|
342
|
-
const { isAbsolute, resolve } = yield import('path');
|
|
343
|
-
const filePath = isAbsolute(relativeOrAbsolutePath)
|
|
344
|
-
? relativeOrAbsolutePath
|
|
345
|
-
: resolve(process.cwd(), relativeOrAbsolutePath);
|
|
346
|
-
const text = yield readFile(filePath, 'utf8');
|
|
347
|
-
return JSON.parse(text);
|
|
348
|
-
}
|
|
349
|
-
catch (_a) {
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
// 2) Try browser fetch
|
|
355
|
-
const fetchFn = safeGlobalProp('fetch');
|
|
356
|
-
if (typeof fetchFn !== 'function') {
|
|
357
|
-
return null;
|
|
358
|
-
}
|
|
359
|
-
// Resolve URL against document.baseURI if possible
|
|
360
|
-
let url = relativeOrAbsolutePath;
|
|
361
|
-
const baseURI = safeGlobalProp('document', 'baseURI');
|
|
362
|
-
if (baseURI) {
|
|
363
|
-
try {
|
|
364
|
-
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
365
|
-
}
|
|
366
|
-
catch (_b) {
|
|
367
|
-
// keep url as-is
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
try {
|
|
371
|
-
const res = yield fetch(relativeOrAbsolutePath);
|
|
372
|
-
if (!res.ok)
|
|
373
|
-
return null;
|
|
374
|
-
return yield res.json();
|
|
375
|
-
}
|
|
376
|
-
catch (_c) {
|
|
377
|
-
return null;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
function getConfigContent() {
|
|
383
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
384
|
-
try {
|
|
385
|
-
// `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
|
|
386
|
-
const cfg = yield readJsonFile('./config.json');
|
|
387
|
-
return cfg;
|
|
388
|
-
}
|
|
389
|
-
catch (_a) {
|
|
390
|
-
// swallow errors & return null so callers can detect “no config”
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
// 2) Pull a single key out of that object
|
|
396
|
-
function getConfigVar() {
|
|
397
|
-
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
398
|
-
const cfg = yield getConfigContent();
|
|
399
|
-
if (cfg && typeof cfg === 'object' && key in cfg) {
|
|
400
|
-
return cfg[key];
|
|
401
|
-
}
|
|
402
|
-
return undefined;
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
|
|
408
|
-
*/
|
|
409
|
-
function getResult(obj) {
|
|
410
|
-
let current = obj;
|
|
411
|
-
while (current &&
|
|
412
|
-
typeof current === "object" &&
|
|
413
|
-
Object.prototype.hasOwnProperty.call(current, "result")) {
|
|
414
|
-
current = current.result;
|
|
415
|
-
}
|
|
416
|
-
return current;
|
|
417
|
-
}
|
|
418
|
-
// Determines HTTP method, defaults to GET or POST based on body
|
|
419
|
-
function getMethod(method = null, body = null) {
|
|
420
|
-
const validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'PULL'];
|
|
421
|
-
method = (method || '').toUpperCase();
|
|
422
|
-
if (!validMethods.includes(method)) {
|
|
423
|
-
method = body ? 'POST' : 'GET';
|
|
424
|
-
}
|
|
425
|
-
return method;
|
|
426
|
-
}
|
|
427
|
-
// Gets headers, skips JSON headers when body is FormData
|
|
428
|
-
function getHeaders(headers = {}, method = null, body = null) {
|
|
429
|
-
const result = Object.assign({}, headers);
|
|
430
|
-
// inject auth if missing
|
|
431
|
-
if (!result.Authorization) {
|
|
432
|
-
const token = getToken();
|
|
433
|
-
Object.assign(result, getAuthorizationHeader(result, token));
|
|
434
|
-
}
|
|
435
|
-
method = getMethod(method, body);
|
|
436
|
-
// if it’s a multipart FormData, let the browser set the boundary header
|
|
437
|
-
if (body instanceof FormData) {
|
|
438
|
-
return result;
|
|
439
|
-
}
|
|
440
|
-
// otherwise for POST/PUT/PATCH default to JSON
|
|
441
|
-
if (['POST', 'PUT', 'PATCH'].includes(method) && !result['Content-Type']) {
|
|
442
|
-
result['Content-Type'] = 'application/json';
|
|
443
|
-
}
|
|
444
|
-
return result;
|
|
445
|
-
}
|
|
446
|
-
// Prepares request body, serializes to JSON for non-GET requests
|
|
447
|
-
function getBody(body = null, method = null) {
|
|
448
|
-
method = getMethod(method, body);
|
|
449
|
-
if (method === 'GET') {
|
|
450
|
-
return undefined;
|
|
451
|
-
}
|
|
452
|
-
if (body) {
|
|
453
|
-
try {
|
|
454
|
-
return JSON.stringify(body);
|
|
455
|
-
}
|
|
456
|
-
catch (err) {
|
|
457
|
-
return body;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return undefined;
|
|
461
|
-
}
|
|
462
|
-
// Prepares fetch variables, passes FormData intact
|
|
463
|
-
function getFetchVars(headers = null, method = null, body = null) {
|
|
464
|
-
method = getMethod(method, body);
|
|
465
|
-
headers = getHeaders(headers || {}, method, body);
|
|
466
|
-
// only JSON-stringify non-FormData bodies
|
|
467
|
-
if (!(body instanceof FormData)) {
|
|
468
|
-
body = getBody(body, method);
|
|
469
|
-
}
|
|
470
|
-
return { method, headers, body };
|
|
471
|
-
}
|
|
472
|
-
/*
|
|
473
|
-
* parseResult no longer needs to worry about JSON vs HTML redirect errors;
|
|
474
|
-
* all 401/403 have already been handled above.
|
|
475
|
-
*/
|
|
476
|
-
function parseResult(res) {
|
|
477
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
478
|
-
// runs checkResponse first, will throw if session is expired
|
|
479
|
-
res = checkResponse(res);
|
|
480
|
-
if (!res.ok) {
|
|
481
|
-
// for any other non-401 errors, you can still surface them
|
|
482
|
-
const errorText = yield res.text();
|
|
483
|
-
throw new Error(errorText || res.statusText);
|
|
484
|
-
}
|
|
485
|
-
// now safely parse JSON
|
|
486
|
-
return res.json();
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Intercept 401/403 and force a clean redirect to login
|
|
491
|
-
* without ever showing an alert.
|
|
492
|
-
*/
|
|
493
|
-
function checkResponse(res) {
|
|
494
|
-
if (res.status === 401 || res.status === 403) {
|
|
495
|
-
// 1) clear out the stale token
|
|
496
|
-
localStorage.removeItem("token");
|
|
497
|
-
// 2) replace history so "back" doesn’t re-trigger the protected route
|
|
498
|
-
window.history.replaceState({}, "", "/secure-files");
|
|
499
|
-
// 3) short-circuit all further fetch logic
|
|
500
|
-
throw new Error("SessionExpired");
|
|
501
|
-
}
|
|
502
|
-
return res;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function fetchIt(endpoint_1) {
|
|
506
|
-
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnResult = true) {
|
|
507
|
-
method = (method || "GET").toUpperCase();
|
|
508
|
-
// 2) choose the URL
|
|
509
|
-
let url = endpoint;
|
|
510
|
-
// 3) prepare headers & body
|
|
511
|
-
headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), headers);
|
|
512
|
-
const opts = {
|
|
513
|
-
method,
|
|
514
|
-
credentials: withCredentials ? "include" : "same-origin",
|
|
515
|
-
headers,
|
|
516
|
-
body: body instanceof FormData
|
|
517
|
-
? body
|
|
518
|
-
: body != null && method !== "GET"
|
|
519
|
-
? JSON.stringify(body)
|
|
520
|
-
: undefined,
|
|
521
|
-
};
|
|
522
|
-
console.debug("➡️ secureFetchIt →", url, opts);
|
|
523
|
-
let res = yield fetch(url, opts);
|
|
524
|
-
if (!res.ok) {
|
|
525
|
-
const err = yield res.text();
|
|
526
|
-
throw new Error(`HTTP ${res.status}: ${err}`);
|
|
527
|
-
}
|
|
528
|
-
if (blob)
|
|
529
|
-
return res.blob();
|
|
530
|
-
if (returnResult || returnJson) {
|
|
531
|
-
let JsonRes = parseResult(res);
|
|
532
|
-
if (returnResult) {
|
|
533
|
-
JsonRes = getResult(JsonRes);
|
|
534
|
-
}
|
|
535
|
-
return JsonRes;
|
|
536
|
-
}
|
|
537
|
-
return res;
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
// Constructs HTML directory path
|
|
541
|
-
function getHtmlDirectory(directory, filename) {
|
|
542
|
-
return `${directory}/${filename}.html`;
|
|
543
|
-
}
|
|
544
|
-
// Fetches HTML content
|
|
545
|
-
function fetchIndexHtml(filename_1) {
|
|
546
|
-
return __awaiter(this, arguments, void 0, function* (filename, directory = 'sf_index', base = 'html') {
|
|
547
|
-
const url = `/${base}/${directory}/${filename}.html`;
|
|
548
|
-
const response = yield fetch(url);
|
|
549
|
-
return yield response.text();
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
// Fetches and injects HTML content into container
|
|
553
|
-
function fetchIndexHtmlContainer(filename_1) {
|
|
554
|
-
return __awaiter(this, arguments, void 0, function* (filename, doc = document, directory = 'html') {
|
|
555
|
-
const container = `${filename}-container`;
|
|
556
|
-
const html = yield fetchIndexHtml(filename, directory);
|
|
557
|
-
const el = doc.getElementById(container);
|
|
558
|
-
if (el) {
|
|
559
|
-
el.innerHTML = html;
|
|
560
|
-
}
|
|
561
|
-
else {
|
|
562
|
-
console.warn(`⚠️ No container found for: #${container}`);
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function assertPath(path) {
|
|
568
|
-
if (typeof path !== 'string') {
|
|
569
|
-
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// Resolves . and .. elements in a path with directory names
|
|
574
|
-
function normalizeStringPosix(path, allowAboveRoot) {
|
|
575
|
-
var res = '';
|
|
576
|
-
var lastSegmentLength = 0;
|
|
577
|
-
var lastSlash = -1;
|
|
578
|
-
var dots = 0;
|
|
579
|
-
var code;
|
|
580
|
-
for (var i = 0; i <= path.length; ++i) {
|
|
581
|
-
if (i < path.length)
|
|
582
|
-
code = path.charCodeAt(i);
|
|
583
|
-
else if (code === 47 /*/*/)
|
|
584
|
-
break;
|
|
585
|
-
else
|
|
586
|
-
code = 47 /*/*/;
|
|
587
|
-
if (code === 47 /*/*/) {
|
|
588
|
-
if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
|
|
589
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
|
|
590
|
-
if (res.length > 2) {
|
|
591
|
-
var lastSlashIndex = res.lastIndexOf('/');
|
|
592
|
-
if (lastSlashIndex !== res.length - 1) {
|
|
593
|
-
if (lastSlashIndex === -1) {
|
|
594
|
-
res = '';
|
|
595
|
-
lastSegmentLength = 0;
|
|
596
|
-
} else {
|
|
597
|
-
res = res.slice(0, lastSlashIndex);
|
|
598
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
|
|
599
|
-
}
|
|
600
|
-
lastSlash = i;
|
|
601
|
-
dots = 0;
|
|
602
|
-
continue;
|
|
603
|
-
}
|
|
604
|
-
} else if (res.length === 2 || res.length === 1) {
|
|
605
|
-
res = '';
|
|
606
|
-
lastSegmentLength = 0;
|
|
607
|
-
lastSlash = i;
|
|
608
|
-
dots = 0;
|
|
609
|
-
continue;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
if (allowAboveRoot) {
|
|
613
|
-
if (res.length > 0)
|
|
614
|
-
res += '/..';
|
|
615
|
-
else
|
|
616
|
-
res = '..';
|
|
617
|
-
lastSegmentLength = 2;
|
|
618
|
-
}
|
|
619
|
-
} else {
|
|
620
|
-
if (res.length > 0)
|
|
621
|
-
res += '/' + path.slice(lastSlash + 1, i);
|
|
622
|
-
else
|
|
623
|
-
res = path.slice(lastSlash + 1, i);
|
|
624
|
-
lastSegmentLength = i - lastSlash - 1;
|
|
625
|
-
}
|
|
626
|
-
lastSlash = i;
|
|
627
|
-
dots = 0;
|
|
628
|
-
} else if (code === 46 /*.*/ && dots !== -1) {
|
|
629
|
-
++dots;
|
|
630
|
-
} else {
|
|
631
|
-
dots = -1;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
return res;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
function _format(sep, pathObject) {
|
|
638
|
-
var dir = pathObject.dir || pathObject.root;
|
|
639
|
-
var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
|
|
640
|
-
if (!dir) {
|
|
641
|
-
return base;
|
|
642
|
-
}
|
|
643
|
-
if (dir === pathObject.root) {
|
|
644
|
-
return dir + base;
|
|
645
|
-
}
|
|
646
|
-
return dir + sep + base;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
var posix = {
|
|
650
|
-
// path.resolve([from ...], to)
|
|
651
|
-
resolve: function resolve() {
|
|
652
|
-
var resolvedPath = '';
|
|
653
|
-
var resolvedAbsolute = false;
|
|
654
|
-
var cwd;
|
|
655
|
-
|
|
656
|
-
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
657
|
-
var path;
|
|
658
|
-
if (i >= 0)
|
|
659
|
-
path = arguments[i];
|
|
660
|
-
else {
|
|
661
|
-
if (cwd === undefined)
|
|
662
|
-
cwd = process.cwd();
|
|
663
|
-
path = cwd;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
assertPath(path);
|
|
667
|
-
|
|
668
|
-
// Skip empty entries
|
|
669
|
-
if (path.length === 0) {
|
|
670
|
-
continue;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
resolvedPath = path + '/' + resolvedPath;
|
|
674
|
-
resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
// At this point the path should be resolved to a full absolute path, but
|
|
678
|
-
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
679
|
-
|
|
680
|
-
// Normalize the path
|
|
681
|
-
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
682
|
-
|
|
683
|
-
if (resolvedAbsolute) {
|
|
684
|
-
if (resolvedPath.length > 0)
|
|
685
|
-
return '/' + resolvedPath;
|
|
686
|
-
else
|
|
687
|
-
return '/';
|
|
688
|
-
} else if (resolvedPath.length > 0) {
|
|
689
|
-
return resolvedPath;
|
|
690
|
-
} else {
|
|
691
|
-
return '.';
|
|
692
|
-
}
|
|
693
|
-
},
|
|
694
|
-
|
|
695
|
-
normalize: function normalize(path) {
|
|
696
|
-
assertPath(path);
|
|
697
|
-
|
|
698
|
-
if (path.length === 0) return '.';
|
|
699
|
-
|
|
700
|
-
var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
|
|
701
|
-
var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
|
|
702
|
-
|
|
703
|
-
// Normalize the path
|
|
704
|
-
path = normalizeStringPosix(path, !isAbsolute);
|
|
705
|
-
|
|
706
|
-
if (path.length === 0 && !isAbsolute) path = '.';
|
|
707
|
-
if (path.length > 0 && trailingSeparator) path += '/';
|
|
708
|
-
|
|
709
|
-
if (isAbsolute) return '/' + path;
|
|
710
|
-
return path;
|
|
711
|
-
},
|
|
712
|
-
|
|
713
|
-
isAbsolute: function isAbsolute(path) {
|
|
714
|
-
assertPath(path);
|
|
715
|
-
return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
|
|
716
|
-
},
|
|
717
|
-
|
|
718
|
-
join: function join() {
|
|
719
|
-
if (arguments.length === 0)
|
|
720
|
-
return '.';
|
|
721
|
-
var joined;
|
|
722
|
-
for (var i = 0; i < arguments.length; ++i) {
|
|
723
|
-
var arg = arguments[i];
|
|
724
|
-
assertPath(arg);
|
|
725
|
-
if (arg.length > 0) {
|
|
726
|
-
if (joined === undefined)
|
|
727
|
-
joined = arg;
|
|
728
|
-
else
|
|
729
|
-
joined += '/' + arg;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
if (joined === undefined)
|
|
733
|
-
return '.';
|
|
734
|
-
return posix.normalize(joined);
|
|
735
|
-
},
|
|
736
|
-
|
|
737
|
-
relative: function relative(from, to) {
|
|
738
|
-
assertPath(from);
|
|
739
|
-
assertPath(to);
|
|
740
|
-
|
|
741
|
-
if (from === to) return '';
|
|
742
|
-
|
|
743
|
-
from = posix.resolve(from);
|
|
744
|
-
to = posix.resolve(to);
|
|
745
|
-
|
|
746
|
-
if (from === to) return '';
|
|
747
|
-
|
|
748
|
-
// Trim any leading backslashes
|
|
749
|
-
var fromStart = 1;
|
|
750
|
-
for (; fromStart < from.length; ++fromStart) {
|
|
751
|
-
if (from.charCodeAt(fromStart) !== 47 /*/*/)
|
|
752
|
-
break;
|
|
753
|
-
}
|
|
754
|
-
var fromEnd = from.length;
|
|
755
|
-
var fromLen = fromEnd - fromStart;
|
|
756
|
-
|
|
757
|
-
// Trim any leading backslashes
|
|
758
|
-
var toStart = 1;
|
|
759
|
-
for (; toStart < to.length; ++toStart) {
|
|
760
|
-
if (to.charCodeAt(toStart) !== 47 /*/*/)
|
|
761
|
-
break;
|
|
762
|
-
}
|
|
763
|
-
var toEnd = to.length;
|
|
764
|
-
var toLen = toEnd - toStart;
|
|
765
|
-
|
|
766
|
-
// Compare paths to find the longest common path from root
|
|
767
|
-
var length = fromLen < toLen ? fromLen : toLen;
|
|
768
|
-
var lastCommonSep = -1;
|
|
769
|
-
var i = 0;
|
|
770
|
-
for (; i <= length; ++i) {
|
|
771
|
-
if (i === length) {
|
|
772
|
-
if (toLen > length) {
|
|
773
|
-
if (to.charCodeAt(toStart + i) === 47 /*/*/) {
|
|
774
|
-
// We get here if `from` is the exact base path for `to`.
|
|
775
|
-
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
|
776
|
-
return to.slice(toStart + i + 1);
|
|
777
|
-
} else if (i === 0) {
|
|
778
|
-
// We get here if `from` is the root
|
|
779
|
-
// For example: from='/'; to='/foo'
|
|
780
|
-
return to.slice(toStart + i);
|
|
781
|
-
}
|
|
782
|
-
} else if (fromLen > length) {
|
|
783
|
-
if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
|
|
784
|
-
// We get here if `to` is the exact base path for `from`.
|
|
785
|
-
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
|
786
|
-
lastCommonSep = i;
|
|
787
|
-
} else if (i === 0) {
|
|
788
|
-
// We get here if `to` is the root.
|
|
789
|
-
// For example: from='/foo'; to='/'
|
|
790
|
-
lastCommonSep = 0;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
break;
|
|
794
|
-
}
|
|
795
|
-
var fromCode = from.charCodeAt(fromStart + i);
|
|
796
|
-
var toCode = to.charCodeAt(toStart + i);
|
|
797
|
-
if (fromCode !== toCode)
|
|
798
|
-
break;
|
|
799
|
-
else if (fromCode === 47 /*/*/)
|
|
800
|
-
lastCommonSep = i;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
var out = '';
|
|
804
|
-
// Generate the relative path based on the path difference between `to`
|
|
805
|
-
// and `from`
|
|
806
|
-
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
807
|
-
if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
|
|
808
|
-
if (out.length === 0)
|
|
809
|
-
out += '..';
|
|
810
|
-
else
|
|
811
|
-
out += '/..';
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
816
|
-
// the common path parts
|
|
817
|
-
if (out.length > 0)
|
|
818
|
-
return out + to.slice(toStart + lastCommonSep);
|
|
819
|
-
else {
|
|
820
|
-
toStart += lastCommonSep;
|
|
821
|
-
if (to.charCodeAt(toStart) === 47 /*/*/)
|
|
822
|
-
++toStart;
|
|
823
|
-
return to.slice(toStart);
|
|
824
|
-
}
|
|
825
|
-
},
|
|
826
|
-
|
|
827
|
-
_makeLong: function _makeLong(path) {
|
|
828
|
-
return path;
|
|
829
|
-
},
|
|
830
|
-
|
|
831
|
-
dirname: function dirname(path) {
|
|
832
|
-
assertPath(path);
|
|
833
|
-
if (path.length === 0) return '.';
|
|
834
|
-
var code = path.charCodeAt(0);
|
|
835
|
-
var hasRoot = code === 47 /*/*/;
|
|
836
|
-
var end = -1;
|
|
837
|
-
var matchedSlash = true;
|
|
838
|
-
for (var i = path.length - 1; i >= 1; --i) {
|
|
839
|
-
code = path.charCodeAt(i);
|
|
840
|
-
if (code === 47 /*/*/) {
|
|
841
|
-
if (!matchedSlash) {
|
|
842
|
-
end = i;
|
|
843
|
-
break;
|
|
844
|
-
}
|
|
845
|
-
} else {
|
|
846
|
-
// We saw the first non-path separator
|
|
847
|
-
matchedSlash = false;
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
if (end === -1) return hasRoot ? '/' : '.';
|
|
852
|
-
if (hasRoot && end === 1) return '//';
|
|
853
|
-
return path.slice(0, end);
|
|
854
|
-
},
|
|
855
|
-
|
|
856
|
-
basename: function basename(path, ext) {
|
|
857
|
-
if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
|
|
858
|
-
assertPath(path);
|
|
859
|
-
|
|
860
|
-
var start = 0;
|
|
861
|
-
var end = -1;
|
|
862
|
-
var matchedSlash = true;
|
|
863
|
-
var i;
|
|
864
|
-
|
|
865
|
-
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
866
|
-
if (ext.length === path.length && ext === path) return '';
|
|
867
|
-
var extIdx = ext.length - 1;
|
|
868
|
-
var firstNonSlashEnd = -1;
|
|
869
|
-
for (i = path.length - 1; i >= 0; --i) {
|
|
870
|
-
var code = path.charCodeAt(i);
|
|
871
|
-
if (code === 47 /*/*/) {
|
|
872
|
-
// If we reached a path separator that was not part of a set of path
|
|
873
|
-
// separators at the end of the string, stop now
|
|
874
|
-
if (!matchedSlash) {
|
|
875
|
-
start = i + 1;
|
|
876
|
-
break;
|
|
877
|
-
}
|
|
878
|
-
} else {
|
|
879
|
-
if (firstNonSlashEnd === -1) {
|
|
880
|
-
// We saw the first non-path separator, remember this index in case
|
|
881
|
-
// we need it if the extension ends up not matching
|
|
882
|
-
matchedSlash = false;
|
|
883
|
-
firstNonSlashEnd = i + 1;
|
|
884
|
-
}
|
|
885
|
-
if (extIdx >= 0) {
|
|
886
|
-
// Try to match the explicit extension
|
|
887
|
-
if (code === ext.charCodeAt(extIdx)) {
|
|
888
|
-
if (--extIdx === -1) {
|
|
889
|
-
// We matched the extension, so mark this as the end of our path
|
|
890
|
-
// component
|
|
891
|
-
end = i;
|
|
892
|
-
}
|
|
893
|
-
} else {
|
|
894
|
-
// Extension does not match, so our result is the entire path
|
|
895
|
-
// component
|
|
896
|
-
extIdx = -1;
|
|
897
|
-
end = firstNonSlashEnd;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
|
|
904
|
-
return path.slice(start, end);
|
|
905
|
-
} else {
|
|
906
|
-
for (i = path.length - 1; i >= 0; --i) {
|
|
907
|
-
if (path.charCodeAt(i) === 47 /*/*/) {
|
|
908
|
-
// If we reached a path separator that was not part of a set of path
|
|
909
|
-
// separators at the end of the string, stop now
|
|
910
|
-
if (!matchedSlash) {
|
|
911
|
-
start = i + 1;
|
|
912
|
-
break;
|
|
913
|
-
}
|
|
914
|
-
} else if (end === -1) {
|
|
915
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
916
|
-
// path component
|
|
917
|
-
matchedSlash = false;
|
|
918
|
-
end = i + 1;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
if (end === -1) return '';
|
|
923
|
-
return path.slice(start, end);
|
|
924
|
-
}
|
|
925
|
-
},
|
|
926
|
-
|
|
927
|
-
extname: function extname(path) {
|
|
928
|
-
assertPath(path);
|
|
929
|
-
var startDot = -1;
|
|
930
|
-
var startPart = 0;
|
|
931
|
-
var end = -1;
|
|
932
|
-
var matchedSlash = true;
|
|
933
|
-
// Track the state of characters (if any) we see before our first dot and
|
|
934
|
-
// after any path separator we find
|
|
935
|
-
var preDotState = 0;
|
|
936
|
-
for (var i = path.length - 1; i >= 0; --i) {
|
|
937
|
-
var code = path.charCodeAt(i);
|
|
938
|
-
if (code === 47 /*/*/) {
|
|
939
|
-
// If we reached a path separator that was not part of a set of path
|
|
940
|
-
// separators at the end of the string, stop now
|
|
941
|
-
if (!matchedSlash) {
|
|
942
|
-
startPart = i + 1;
|
|
943
|
-
break;
|
|
944
|
-
}
|
|
945
|
-
continue;
|
|
946
|
-
}
|
|
947
|
-
if (end === -1) {
|
|
948
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
949
|
-
// extension
|
|
950
|
-
matchedSlash = false;
|
|
951
|
-
end = i + 1;
|
|
952
|
-
}
|
|
953
|
-
if (code === 46 /*.*/) {
|
|
954
|
-
// If this is our first dot, mark it as the start of our extension
|
|
955
|
-
if (startDot === -1)
|
|
956
|
-
startDot = i;
|
|
957
|
-
else if (preDotState !== 1)
|
|
958
|
-
preDotState = 1;
|
|
959
|
-
} else if (startDot !== -1) {
|
|
960
|
-
// We saw a non-dot and non-path separator before our dot, so we should
|
|
961
|
-
// have a good chance at having a non-empty extension
|
|
962
|
-
preDotState = -1;
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
if (startDot === -1 || end === -1 ||
|
|
967
|
-
// We saw a non-dot character immediately before the dot
|
|
968
|
-
preDotState === 0 ||
|
|
969
|
-
// The (right-most) trimmed path component is exactly '..'
|
|
970
|
-
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
971
|
-
return '';
|
|
972
|
-
}
|
|
973
|
-
return path.slice(startDot, end);
|
|
974
|
-
},
|
|
975
|
-
|
|
976
|
-
format: function format(pathObject) {
|
|
977
|
-
if (pathObject === null || typeof pathObject !== 'object') {
|
|
978
|
-
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
979
|
-
}
|
|
980
|
-
return _format('/', pathObject);
|
|
981
|
-
},
|
|
982
|
-
|
|
983
|
-
parse: function parse(path) {
|
|
984
|
-
assertPath(path);
|
|
985
|
-
|
|
986
|
-
var ret = { root: '', dir: '', base: '', ext: '', name: '' };
|
|
987
|
-
if (path.length === 0) return ret;
|
|
988
|
-
var code = path.charCodeAt(0);
|
|
989
|
-
var isAbsolute = code === 47 /*/*/;
|
|
990
|
-
var start;
|
|
991
|
-
if (isAbsolute) {
|
|
992
|
-
ret.root = '/';
|
|
993
|
-
start = 1;
|
|
994
|
-
} else {
|
|
995
|
-
start = 0;
|
|
996
|
-
}
|
|
997
|
-
var startDot = -1;
|
|
998
|
-
var startPart = 0;
|
|
999
|
-
var end = -1;
|
|
1000
|
-
var matchedSlash = true;
|
|
1001
|
-
var i = path.length - 1;
|
|
1002
|
-
|
|
1003
|
-
// Track the state of characters (if any) we see before our first dot and
|
|
1004
|
-
// after any path separator we find
|
|
1005
|
-
var preDotState = 0;
|
|
1006
|
-
|
|
1007
|
-
// Get non-dir info
|
|
1008
|
-
for (; i >= start; --i) {
|
|
1009
|
-
code = path.charCodeAt(i);
|
|
1010
|
-
if (code === 47 /*/*/) {
|
|
1011
|
-
// If we reached a path separator that was not part of a set of path
|
|
1012
|
-
// separators at the end of the string, stop now
|
|
1013
|
-
if (!matchedSlash) {
|
|
1014
|
-
startPart = i + 1;
|
|
1015
|
-
break;
|
|
1016
|
-
}
|
|
1017
|
-
continue;
|
|
1018
|
-
}
|
|
1019
|
-
if (end === -1) {
|
|
1020
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
1021
|
-
// extension
|
|
1022
|
-
matchedSlash = false;
|
|
1023
|
-
end = i + 1;
|
|
1024
|
-
}
|
|
1025
|
-
if (code === 46 /*.*/) {
|
|
1026
|
-
// If this is our first dot, mark it as the start of our extension
|
|
1027
|
-
if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
|
|
1028
|
-
} else if (startDot !== -1) {
|
|
1029
|
-
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1030
|
-
// have a good chance at having a non-empty extension
|
|
1031
|
-
preDotState = -1;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
if (startDot === -1 || end === -1 ||
|
|
1036
|
-
// We saw a non-dot character immediately before the dot
|
|
1037
|
-
preDotState === 0 ||
|
|
1038
|
-
// The (right-most) trimmed path component is exactly '..'
|
|
1039
|
-
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
1040
|
-
if (end !== -1) {
|
|
1041
|
-
if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
|
|
1042
|
-
}
|
|
1043
|
-
} else {
|
|
1044
|
-
if (startPart === 0 && isAbsolute) {
|
|
1045
|
-
ret.name = path.slice(1, startDot);
|
|
1046
|
-
ret.base = path.slice(1, end);
|
|
1047
|
-
} else {
|
|
1048
|
-
ret.name = path.slice(startPart, startDot);
|
|
1049
|
-
ret.base = path.slice(startPart, end);
|
|
1050
|
-
}
|
|
1051
|
-
ret.ext = path.slice(startDot, end);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
|
|
1055
|
-
|
|
1056
|
-
return ret;
|
|
1057
|
-
},
|
|
1058
|
-
|
|
1059
|
-
sep: '/',
|
|
1060
|
-
delimiter: ':',
|
|
1061
|
-
win32: null,
|
|
1062
|
-
posix: null
|
|
1063
|
-
};
|
|
1064
|
-
|
|
1065
|
-
posix.posix = posix;
|
|
1066
|
-
|
|
1067
|
-
var pathBrowserify = posix;
|
|
1068
|
-
|
|
1069
|
-
function ensure_list(obj) {
|
|
1070
|
-
const objArray = Array.isArray(obj) ? obj : [obj];
|
|
1071
|
-
return objArray;
|
|
1072
|
-
}
|
|
1073
|
-
function assureString(obj) {
|
|
1074
|
-
return String(obj);
|
|
1075
|
-
}
|
|
1076
|
-
function cleanArray(obj) {
|
|
1077
|
-
obj = assureArray(obj);
|
|
1078
|
-
return Array.from(new Set(obj));
|
|
1079
|
-
}
|
|
1080
|
-
function assureArray(input) {
|
|
1081
|
-
if (typeof input === 'string') {
|
|
1082
|
-
return [input];
|
|
1083
|
-
}
|
|
1084
|
-
if (Array.isArray(input)) {
|
|
1085
|
-
return input.map(item => assureString(item));
|
|
1086
|
-
}
|
|
1087
|
-
return [];
|
|
1088
|
-
}
|
|
1089
|
-
// Constrain T so 'in obj' is allowed
|
|
1090
|
-
function get_key_value(obj, key) {
|
|
1091
|
-
// we cast to any for the indexing, since TS can’t infer arbitrary string keys
|
|
1092
|
-
if (key in obj && obj[key] != null) {
|
|
1093
|
-
return obj[key];
|
|
1094
|
-
}
|
|
1095
|
-
return null;
|
|
1096
|
-
}
|
|
1097
|
-
function get(obj, keys, defaultValue = null) {
|
|
1098
|
-
const keyArray = assureArray(keys);
|
|
1099
|
-
if (!obj || keyArray.length === 0) {
|
|
1100
|
-
return defaultValue;
|
|
1101
|
-
}
|
|
1102
|
-
for (const key of keyArray) {
|
|
1103
|
-
const val = get_key_value(obj, key);
|
|
1104
|
-
if (val != null) {
|
|
1105
|
-
return val;
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
return defaultValue;
|
|
1109
|
-
}
|
|
1110
|
-
function cleanText(input) {
|
|
1111
|
-
// Replace delimiters with spaces and split
|
|
1112
|
-
const str = assureString(input);
|
|
1113
|
-
const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
|
|
1114
|
-
return words;
|
|
1115
|
-
}
|
|
1116
|
-
function getCleanArray(obj) {
|
|
1117
|
-
obj = obj.split(/\s+/) // Split on any whitespace
|
|
1118
|
-
.filter((item) => typeof item === 'string' && item !== '');
|
|
1119
|
-
// Get basename
|
|
1120
|
-
// Remove duplicates using Set
|
|
1121
|
-
const uniqueWords = cleanArray(obj);
|
|
1122
|
-
return uniqueWords;
|
|
1123
|
-
}
|
|
1124
|
-
function isStrInString(obj, string) {
|
|
1125
|
-
const obj_str = assureString(obj).toLowerCase;
|
|
1126
|
-
string = assureString(string).toLowerCase;
|
|
1127
|
-
if (string.includes(obj_str)) {
|
|
1128
|
-
return true;
|
|
1129
|
-
}
|
|
1130
|
-
return false;
|
|
1131
|
-
}
|
|
1132
|
-
function getChar(i, string) {
|
|
1133
|
-
if (string.length >= i) {
|
|
1134
|
-
return assureString(string)[i];
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
function isType(obj, type) {
|
|
1138
|
-
if (typeof obj === type) {
|
|
1139
|
-
return true;
|
|
1140
|
-
}
|
|
1141
|
-
return false;
|
|
1142
|
-
}
|
|
1143
|
-
function getNums() {
|
|
1144
|
-
return '0123456789';
|
|
1145
|
-
}
|
|
1146
|
-
function isNum(obj) {
|
|
1147
|
-
const is_num = isType(obj, 'number');
|
|
1148
|
-
if (is_num) {
|
|
1149
|
-
return is_num;
|
|
1150
|
-
}
|
|
1151
|
-
return isStrInString(obj, getNums());
|
|
1152
|
-
}
|
|
1153
|
-
function getAlphas() {
|
|
1154
|
-
return 'abcdefghijklmnopqrstuvwxyz';
|
|
1155
|
-
}
|
|
1156
|
-
function getAlphaNum(obj) {
|
|
1157
|
-
const is_num = isNum(obj);
|
|
1158
|
-
const alphas = getAlphas();
|
|
1159
|
-
if (is_num) {
|
|
1160
|
-
return getChar(obj, alphas);
|
|
1161
|
-
}
|
|
1162
|
-
if (isStrInString(obj, alphas)) {
|
|
1163
|
-
return getChar(obj, alphas);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
function getSubstring(obj, maxLength = null, minLength = null) {
|
|
1168
|
-
const objLength = obj.length;
|
|
1169
|
-
const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
|
|
1170
|
-
const effectiveMinLength = minLength !== null && minLength !== void 0 ? minLength : 0;
|
|
1171
|
-
// Ensure bounds are valid
|
|
1172
|
-
const clampedMaxLength = Math.min(Math.max(effectiveMaxLength, 0), objLength);
|
|
1173
|
-
const clampedMinLength = Math.min(Math.max(effectiveMinLength, 0), objLength);
|
|
1174
|
-
// If minLength exceeds maxLength, return empty string or adjust logic as needed
|
|
1175
|
-
if (clampedMinLength >= clampedMaxLength) {
|
|
1176
|
-
return '';
|
|
1177
|
-
}
|
|
1178
|
-
return obj.substring(clampedMinLength, clampedMaxLength);
|
|
1179
|
-
}
|
|
1180
|
-
function truncateString(obj, maxLength = 20) {
|
|
1181
|
-
const objLength = obj.length;
|
|
1182
|
-
if (objLength > maxLength && maxLength) {
|
|
1183
|
-
obj = getSubstring(obj, maxLength) + '...';
|
|
1184
|
-
}
|
|
1185
|
-
return obj;
|
|
1186
|
-
}
|
|
1187
|
-
function capitalize_str(string) {
|
|
1188
|
-
string = assureString(string);
|
|
1189
|
-
const string_len = string.length;
|
|
1190
|
-
let init_char = string.toUpperCase();
|
|
1191
|
-
if (string_len > 0) {
|
|
1192
|
-
init_char = string[0].toUpperCase();
|
|
1193
|
-
}
|
|
1194
|
-
let rest_chars = '';
|
|
1195
|
-
if (string_len > 1) {
|
|
1196
|
-
rest_chars = string.slice(1).toLowerCase();
|
|
1197
|
-
}
|
|
1198
|
-
const fin_chars = `${init_char}${rest_chars}`;
|
|
1199
|
-
return fin_chars;
|
|
1200
|
-
}
|
|
1201
|
-
function capitalize(string) {
|
|
1202
|
-
let nu_string = '';
|
|
1203
|
-
string = assureString(string);
|
|
1204
|
-
let objs = string.replace('-', '_').split('_');
|
|
1205
|
-
for (const obj of objs) {
|
|
1206
|
-
let str_obj = capitalize_str(obj);
|
|
1207
|
-
nu_string = `${nu_string} ${str_obj}`;
|
|
1208
|
-
}
|
|
1209
|
-
return eatAll(nu_string, [' ']);
|
|
1210
|
-
}
|
|
1211
|
-
// string_utils/src/string_utils.ts
|
|
1212
|
-
function stripPrefixes(str, bases = []) {
|
|
1213
|
-
/* NEW: coerce whatever arrives into a string */
|
|
1214
|
-
str = String(str);
|
|
1215
|
-
const prefixes = (Array.isArray(bases) ? bases : [bases])
|
|
1216
|
-
.filter(Boolean)
|
|
1217
|
-
.sort((a, b) => b.length - a.length); // longest first
|
|
1218
|
-
let changed = true;
|
|
1219
|
-
while (changed) {
|
|
1220
|
-
changed = false;
|
|
1221
|
-
for (const prefix of prefixes) {
|
|
1222
|
-
if (str.startsWith(prefix)) {
|
|
1223
|
-
str = str.slice(prefix.length);
|
|
1224
|
-
changed = true;
|
|
1225
|
-
break; // restart from longest prefix
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
return str;
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* Removes characters from the beginning of the string
|
|
1233
|
-
* if they are found in the list of characters.
|
|
1234
|
-
*
|
|
1235
|
-
* @param str - The input string.
|
|
1236
|
-
* @param listObjects - A string or an array of characters to remove.
|
|
1237
|
-
* @returns The modified string.
|
|
1238
|
-
*/
|
|
1239
|
-
function eatInner(str, listObjects) {
|
|
1240
|
-
if (!Array.isArray(listObjects)) {
|
|
1241
|
-
listObjects = [listObjects];
|
|
1242
|
-
}
|
|
1243
|
-
// Ensure str is a string
|
|
1244
|
-
str = String(str);
|
|
1245
|
-
// Remove characters from the beginning while they are in listObjects
|
|
1246
|
-
while (str.length > 0 && listObjects.includes(str[0])) {
|
|
1247
|
-
str = str.slice(1);
|
|
1248
|
-
}
|
|
1249
|
-
return str;
|
|
1250
|
-
}
|
|
1251
|
-
/**
|
|
1252
|
-
* Removes characters from the end of the string
|
|
1253
|
-
* if they are found in the list of characters.
|
|
1254
|
-
*
|
|
1255
|
-
* @param str - The input string.
|
|
1256
|
-
* @param listObjects - A string or an array of characters to remove.
|
|
1257
|
-
* @returns The modified string.
|
|
1258
|
-
*/
|
|
1259
|
-
function eatOuter(str, listObjects) {
|
|
1260
|
-
if (!Array.isArray(listObjects)) {
|
|
1261
|
-
listObjects = [listObjects];
|
|
1262
|
-
}
|
|
1263
|
-
// Ensure str is a string
|
|
1264
|
-
str = String(str);
|
|
1265
|
-
// Remove characters from the end while they are in listObjects
|
|
1266
|
-
while (str.length > 0 && listObjects.includes(str[str.length - 1])) {
|
|
1267
|
-
str = str.slice(0, -1);
|
|
1268
|
-
}
|
|
1269
|
-
return str;
|
|
1270
|
-
}
|
|
1271
|
-
/**
|
|
1272
|
-
* Removes characters from both the beginning and the end of the string
|
|
1273
|
-
* if they are found in the list of characters.
|
|
1274
|
-
*
|
|
1275
|
-
* @param str - The input string.
|
|
1276
|
-
* @param listObjects - A string or an array of characters to remove.
|
|
1277
|
-
* @returns The modified string.
|
|
1278
|
-
*/
|
|
1279
|
-
function eatAll(str, listObjects) {
|
|
1280
|
-
return eatOuter(eatInner(str, listObjects), listObjects);
|
|
1281
|
-
}
|
|
1282
|
-
function eatEnd(obj, endings = ['/']) {
|
|
1283
|
-
let result = obj;
|
|
1284
|
-
let modified = true;
|
|
1285
|
-
while (modified) {
|
|
1286
|
-
modified = false;
|
|
1287
|
-
for (const ending of endings) {
|
|
1288
|
-
if (result.endsWith(ending)) {
|
|
1289
|
-
result = result.slice(0, -ending.length);
|
|
1290
|
-
modified = true;
|
|
1291
|
-
break;
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
return result;
|
|
1296
|
-
}
|
|
1297
|
-
function tryParse(obj) {
|
|
1298
|
-
try {
|
|
1299
|
-
obj = JSON.stringify(obj);
|
|
1300
|
-
}
|
|
1301
|
-
catch (err) {
|
|
1302
|
-
try {
|
|
1303
|
-
obj = JSON.parse(obj);
|
|
1304
|
-
}
|
|
1305
|
-
catch (err) {
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
return obj;
|
|
1309
|
-
}
|
|
1310
|
-
function create_list_string(array_obj) {
|
|
1311
|
-
let string = '';
|
|
1312
|
-
for (const obj in array_obj) {
|
|
1313
|
-
const array_value = array_obj[obj];
|
|
1314
|
-
const parsed_value = tryParse(array_value);
|
|
1315
|
-
string += `${obj} == ${parsed_value}\n`;
|
|
1316
|
-
}
|
|
1317
|
-
return string;
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
/**
|
|
1321
|
-
* In the browser we already have a WHATWG URL constructor on window.
|
|
1322
|
-
* Here we re-export it as “url” so other modules can import it.
|
|
1323
|
-
*/
|
|
1324
|
-
/**
|
|
1325
|
-
* Minimal fileURLToPath implementation for browser-side code.
|
|
1326
|
-
* If you only ever need to strip off “file://” in development, this is enough.
|
|
1327
|
-
*/
|
|
1328
|
-
function fileURLToPath(fileUrl) {
|
|
1329
|
-
// e.g. fileUrl = "file:///Users/foo/bar.txt"
|
|
1330
|
-
try {
|
|
1331
|
-
const u = new URL(fileUrl);
|
|
1332
|
-
return u.pathname;
|
|
1333
|
-
}
|
|
1334
|
-
catch (_a) {
|
|
1335
|
-
// fallback: just strip file://
|
|
1336
|
-
return fileUrl.replace(/^file:\/\//, '');
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
function getAbsolutePath() {
|
|
1340
|
-
return fileURLToPath(import.meta.url);
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
function get_dirname(filePath) {
|
|
1344
|
-
if (!filePath)
|
|
1345
|
-
return '';
|
|
1346
|
-
return pathBrowserify.dirname(filePath);
|
|
1347
|
-
}
|
|
1348
|
-
function get_basename(filePath) {
|
|
1349
|
-
if (!filePath)
|
|
1350
|
-
return '';
|
|
1351
|
-
return pathBrowserify.basename(filePath);
|
|
1352
|
-
}
|
|
1353
|
-
function get_filename(file_path) {
|
|
1354
|
-
const ext = pathBrowserify.extname(file_path);
|
|
1355
|
-
return pathBrowserify.basename(file_path, ext);
|
|
1356
|
-
}
|
|
1357
|
-
function get_extname(filePath) {
|
|
1358
|
-
if (!filePath)
|
|
1359
|
-
return '';
|
|
1360
|
-
return pathBrowserify.extname(filePath);
|
|
1361
|
-
}
|
|
1362
|
-
function get_splitext(filePath) {
|
|
1363
|
-
if (!filePath)
|
|
1364
|
-
return { filename: '', extname: '' };
|
|
1365
|
-
const ext = pathBrowserify.extname(filePath);
|
|
1366
|
-
// Get the basename without the extension
|
|
1367
|
-
const filename = pathBrowserify.basename(filePath, ext);
|
|
1368
|
-
return { filename, ext };
|
|
1369
|
-
}
|
|
1370
|
-
/**
|
|
1371
|
-
* Join multiple path segments, normalizing leading/trailing slashes.
|
|
1372
|
-
*
|
|
1373
|
-
* Usage:
|
|
1374
|
-
* make_path('/foo','bar','baz')
|
|
1375
|
-
* make_path(['/foo','bar','baz'])
|
|
1376
|
-
*/
|
|
1377
|
-
function make_path(...paths) {
|
|
1378
|
-
// If someone passed a single array, unwrap it:
|
|
1379
|
-
const pathArray = (paths.length === 1 && Array.isArray(paths[0])
|
|
1380
|
-
? paths[0]
|
|
1381
|
-
: paths);
|
|
1382
|
-
let real_path = '';
|
|
1383
|
-
for (let i = 0; i < pathArray.length; i++) {
|
|
1384
|
-
let segment = pathArray[i];
|
|
1385
|
-
if (i === 0) {
|
|
1386
|
-
real_path = segment;
|
|
1387
|
-
}
|
|
1388
|
-
else {
|
|
1389
|
-
// remove any leading slash on this segment
|
|
1390
|
-
segment = segment.replace(/^\/+/, '');
|
|
1391
|
-
// remove any trailing slash on the accumulator
|
|
1392
|
-
real_path = real_path.replace(/\/+$/, '');
|
|
1393
|
-
real_path = `${real_path}/${segment}`;
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
return real_path;
|
|
1397
|
-
}
|
|
1398
|
-
function sanitizeFilename(filename) {
|
|
1399
|
-
return filename
|
|
1400
|
-
.toLowerCase()
|
|
1401
|
-
.replace(/\s+|-/g, '-') // Replace spaces and hyphens with single hyphen
|
|
1402
|
-
.replace(/_/g, '-') // Replace underscores with hyphens
|
|
1403
|
-
.replace(/[^a-z0-9-.]/g, '') // Remove all non-alphanumeric chars except hyphen and dot
|
|
1404
|
-
.replace(/-+/g, '-') // Collapse multiple hyphens into one
|
|
1405
|
-
.replace(/^-|-$/, ''); // Remove leading/trailing hyphens
|
|
1406
|
-
}
|
|
1407
|
-
function make_sanitized_path(...paths) {
|
|
1408
|
-
let real_path = '';
|
|
1409
|
-
for (let i = 0; i < paths.length; i++) {
|
|
1410
|
-
const sanitized = sanitizeFilename(eatInner(paths[i], ['/']));
|
|
1411
|
-
if (i === 0) {
|
|
1412
|
-
real_path = sanitized;
|
|
1413
|
-
}
|
|
1414
|
-
else if (sanitized) { // Only append if there's a non-empty segment
|
|
1415
|
-
real_path = `${real_path}/${sanitized}`;
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
return real_path || '';
|
|
1419
|
-
}
|
|
1420
|
-
function normalizeUrl(base, p) {
|
|
1421
|
-
if (!p)
|
|
1422
|
-
return base;
|
|
1423
|
-
const cleanBase = base.replace(/\/+$/, ''); // regex literal
|
|
1424
|
-
const cleanPath = p.replace(/^\/+/, '');
|
|
1425
|
-
// collapse multiple “//” into one, but keep the “://” after protocol
|
|
1426
|
-
return `${cleanBase}/${cleanPath}`.replace(/([^:])\/{2,}/g, '$1/');
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
/**
|
|
1430
|
-
* Returns the absolute path of the current file.
|
|
1431
|
-
*/
|
|
1432
|
-
function getAbsDir() {
|
|
1433
|
-
return get_dirname(getAbsolutePath());
|
|
1434
|
-
}
|
|
1435
|
-
function getAbsPath(subPath) {
|
|
1436
|
-
return make_path(getAbsDir(), subPath);
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
function getFunctionsDir() {
|
|
1440
|
-
return get_dirname(getAbsDir());
|
|
1441
|
-
}
|
|
1442
|
-
function geAuthsUtilsDirectory() {
|
|
1443
|
-
return make_path(getFunctionsDir(), 'auths');
|
|
1444
|
-
}
|
|
1445
|
-
function geBackupsUtilsDirectory() {
|
|
1446
|
-
return make_path(getFunctionsDir(), 'backups');
|
|
1447
|
-
}
|
|
1448
|
-
function geConstantsUtilsDirectory() {
|
|
1449
|
-
return make_path(getFunctionsDir(), 'constants');
|
|
1450
|
-
}
|
|
1451
|
-
function geEnvUtilsDirectory() {
|
|
1452
|
-
return make_path(getFunctionsDir(), 'env_utils');
|
|
1453
|
-
}
|
|
1454
|
-
function geFetchUtilsDirectory() {
|
|
1455
|
-
return make_path(getFunctionsDir(), 'fetch_utils');
|
|
1456
|
-
}
|
|
1457
|
-
function geFileUtilsDirectory() {
|
|
1458
|
-
return make_path(getFunctionsDir(), 'file_utils');
|
|
1459
|
-
}
|
|
1460
|
-
function gePathUtilsDirectory() {
|
|
1461
|
-
return make_path(getFunctionsDir(), 'path_utils');
|
|
1462
|
-
}
|
|
1463
|
-
function geStringUtilsDirectory() {
|
|
1464
|
-
return make_path(getFunctionsDir(), 'string_utils');
|
|
1465
|
-
}
|
|
1466
|
-
function geTypeUtilsDirectory() {
|
|
1467
|
-
return make_path(getFunctionsDir(), 'type_utils');
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
function getSrcDir() {
|
|
1471
|
-
return get_dirname(getFunctionsDir());
|
|
1472
|
-
}
|
|
1473
|
-
function geStaticDirectory() {
|
|
1474
|
-
return make_path(getSrcDir(), 'static');
|
|
1475
|
-
}
|
|
1476
|
-
function getLibUtilsDirectory() {
|
|
1477
|
-
return make_path(getSrcDir(), 'lib');
|
|
1478
|
-
}
|
|
1479
|
-
function getHooksUtilsDirectory() {
|
|
1480
|
-
return make_path(getSrcDir(), 'hooks');
|
|
1481
|
-
}
|
|
1482
|
-
function getFunctionsUtilsDirectory() {
|
|
1483
|
-
return make_path(getSrcDir(), 'functions');
|
|
1484
|
-
}
|
|
1485
|
-
function getComponentsUtilsDirectory() {
|
|
1486
|
-
return make_path(getSrcDir(), 'components');
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
function getBaseDir() {
|
|
1490
|
-
return get_dirname(getSrcDir());
|
|
1491
|
-
}
|
|
1492
|
-
function getPublicDir() {
|
|
1493
|
-
return make_path(getBaseDir(), 'public');
|
|
1494
|
-
}
|
|
1495
|
-
function getDistDir() {
|
|
1496
|
-
return make_path(getBaseDir(), 'dist');
|
|
1497
|
-
}
|
|
1498
|
-
function getEnvDir() {
|
|
1499
|
-
return make_path(getBaseDir(), '.env');
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
function getEnvPath(string = '.env') {
|
|
1503
|
-
return make_path(getEnvDir(), string);
|
|
1504
|
-
}
|
|
1505
|
-
function getDbConfigsPath() {
|
|
1506
|
-
return make_path(getBaseDir(), 'dbConfigs');
|
|
1507
|
-
}
|
|
1508
|
-
function getSchemasPath() {
|
|
1509
|
-
return make_path(getDbConfigsPath(), 'schemas');
|
|
1510
|
-
}
|
|
1511
|
-
function getSchemasDirPath(subPath) {
|
|
1512
|
-
return make_path(getSchemasPath(), subPath);
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
// src/functions/rndm_utils/utils.ts
|
|
1516
|
-
function alertit(obj = null) {
|
|
1517
|
-
let msg;
|
|
1518
|
-
try {
|
|
1519
|
-
msg = JSON.stringify(obj);
|
|
1520
|
-
}
|
|
1521
|
-
catch (_a) {
|
|
1522
|
-
// If JSON.stringify fails (circular refs, etc.), fall back to a simple string
|
|
1523
|
-
msg = String(obj);
|
|
1524
|
-
}
|
|
1525
|
-
alert(msg);
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
function Button(_a) {
|
|
1529
|
-
var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
|
|
1530
|
-
const base = 'rounded px-3 py-1 text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors duration-150';
|
|
1531
|
-
const variantStyles = {
|
|
1532
|
-
default: '',
|
|
1533
|
-
icon: 'p-1 bg-transparent hover:bg-gray-100',
|
|
1534
|
-
primary: 'text-white',
|
|
1535
|
-
secondary: '',
|
|
1536
|
-
};
|
|
1537
|
-
const palette = {
|
|
1538
|
-
gray: variant === 'primary'
|
|
1539
|
-
? 'bg-gray-600 hover:bg-gray-700 focus:ring-gray-500'
|
|
1540
|
-
: 'bg-gray-200 hover:bg-gray-300 focus:ring-gray-400',
|
|
1541
|
-
green: 'bg-green-600 text-white hover:bg-green-700 focus:ring-green-500',
|
|
1542
|
-
blue: variant === 'primary'
|
|
1543
|
-
? 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500'
|
|
1544
|
-
: 'bg-blue-200 hover:bg-blue-300 focus:ring-blue-400',
|
|
1545
|
-
};
|
|
1546
|
-
return (jsx("button", Object.assign({ className: `${base} ${variantStyles[variant]} ${palette[color]} ${className}` }, rest, { children: children })));
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
function Checkbox(_a) {
|
|
1550
|
-
var { label } = _a, rest = __rest(_a, ["label"]);
|
|
1551
|
-
return (jsxs("label", { className: 'flex items-center gap-2 mb-4', children: [jsx("input", Object.assign({ type: 'checkbox' }, rest)), jsx("span", { children: label })] }));
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
function Input(_a) {
|
|
1555
|
-
var { label, trailing } = _a, rest = __rest(_a, ["label", "trailing"]);
|
|
1556
|
-
return (jsxs("label", { className: 'mb-4 block', children: [jsx("span", { className: 'block text-sm font-medium mb-1', children: label }), jsxs("div", { className: 'flex gap-2', children: [jsx("input", Object.assign({ className: 'flex-1 rounded border px-2 py-1 disabled:bg-gray-100' }, rest)), trailing] })] }));
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
function Spinner() {
|
|
1560
|
-
return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
// src/functions/config_utils/src/config_utils.ts
|
|
1564
|
-
/**
|
|
1565
|
-
* Attempt to load config.json if present, otherwise return empty object.
|
|
1566
|
-
*/
|
|
1567
|
-
function getConfigJson() {
|
|
1568
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1569
|
-
try {
|
|
1570
|
-
return (yield readJsonFile('config.json')) || {};
|
|
1571
|
-
}
|
|
1572
|
-
catch (_a) {
|
|
1573
|
-
return {};
|
|
1574
|
-
}
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
/**
|
|
1579
|
-
* Processes keywords by checking if keywords is a string and splitting it.
|
|
1580
|
-
* Then cleans each keyword using `eatAll` with a set of characters to remove.
|
|
1581
|
-
*
|
|
1582
|
-
* @param keywords - The keywords as a comma-separated string or as an array.
|
|
1583
|
-
* @returns An array of cleaned keywords.
|
|
1584
|
-
*/
|
|
1585
|
-
function processKeywords(keywords) {
|
|
1586
|
-
let keywordArray;
|
|
1587
|
-
// If keywords is a string, split it on commas
|
|
1588
|
-
if (typeof keywords === "string") {
|
|
1589
|
-
keywordArray = keywords.split(",");
|
|
1590
|
-
}
|
|
1591
|
-
else {
|
|
1592
|
-
keywordArray = keywords;
|
|
1593
|
-
}
|
|
1594
|
-
// Clean each keyword by removing unwanted characters
|
|
1595
|
-
return keywordArray.map(keyword => eatAll(keyword, [",", "\n", "\t", " ", "#"]));
|
|
1596
|
-
}
|
|
1597
|
-
/**
|
|
1598
|
-
* Constructs a keyword string where each keyword is prefixed with a hash (#).
|
|
1599
|
-
*
|
|
1600
|
-
* @param keywords - An array of keywords.
|
|
1601
|
-
* @returns A string with each keyword prefixed by '#'.
|
|
1602
|
-
*/
|
|
1603
|
-
function get_keyword_string(keywords) {
|
|
1604
|
-
keywords = processKeywords(keywords);
|
|
1605
|
-
let allString = "";
|
|
1606
|
-
for (const keyword of keywords) {
|
|
1607
|
-
allString += ` #${keyword}`;
|
|
1608
|
-
}
|
|
1609
|
-
return allString;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, assureArray, assureString, callStorage, callWindowMethod, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, create_list_string, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfigContent, getConfigJson, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_basename, get_dirname, get_extname, get_filename, get_key_value, get_keyword_string, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isNum, isStrInString, isTokenExpired, isType, make_path, make_sanitized_path, normalizeUrl, parseResult, processKeywords, readJsonFile, removeToken, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse };
|
|
1613
|
-
//# sourceMappingURL=index.js.map
|