@putkoff/abstract-utilities 0.1.220 → 0.1.223

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.
@@ -0,0 +1,1626 @@
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
+ try {
340
+ const { readFile } = yield import('fs/promises');
341
+ const { isAbsolute, resolve } = yield import('path');
342
+ const filePath = isAbsolute(relativeOrAbsolutePath)
343
+ ? relativeOrAbsolutePath
344
+ : resolve(import.meta.url ? new URL('.', import.meta.url).pathname : '', relativeOrAbsolutePath);
345
+ const text = yield readFile(filePath, 'utf8');
346
+ return JSON.parse(text);
347
+ }
348
+ catch (_a) {
349
+ return null;
350
+ }
351
+ }
352
+ // Browser fallback
353
+ const fetchFn = safeGlobalProp('fetch');
354
+ if (typeof fetchFn !== 'function')
355
+ return null;
356
+ let url = relativeOrAbsolutePath;
357
+ const baseURI = safeGlobalProp('document', 'baseURI');
358
+ if (baseURI) {
359
+ try {
360
+ url = new URL(relativeOrAbsolutePath, baseURI).href;
361
+ }
362
+ catch (_b) { }
363
+ }
364
+ try {
365
+ const res = yield fetchFn(url);
366
+ if (!res.ok)
367
+ return null;
368
+ return yield res.json();
369
+ }
370
+ catch (_c) {
371
+ return null;
372
+ }
373
+ });
374
+ }
375
+ function getConfigContent() {
376
+ return __awaiter(this, void 0, void 0, function* () {
377
+ try {
378
+ // `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
379
+ const cfg = yield readJsonFile('./config.json');
380
+ return cfg;
381
+ }
382
+ catch (_a) {
383
+ // swallow errors & return null so callers can detect “no config”
384
+ return null;
385
+ }
386
+ });
387
+ }
388
+ // 2) Pull a single key out of that object
389
+ function getConfigVar() {
390
+ return __awaiter(this, arguments, void 0, function* (key = null) {
391
+ const cfg = yield getConfigContent();
392
+ if (cfg && typeof cfg === 'object' && key in cfg) {
393
+ return cfg[key];
394
+ }
395
+ return undefined;
396
+ });
397
+ }
398
+
399
+ /**
400
+ * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
401
+ */
402
+ function getResult(obj) {
403
+ let current = obj;
404
+ while (current &&
405
+ typeof current === "object" &&
406
+ Object.prototype.hasOwnProperty.call(current, "result")) {
407
+ current = current.result;
408
+ }
409
+ return current;
410
+ }
411
+ // Determines HTTP method, defaults to GET or POST based on body
412
+ function getMethod(method = null, body = null) {
413
+ const validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'PULL'];
414
+ method = (method || '').toUpperCase();
415
+ if (!validMethods.includes(method)) {
416
+ method = body ? 'POST' : 'GET';
417
+ }
418
+ return method;
419
+ }
420
+ // Gets headers, skips JSON headers when body is FormData
421
+ function getHeaders(headers = {}, method = null, body = null) {
422
+ const result = Object.assign({}, headers);
423
+ // inject auth if missing
424
+ if (!result.Authorization) {
425
+ const token = getToken();
426
+ Object.assign(result, getAuthorizationHeader(result, token));
427
+ }
428
+ method = getMethod(method, body);
429
+ // if it’s a multipart FormData, let the browser set the boundary header
430
+ if (body instanceof FormData) {
431
+ return result;
432
+ }
433
+ // otherwise for POST/PUT/PATCH default to JSON
434
+ if (['POST', 'PUT', 'PATCH'].includes(method) && !result['Content-Type']) {
435
+ result['Content-Type'] = 'application/json';
436
+ }
437
+ return result;
438
+ }
439
+ // Prepares request body, serializes to JSON for non-GET requests
440
+ function getBody(body = null, method = null) {
441
+ method = getMethod(method, body);
442
+ if (method === 'GET') {
443
+ return undefined;
444
+ }
445
+ if (body) {
446
+ try {
447
+ return JSON.stringify(body);
448
+ }
449
+ catch (err) {
450
+ return body;
451
+ }
452
+ }
453
+ return undefined;
454
+ }
455
+ // Prepares fetch variables, passes FormData intact
456
+ function getFetchVars(headers = null, method = null, body = null) {
457
+ method = getMethod(method, body);
458
+ headers = getHeaders(headers || {}, method, body);
459
+ // only JSON-stringify non-FormData bodies
460
+ if (!(body instanceof FormData)) {
461
+ body = getBody(body, method);
462
+ }
463
+ return { method, headers, body };
464
+ }
465
+ /*
466
+ * parseResult no longer needs to worry about JSON vs HTML redirect errors;
467
+ * all 401/403 have already been handled above.
468
+ */
469
+ function parseResult(res) {
470
+ return __awaiter(this, void 0, void 0, function* () {
471
+ // runs checkResponse first, will throw if session is expired
472
+ res = checkResponse(res);
473
+ if (!res.ok) {
474
+ // for any other non-401 errors, you can still surface them
475
+ const errorText = yield res.text();
476
+ throw new Error(errorText || res.statusText);
477
+ }
478
+ // now safely parse JSON
479
+ return res.json();
480
+ });
481
+ }
482
+ /**
483
+ * Intercept 401/403 and force a clean redirect to login
484
+ * without ever showing an alert.
485
+ */
486
+ function checkResponse(res) {
487
+ if (res.status === 401 || res.status === 403) {
488
+ // 1) clear out the stale token
489
+ localStorage.removeItem("token");
490
+ // 2) replace history so "back" doesn’t re-trigger the protected route
491
+ window.history.replaceState({}, "", "/secure-files");
492
+ // 3) short-circuit all further fetch logic
493
+ throw new Error("SessionExpired");
494
+ }
495
+ return res;
496
+ }
497
+
498
+ function fetchIt(endpoint_1) {
499
+ return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnResult = true) {
500
+ method = (method || "GET").toUpperCase();
501
+ // 2) choose the URL
502
+ let url = endpoint;
503
+ // 3) prepare headers & body
504
+ headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), headers);
505
+ const opts = {
506
+ method,
507
+ credentials: withCredentials ? "include" : "same-origin",
508
+ headers,
509
+ body: body instanceof FormData
510
+ ? body
511
+ : body != null && method !== "GET"
512
+ ? JSON.stringify(body)
513
+ : undefined,
514
+ };
515
+ console.debug("➡️ secureFetchIt →", url, opts);
516
+ let res = yield fetch(url, opts);
517
+ if (!res.ok) {
518
+ const err = yield res.text();
519
+ throw new Error(`HTTP ${res.status}: ${err}`);
520
+ }
521
+ if (blob)
522
+ return res.blob();
523
+ if (returnResult || returnJson) {
524
+ let JsonRes = parseResult(res);
525
+ if (returnResult) {
526
+ JsonRes = getResult(JsonRes);
527
+ }
528
+ return JsonRes;
529
+ }
530
+ return res;
531
+ });
532
+ }
533
+ // Constructs HTML directory path
534
+ function getHtmlDirectory(directory, filename) {
535
+ return `${directory}/${filename}.html`;
536
+ }
537
+ // Fetches HTML content
538
+ function fetchIndexHtml(filename_1) {
539
+ return __awaiter(this, arguments, void 0, function* (filename, directory = 'sf_index', base = 'html') {
540
+ const url = `/${base}/${directory}/${filename}.html`;
541
+ const response = yield fetch(url);
542
+ return yield response.text();
543
+ });
544
+ }
545
+ // Fetches and injects HTML content into container
546
+ function fetchIndexHtmlContainer(filename_1) {
547
+ return __awaiter(this, arguments, void 0, function* (filename, doc = document, directory = 'html') {
548
+ const container = `${filename}-container`;
549
+ const html = yield fetchIndexHtml(filename, directory);
550
+ const el = doc.getElementById(container);
551
+ if (el) {
552
+ el.innerHTML = html;
553
+ }
554
+ else {
555
+ console.warn(`⚠️ No container found for: #${container}`);
556
+ }
557
+ });
558
+ }
559
+
560
+ function assertPath(path) {
561
+ if (typeof path !== 'string') {
562
+ throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
563
+ }
564
+ }
565
+
566
+ // Resolves . and .. elements in a path with directory names
567
+ function normalizeStringPosix(path, allowAboveRoot) {
568
+ var res = '';
569
+ var lastSegmentLength = 0;
570
+ var lastSlash = -1;
571
+ var dots = 0;
572
+ var code;
573
+ for (var i = 0; i <= path.length; ++i) {
574
+ if (i < path.length)
575
+ code = path.charCodeAt(i);
576
+ else if (code === 47 /*/*/)
577
+ break;
578
+ else
579
+ code = 47 /*/*/;
580
+ if (code === 47 /*/*/) {
581
+ if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
582
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
583
+ if (res.length > 2) {
584
+ var lastSlashIndex = res.lastIndexOf('/');
585
+ if (lastSlashIndex !== res.length - 1) {
586
+ if (lastSlashIndex === -1) {
587
+ res = '';
588
+ lastSegmentLength = 0;
589
+ } else {
590
+ res = res.slice(0, lastSlashIndex);
591
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
592
+ }
593
+ lastSlash = i;
594
+ dots = 0;
595
+ continue;
596
+ }
597
+ } else if (res.length === 2 || res.length === 1) {
598
+ res = '';
599
+ lastSegmentLength = 0;
600
+ lastSlash = i;
601
+ dots = 0;
602
+ continue;
603
+ }
604
+ }
605
+ if (allowAboveRoot) {
606
+ if (res.length > 0)
607
+ res += '/..';
608
+ else
609
+ res = '..';
610
+ lastSegmentLength = 2;
611
+ }
612
+ } else {
613
+ if (res.length > 0)
614
+ res += '/' + path.slice(lastSlash + 1, i);
615
+ else
616
+ res = path.slice(lastSlash + 1, i);
617
+ lastSegmentLength = i - lastSlash - 1;
618
+ }
619
+ lastSlash = i;
620
+ dots = 0;
621
+ } else if (code === 46 /*.*/ && dots !== -1) {
622
+ ++dots;
623
+ } else {
624
+ dots = -1;
625
+ }
626
+ }
627
+ return res;
628
+ }
629
+
630
+ function _format(sep, pathObject) {
631
+ var dir = pathObject.dir || pathObject.root;
632
+ var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
633
+ if (!dir) {
634
+ return base;
635
+ }
636
+ if (dir === pathObject.root) {
637
+ return dir + base;
638
+ }
639
+ return dir + sep + base;
640
+ }
641
+
642
+ var posix = {
643
+ // path.resolve([from ...], to)
644
+ resolve: function resolve() {
645
+ var resolvedPath = '';
646
+ var resolvedAbsolute = false;
647
+ var cwd;
648
+
649
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
650
+ var path;
651
+ if (i >= 0)
652
+ path = arguments[i];
653
+ else {
654
+ if (cwd === undefined)
655
+ cwd = process.cwd();
656
+ path = cwd;
657
+ }
658
+
659
+ assertPath(path);
660
+
661
+ // Skip empty entries
662
+ if (path.length === 0) {
663
+ continue;
664
+ }
665
+
666
+ resolvedPath = path + '/' + resolvedPath;
667
+ resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
668
+ }
669
+
670
+ // At this point the path should be resolved to a full absolute path, but
671
+ // handle relative paths to be safe (might happen when process.cwd() fails)
672
+
673
+ // Normalize the path
674
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
675
+
676
+ if (resolvedAbsolute) {
677
+ if (resolvedPath.length > 0)
678
+ return '/' + resolvedPath;
679
+ else
680
+ return '/';
681
+ } else if (resolvedPath.length > 0) {
682
+ return resolvedPath;
683
+ } else {
684
+ return '.';
685
+ }
686
+ },
687
+
688
+ normalize: function normalize(path) {
689
+ assertPath(path);
690
+
691
+ if (path.length === 0) return '.';
692
+
693
+ var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
694
+ var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
695
+
696
+ // Normalize the path
697
+ path = normalizeStringPosix(path, !isAbsolute);
698
+
699
+ if (path.length === 0 && !isAbsolute) path = '.';
700
+ if (path.length > 0 && trailingSeparator) path += '/';
701
+
702
+ if (isAbsolute) return '/' + path;
703
+ return path;
704
+ },
705
+
706
+ isAbsolute: function isAbsolute(path) {
707
+ assertPath(path);
708
+ return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
709
+ },
710
+
711
+ join: function join() {
712
+ if (arguments.length === 0)
713
+ return '.';
714
+ var joined;
715
+ for (var i = 0; i < arguments.length; ++i) {
716
+ var arg = arguments[i];
717
+ assertPath(arg);
718
+ if (arg.length > 0) {
719
+ if (joined === undefined)
720
+ joined = arg;
721
+ else
722
+ joined += '/' + arg;
723
+ }
724
+ }
725
+ if (joined === undefined)
726
+ return '.';
727
+ return posix.normalize(joined);
728
+ },
729
+
730
+ relative: function relative(from, to) {
731
+ assertPath(from);
732
+ assertPath(to);
733
+
734
+ if (from === to) return '';
735
+
736
+ from = posix.resolve(from);
737
+ to = posix.resolve(to);
738
+
739
+ if (from === to) return '';
740
+
741
+ // Trim any leading backslashes
742
+ var fromStart = 1;
743
+ for (; fromStart < from.length; ++fromStart) {
744
+ if (from.charCodeAt(fromStart) !== 47 /*/*/)
745
+ break;
746
+ }
747
+ var fromEnd = from.length;
748
+ var fromLen = fromEnd - fromStart;
749
+
750
+ // Trim any leading backslashes
751
+ var toStart = 1;
752
+ for (; toStart < to.length; ++toStart) {
753
+ if (to.charCodeAt(toStart) !== 47 /*/*/)
754
+ break;
755
+ }
756
+ var toEnd = to.length;
757
+ var toLen = toEnd - toStart;
758
+
759
+ // Compare paths to find the longest common path from root
760
+ var length = fromLen < toLen ? fromLen : toLen;
761
+ var lastCommonSep = -1;
762
+ var i = 0;
763
+ for (; i <= length; ++i) {
764
+ if (i === length) {
765
+ if (toLen > length) {
766
+ if (to.charCodeAt(toStart + i) === 47 /*/*/) {
767
+ // We get here if `from` is the exact base path for `to`.
768
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
769
+ return to.slice(toStart + i + 1);
770
+ } else if (i === 0) {
771
+ // We get here if `from` is the root
772
+ // For example: from='/'; to='/foo'
773
+ return to.slice(toStart + i);
774
+ }
775
+ } else if (fromLen > length) {
776
+ if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
777
+ // We get here if `to` is the exact base path for `from`.
778
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
779
+ lastCommonSep = i;
780
+ } else if (i === 0) {
781
+ // We get here if `to` is the root.
782
+ // For example: from='/foo'; to='/'
783
+ lastCommonSep = 0;
784
+ }
785
+ }
786
+ break;
787
+ }
788
+ var fromCode = from.charCodeAt(fromStart + i);
789
+ var toCode = to.charCodeAt(toStart + i);
790
+ if (fromCode !== toCode)
791
+ break;
792
+ else if (fromCode === 47 /*/*/)
793
+ lastCommonSep = i;
794
+ }
795
+
796
+ var out = '';
797
+ // Generate the relative path based on the path difference between `to`
798
+ // and `from`
799
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
800
+ if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
801
+ if (out.length === 0)
802
+ out += '..';
803
+ else
804
+ out += '/..';
805
+ }
806
+ }
807
+
808
+ // Lastly, append the rest of the destination (`to`) path that comes after
809
+ // the common path parts
810
+ if (out.length > 0)
811
+ return out + to.slice(toStart + lastCommonSep);
812
+ else {
813
+ toStart += lastCommonSep;
814
+ if (to.charCodeAt(toStart) === 47 /*/*/)
815
+ ++toStart;
816
+ return to.slice(toStart);
817
+ }
818
+ },
819
+
820
+ _makeLong: function _makeLong(path) {
821
+ return path;
822
+ },
823
+
824
+ dirname: function dirname(path) {
825
+ assertPath(path);
826
+ if (path.length === 0) return '.';
827
+ var code = path.charCodeAt(0);
828
+ var hasRoot = code === 47 /*/*/;
829
+ var end = -1;
830
+ var matchedSlash = true;
831
+ for (var i = path.length - 1; i >= 1; --i) {
832
+ code = path.charCodeAt(i);
833
+ if (code === 47 /*/*/) {
834
+ if (!matchedSlash) {
835
+ end = i;
836
+ break;
837
+ }
838
+ } else {
839
+ // We saw the first non-path separator
840
+ matchedSlash = false;
841
+ }
842
+ }
843
+
844
+ if (end === -1) return hasRoot ? '/' : '.';
845
+ if (hasRoot && end === 1) return '//';
846
+ return path.slice(0, end);
847
+ },
848
+
849
+ basename: function basename(path, ext) {
850
+ if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
851
+ assertPath(path);
852
+
853
+ var start = 0;
854
+ var end = -1;
855
+ var matchedSlash = true;
856
+ var i;
857
+
858
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
859
+ if (ext.length === path.length && ext === path) return '';
860
+ var extIdx = ext.length - 1;
861
+ var firstNonSlashEnd = -1;
862
+ for (i = path.length - 1; i >= 0; --i) {
863
+ var code = path.charCodeAt(i);
864
+ if (code === 47 /*/*/) {
865
+ // If we reached a path separator that was not part of a set of path
866
+ // separators at the end of the string, stop now
867
+ if (!matchedSlash) {
868
+ start = i + 1;
869
+ break;
870
+ }
871
+ } else {
872
+ if (firstNonSlashEnd === -1) {
873
+ // We saw the first non-path separator, remember this index in case
874
+ // we need it if the extension ends up not matching
875
+ matchedSlash = false;
876
+ firstNonSlashEnd = i + 1;
877
+ }
878
+ if (extIdx >= 0) {
879
+ // Try to match the explicit extension
880
+ if (code === ext.charCodeAt(extIdx)) {
881
+ if (--extIdx === -1) {
882
+ // We matched the extension, so mark this as the end of our path
883
+ // component
884
+ end = i;
885
+ }
886
+ } else {
887
+ // Extension does not match, so our result is the entire path
888
+ // component
889
+ extIdx = -1;
890
+ end = firstNonSlashEnd;
891
+ }
892
+ }
893
+ }
894
+ }
895
+
896
+ if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
897
+ return path.slice(start, end);
898
+ } else {
899
+ for (i = path.length - 1; i >= 0; --i) {
900
+ if (path.charCodeAt(i) === 47 /*/*/) {
901
+ // If we reached a path separator that was not part of a set of path
902
+ // separators at the end of the string, stop now
903
+ if (!matchedSlash) {
904
+ start = i + 1;
905
+ break;
906
+ }
907
+ } else if (end === -1) {
908
+ // We saw the first non-path separator, mark this as the end of our
909
+ // path component
910
+ matchedSlash = false;
911
+ end = i + 1;
912
+ }
913
+ }
914
+
915
+ if (end === -1) return '';
916
+ return path.slice(start, end);
917
+ }
918
+ },
919
+
920
+ extname: function extname(path) {
921
+ assertPath(path);
922
+ var startDot = -1;
923
+ var startPart = 0;
924
+ var end = -1;
925
+ var matchedSlash = true;
926
+ // Track the state of characters (if any) we see before our first dot and
927
+ // after any path separator we find
928
+ var preDotState = 0;
929
+ for (var i = path.length - 1; i >= 0; --i) {
930
+ var code = path.charCodeAt(i);
931
+ if (code === 47 /*/*/) {
932
+ // If we reached a path separator that was not part of a set of path
933
+ // separators at the end of the string, stop now
934
+ if (!matchedSlash) {
935
+ startPart = i + 1;
936
+ break;
937
+ }
938
+ continue;
939
+ }
940
+ if (end === -1) {
941
+ // We saw the first non-path separator, mark this as the end of our
942
+ // extension
943
+ matchedSlash = false;
944
+ end = i + 1;
945
+ }
946
+ if (code === 46 /*.*/) {
947
+ // If this is our first dot, mark it as the start of our extension
948
+ if (startDot === -1)
949
+ startDot = i;
950
+ else if (preDotState !== 1)
951
+ preDotState = 1;
952
+ } else if (startDot !== -1) {
953
+ // We saw a non-dot and non-path separator before our dot, so we should
954
+ // have a good chance at having a non-empty extension
955
+ preDotState = -1;
956
+ }
957
+ }
958
+
959
+ if (startDot === -1 || end === -1 ||
960
+ // We saw a non-dot character immediately before the dot
961
+ preDotState === 0 ||
962
+ // The (right-most) trimmed path component is exactly '..'
963
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
964
+ return '';
965
+ }
966
+ return path.slice(startDot, end);
967
+ },
968
+
969
+ format: function format(pathObject) {
970
+ if (pathObject === null || typeof pathObject !== 'object') {
971
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
972
+ }
973
+ return _format('/', pathObject);
974
+ },
975
+
976
+ parse: function parse(path) {
977
+ assertPath(path);
978
+
979
+ var ret = { root: '', dir: '', base: '', ext: '', name: '' };
980
+ if (path.length === 0) return ret;
981
+ var code = path.charCodeAt(0);
982
+ var isAbsolute = code === 47 /*/*/;
983
+ var start;
984
+ if (isAbsolute) {
985
+ ret.root = '/';
986
+ start = 1;
987
+ } else {
988
+ start = 0;
989
+ }
990
+ var startDot = -1;
991
+ var startPart = 0;
992
+ var end = -1;
993
+ var matchedSlash = true;
994
+ var i = path.length - 1;
995
+
996
+ // Track the state of characters (if any) we see before our first dot and
997
+ // after any path separator we find
998
+ var preDotState = 0;
999
+
1000
+ // Get non-dir info
1001
+ for (; i >= start; --i) {
1002
+ code = path.charCodeAt(i);
1003
+ if (code === 47 /*/*/) {
1004
+ // If we reached a path separator that was not part of a set of path
1005
+ // separators at the end of the string, stop now
1006
+ if (!matchedSlash) {
1007
+ startPart = i + 1;
1008
+ break;
1009
+ }
1010
+ continue;
1011
+ }
1012
+ if (end === -1) {
1013
+ // We saw the first non-path separator, mark this as the end of our
1014
+ // extension
1015
+ matchedSlash = false;
1016
+ end = i + 1;
1017
+ }
1018
+ if (code === 46 /*.*/) {
1019
+ // If this is our first dot, mark it as the start of our extension
1020
+ if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
1021
+ } else if (startDot !== -1) {
1022
+ // We saw a non-dot and non-path separator before our dot, so we should
1023
+ // have a good chance at having a non-empty extension
1024
+ preDotState = -1;
1025
+ }
1026
+ }
1027
+
1028
+ if (startDot === -1 || end === -1 ||
1029
+ // We saw a non-dot character immediately before the dot
1030
+ preDotState === 0 ||
1031
+ // The (right-most) trimmed path component is exactly '..'
1032
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1033
+ if (end !== -1) {
1034
+ if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
1035
+ }
1036
+ } else {
1037
+ if (startPart === 0 && isAbsolute) {
1038
+ ret.name = path.slice(1, startDot);
1039
+ ret.base = path.slice(1, end);
1040
+ } else {
1041
+ ret.name = path.slice(startPart, startDot);
1042
+ ret.base = path.slice(startPart, end);
1043
+ }
1044
+ ret.ext = path.slice(startDot, end);
1045
+ }
1046
+
1047
+ if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
1048
+
1049
+ return ret;
1050
+ },
1051
+
1052
+ sep: '/',
1053
+ delimiter: ':',
1054
+ win32: null,
1055
+ posix: null
1056
+ };
1057
+
1058
+ posix.posix = posix;
1059
+
1060
+ var pathBrowserify = posix;
1061
+
1062
+ function ensure_list(obj) {
1063
+ const objArray = Array.isArray(obj) ? obj : [obj];
1064
+ return objArray;
1065
+ }
1066
+ function assureString(obj) {
1067
+ return String(obj);
1068
+ }
1069
+ function cleanArray(obj) {
1070
+ obj = assureArray(obj);
1071
+ return Array.from(new Set(obj));
1072
+ }
1073
+ function assureArray(input) {
1074
+ if (typeof input === 'string') {
1075
+ return [input];
1076
+ }
1077
+ if (Array.isArray(input)) {
1078
+ return input.map(item => assureString(item));
1079
+ }
1080
+ return [];
1081
+ }
1082
+ // Constrain T so 'in obj' is allowed
1083
+ function get_key_value(obj, key) {
1084
+ // we cast to any for the indexing, since TS can’t infer arbitrary string keys
1085
+ if (key in obj && obj[key] != null) {
1086
+ return obj[key];
1087
+ }
1088
+ return null;
1089
+ }
1090
+ function get(obj, keys, defaultValue = null) {
1091
+ const keyArray = assureArray(keys);
1092
+ if (!obj || keyArray.length === 0) {
1093
+ return defaultValue;
1094
+ }
1095
+ for (const key of keyArray) {
1096
+ const val = get_key_value(obj, key);
1097
+ if (val != null) {
1098
+ return val;
1099
+ }
1100
+ }
1101
+ return defaultValue;
1102
+ }
1103
+ function cleanText(input) {
1104
+ // Replace delimiters with spaces and split
1105
+ const str = assureString(input);
1106
+ const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
1107
+ return words;
1108
+ }
1109
+ function getCleanArray(obj) {
1110
+ obj = obj.split(/\s+/) // Split on any whitespace
1111
+ .filter((item) => typeof item === 'string' && item !== '');
1112
+ // Get basename
1113
+ // Remove duplicates using Set
1114
+ const uniqueWords = cleanArray(obj);
1115
+ return uniqueWords;
1116
+ }
1117
+ function isStrInString(obj, string) {
1118
+ const obj_str = assureString(obj).toLowerCase;
1119
+ string = assureString(string).toLowerCase;
1120
+ if (string.includes(obj_str)) {
1121
+ return true;
1122
+ }
1123
+ return false;
1124
+ }
1125
+ function getChar(i, string) {
1126
+ if (string.length >= i) {
1127
+ return assureString(string)[i];
1128
+ }
1129
+ }
1130
+ function isType(obj, type) {
1131
+ if (typeof obj === type) {
1132
+ return true;
1133
+ }
1134
+ return false;
1135
+ }
1136
+ function getNums() {
1137
+ return '0123456789';
1138
+ }
1139
+ function isNum(obj) {
1140
+ const is_num = isType(obj, 'number');
1141
+ if (is_num) {
1142
+ return is_num;
1143
+ }
1144
+ return isStrInString(obj, getNums());
1145
+ }
1146
+ function ensure_number(object) {
1147
+ if (isNum(object)) {
1148
+ return Number(object);
1149
+ }
1150
+ let nuString = '';
1151
+ const object_str = assureString(object);
1152
+ const str_spl = object_str.split('');
1153
+ for (const obj in str_spl) {
1154
+ if (isNum(obj)) {
1155
+ nuString += obj;
1156
+ }
1157
+ }
1158
+ if (nuString != '') {
1159
+ return Number(nuString);
1160
+ }
1161
+ return null;
1162
+ }
1163
+ function getAlphas() {
1164
+ return 'abcdefghijklmnopqrstuvwxyz';
1165
+ }
1166
+ function getAlphaNum(obj) {
1167
+ const is_num = isNum(obj);
1168
+ const alphas = getAlphas();
1169
+ if (is_num) {
1170
+ return getChar(obj, alphas);
1171
+ }
1172
+ if (isStrInString(obj, alphas)) {
1173
+ return getChar(obj, alphas);
1174
+ }
1175
+ }
1176
+
1177
+ function getSubstring(obj, maxLength = null, minLength = null) {
1178
+ const objLength = obj.length;
1179
+ const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
1180
+ const effectiveMinLength = minLength !== null && minLength !== void 0 ? minLength : 0;
1181
+ // Ensure bounds are valid
1182
+ const clampedMaxLength = Math.min(Math.max(effectiveMaxLength, 0), objLength);
1183
+ const clampedMinLength = Math.min(Math.max(effectiveMinLength, 0), objLength);
1184
+ // If minLength exceeds maxLength, return empty string or adjust logic as needed
1185
+ if (clampedMinLength >= clampedMaxLength) {
1186
+ return '';
1187
+ }
1188
+ return obj.substring(clampedMinLength, clampedMaxLength);
1189
+ }
1190
+ function truncateString(obj, maxLength = 20) {
1191
+ const objLength = obj.length;
1192
+ if (objLength > maxLength && maxLength) {
1193
+ obj = getSubstring(obj, maxLength) + '...';
1194
+ }
1195
+ return obj;
1196
+ }
1197
+ function capitalize_str(string) {
1198
+ string = assureString(string);
1199
+ const string_len = string.length;
1200
+ let init_char = string.toUpperCase();
1201
+ if (string_len > 0) {
1202
+ init_char = string[0].toUpperCase();
1203
+ }
1204
+ let rest_chars = '';
1205
+ if (string_len > 1) {
1206
+ rest_chars = string.slice(1).toLowerCase();
1207
+ }
1208
+ const fin_chars = `${init_char}${rest_chars}`;
1209
+ return fin_chars;
1210
+ }
1211
+ function capitalize(string) {
1212
+ let nu_string = '';
1213
+ string = assureString(string);
1214
+ let objs = string.replace('-', '_').split('_');
1215
+ for (const obj of objs) {
1216
+ let str_obj = capitalize_str(obj);
1217
+ nu_string = `${nu_string} ${str_obj}`;
1218
+ }
1219
+ return eatAll(nu_string, [' ']);
1220
+ }
1221
+ // string_utils/src/string_utils.ts
1222
+ function stripPrefixes(str, bases = []) {
1223
+ /* NEW: coerce whatever arrives into a string */
1224
+ str = String(str);
1225
+ const prefixes = (Array.isArray(bases) ? bases : [bases])
1226
+ .filter(Boolean)
1227
+ .sort((a, b) => b.length - a.length); // longest first
1228
+ let changed = true;
1229
+ while (changed) {
1230
+ changed = false;
1231
+ for (const prefix of prefixes) {
1232
+ if (str.startsWith(prefix)) {
1233
+ str = str.slice(prefix.length);
1234
+ changed = true;
1235
+ break; // restart from longest prefix
1236
+ }
1237
+ }
1238
+ }
1239
+ return str;
1240
+ }
1241
+ /**
1242
+ * Removes characters from the beginning of the string
1243
+ * if they are found in the list of characters.
1244
+ *
1245
+ * @param str - The input string.
1246
+ * @param listObjects - A string or an array of characters to remove.
1247
+ * @returns The modified string.
1248
+ */
1249
+ function eatInner(str, listObjects) {
1250
+ if (!Array.isArray(listObjects)) {
1251
+ listObjects = [listObjects];
1252
+ }
1253
+ // Ensure str is a string
1254
+ str = String(str);
1255
+ // Remove characters from the beginning while they are in listObjects
1256
+ while (str.length > 0 && listObjects.includes(str[0])) {
1257
+ str = str.slice(1);
1258
+ }
1259
+ return str;
1260
+ }
1261
+ /**
1262
+ * Removes characters from the end of the string
1263
+ * if they are found in the list of characters.
1264
+ *
1265
+ * @param str - The input string.
1266
+ * @param listObjects - A string or an array of characters to remove.
1267
+ * @returns The modified string.
1268
+ */
1269
+ function eatOuter(str, listObjects) {
1270
+ if (!Array.isArray(listObjects)) {
1271
+ listObjects = [listObjects];
1272
+ }
1273
+ // Ensure str is a string
1274
+ str = String(str);
1275
+ // Remove characters from the end while they are in listObjects
1276
+ while (str.length > 0 && listObjects.includes(str[str.length - 1])) {
1277
+ str = str.slice(0, -1);
1278
+ }
1279
+ return str;
1280
+ }
1281
+ /**
1282
+ * Removes characters from both the beginning and the end of the string
1283
+ * if they are found in the list of characters.
1284
+ *
1285
+ * @param str - The input string.
1286
+ * @param listObjects - A string or an array of characters to remove.
1287
+ * @returns The modified string.
1288
+ */
1289
+ function eatAll(str, listObjects) {
1290
+ return eatOuter(eatInner(str, listObjects), listObjects);
1291
+ }
1292
+ function eatEnd(obj, endings = ['/']) {
1293
+ let result = obj;
1294
+ let modified = true;
1295
+ while (modified) {
1296
+ modified = false;
1297
+ for (const ending of endings) {
1298
+ if (result.endsWith(ending)) {
1299
+ result = result.slice(0, -ending.length);
1300
+ modified = true;
1301
+ break;
1302
+ }
1303
+ }
1304
+ }
1305
+ return result;
1306
+ }
1307
+ function tryParse(obj) {
1308
+ try {
1309
+ obj = JSON.stringify(obj);
1310
+ }
1311
+ catch (err) {
1312
+ try {
1313
+ obj = JSON.parse(obj);
1314
+ }
1315
+ catch (err) {
1316
+ }
1317
+ }
1318
+ return obj;
1319
+ }
1320
+ function create_list_string(array_obj) {
1321
+ let string = '';
1322
+ for (const obj in array_obj) {
1323
+ const array_value = array_obj[obj];
1324
+ const parsed_value = tryParse(array_value);
1325
+ string += `${obj} == ${parsed_value}\n`;
1326
+ }
1327
+ return string;
1328
+ }
1329
+
1330
+ /**
1331
+ * In the browser we already have a WHATWG URL constructor on window.
1332
+ * Here we re-export it as “url” so other modules can import it.
1333
+ */
1334
+ /**
1335
+ * Minimal fileURLToPath implementation for browser-side code.
1336
+ * If you only ever need to strip off “file://” in development, this is enough.
1337
+ */
1338
+ function fileURLToPath(fileUrl) {
1339
+ // e.g. fileUrl = "file:///Users/foo/bar.txt"
1340
+ try {
1341
+ const u = new URL(fileUrl);
1342
+ return u.pathname;
1343
+ }
1344
+ catch (_a) {
1345
+ // fallback: just strip file://
1346
+ return fileUrl.replace(/^file:\/\//, '');
1347
+ }
1348
+ }
1349
+ function getAbsolutePath() {
1350
+ if (typeof window !== 'undefined')
1351
+ return '';
1352
+ return fileURLToPath(import.meta.url);
1353
+ }
1354
+
1355
+ // path_utils.browser.ts
1356
+ function get_dirname(filePath) {
1357
+ if (!filePath)
1358
+ return '';
1359
+ return pathBrowserify.dirname(filePath);
1360
+ }
1361
+ function get_basename(filePath) {
1362
+ if (!filePath)
1363
+ return '';
1364
+ return pathBrowserify.basename(filePath);
1365
+ }
1366
+ function get_filename(file_path) {
1367
+ const ext = pathBrowserify.extname(file_path);
1368
+ return pathBrowserify.basename(file_path, ext);
1369
+ }
1370
+ function get_extname(filePath) {
1371
+ if (!filePath)
1372
+ return '';
1373
+ return pathBrowserify.extname(filePath);
1374
+ }
1375
+ function get_splitext(filePath) {
1376
+ if (!filePath)
1377
+ return { filename: '', extname: '' };
1378
+ const ext = pathBrowserify.extname(filePath);
1379
+ // Get the basename without the extension
1380
+ const filename = pathBrowserify.basename(filePath, ext);
1381
+ return { filename, ext };
1382
+ }
1383
+ /**
1384
+ * Join multiple path segments, normalizing leading/trailing slashes.
1385
+ *
1386
+ * Usage:
1387
+ * make_path('/foo','bar','baz')
1388
+ * make_path(['/foo','bar','baz'])
1389
+ */
1390
+ function make_path(...paths) {
1391
+ // If someone passed a single array, unwrap it:
1392
+ const pathArray = (paths.length === 1 && Array.isArray(paths[0])
1393
+ ? paths[0]
1394
+ : paths);
1395
+ let real_path = '';
1396
+ for (let i = 0; i < pathArray.length; i++) {
1397
+ let segment = pathArray[i];
1398
+ if (i === 0) {
1399
+ real_path = segment;
1400
+ }
1401
+ else {
1402
+ // remove any leading slash on this segment
1403
+ segment = segment.replace(/^\/+/, '');
1404
+ // remove any trailing slash on the accumulator
1405
+ real_path = real_path.replace(/\/+$/, '');
1406
+ real_path = `${real_path}/${segment}`;
1407
+ }
1408
+ }
1409
+ return real_path;
1410
+ }
1411
+ function sanitizeFilename(filename) {
1412
+ return filename
1413
+ .toLowerCase()
1414
+ .replace(/\s+|-/g, '-') // Replace spaces and hyphens with single hyphen
1415
+ .replace(/_/g, '-') // Replace underscores with hyphens
1416
+ .replace(/[^a-z0-9-.]/g, '') // Remove all non-alphanumeric chars except hyphen and dot
1417
+ .replace(/-+/g, '-') // Collapse multiple hyphens into one
1418
+ .replace(/^-|-$/, ''); // Remove leading/trailing hyphens
1419
+ }
1420
+ function make_sanitized_path(...paths) {
1421
+ let real_path = '';
1422
+ for (let i = 0; i < paths.length; i++) {
1423
+ const sanitized = sanitizeFilename(eatInner(paths[i], ['/']));
1424
+ if (i === 0) {
1425
+ real_path = sanitized;
1426
+ }
1427
+ else if (sanitized) { // Only append if there's a non-empty segment
1428
+ real_path = `${real_path}/${sanitized}`;
1429
+ }
1430
+ }
1431
+ return real_path || '';
1432
+ }
1433
+ function normalizeUrl(base, p) {
1434
+ if (!p)
1435
+ return base;
1436
+ const cleanBase = base.replace(/\/+$/, ''); // regex literal
1437
+ const cleanPath = p.replace(/^\/+/, '');
1438
+ // collapse multiple “//” into one, but keep the “://” after protocol
1439
+ return `${cleanBase}/${cleanPath}`.replace(/([^:])\/{2,}/g, '$1/');
1440
+ }
1441
+
1442
+ /**
1443
+ * Returns the absolute path of the current file.
1444
+ */
1445
+ function getAbsDir() {
1446
+ return get_dirname(getAbsolutePath());
1447
+ }
1448
+ function getAbsPath(subPath) {
1449
+ return make_path(getAbsDir(), subPath);
1450
+ }
1451
+
1452
+ function getFunctionsDir() {
1453
+ return get_dirname(getAbsDir());
1454
+ }
1455
+ function geAuthsUtilsDirectory() {
1456
+ return make_path(getFunctionsDir(), 'auths');
1457
+ }
1458
+ function geBackupsUtilsDirectory() {
1459
+ return make_path(getFunctionsDir(), 'backups');
1460
+ }
1461
+ function geConstantsUtilsDirectory() {
1462
+ return make_path(getFunctionsDir(), 'constants');
1463
+ }
1464
+ function geEnvUtilsDirectory() {
1465
+ return make_path(getFunctionsDir(), 'env_utils');
1466
+ }
1467
+ function geFetchUtilsDirectory() {
1468
+ return make_path(getFunctionsDir(), 'fetch_utils');
1469
+ }
1470
+ function geFileUtilsDirectory() {
1471
+ return make_path(getFunctionsDir(), 'file_utils');
1472
+ }
1473
+ function gePathUtilsDirectory() {
1474
+ return make_path(getFunctionsDir(), 'path_utils');
1475
+ }
1476
+ function geStringUtilsDirectory() {
1477
+ return make_path(getFunctionsDir(), 'string_utils');
1478
+ }
1479
+ function geTypeUtilsDirectory() {
1480
+ return make_path(getFunctionsDir(), 'type_utils');
1481
+ }
1482
+
1483
+ function getSrcDir() {
1484
+ return get_dirname(getFunctionsDir());
1485
+ }
1486
+ function geStaticDirectory() {
1487
+ return make_path(getSrcDir(), 'static');
1488
+ }
1489
+ function getLibUtilsDirectory() {
1490
+ return make_path(getSrcDir(), 'lib');
1491
+ }
1492
+ function getHooksUtilsDirectory() {
1493
+ return make_path(getSrcDir(), 'hooks');
1494
+ }
1495
+ function getFunctionsUtilsDirectory() {
1496
+ return make_path(getSrcDir(), 'functions');
1497
+ }
1498
+ function getComponentsUtilsDirectory() {
1499
+ return make_path(getSrcDir(), 'components');
1500
+ }
1501
+
1502
+ function getBaseDir() {
1503
+ return get_dirname(getSrcDir());
1504
+ }
1505
+ function getPublicDir() {
1506
+ return make_path(getBaseDir(), 'public');
1507
+ }
1508
+ function getDistDir() {
1509
+ return make_path(getBaseDir(), 'dist');
1510
+ }
1511
+ function getEnvDir() {
1512
+ return make_path(getBaseDir(), '.env');
1513
+ }
1514
+
1515
+ function getEnvPath(string = '.env') {
1516
+ return make_path(getEnvDir(), string);
1517
+ }
1518
+ function getDbConfigsPath() {
1519
+ return make_path(getBaseDir(), 'dbConfigs');
1520
+ }
1521
+ function getSchemasPath() {
1522
+ return make_path(getDbConfigsPath(), 'schemas');
1523
+ }
1524
+ function getSchemasDirPath(subPath) {
1525
+ return make_path(getSchemasPath(), subPath);
1526
+ }
1527
+
1528
+ // src/functions/rndm_utils/utils.ts
1529
+ function alertit(obj = null) {
1530
+ let msg;
1531
+ try {
1532
+ msg = JSON.stringify(obj);
1533
+ }
1534
+ catch (_a) {
1535
+ // If JSON.stringify fails (circular refs, etc.), fall back to a simple string
1536
+ msg = String(obj);
1537
+ }
1538
+ alert(msg);
1539
+ }
1540
+
1541
+ function Button(_a) {
1542
+ var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
1543
+ 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';
1544
+ const variantStyles = {
1545
+ default: '',
1546
+ icon: 'p-1 bg-transparent hover:bg-gray-100',
1547
+ primary: 'text-white',
1548
+ secondary: '',
1549
+ };
1550
+ const palette = {
1551
+ gray: variant === 'primary'
1552
+ ? 'bg-gray-600 hover:bg-gray-700 focus:ring-gray-500'
1553
+ : 'bg-gray-200 hover:bg-gray-300 focus:ring-gray-400',
1554
+ green: 'bg-green-600 text-white hover:bg-green-700 focus:ring-green-500',
1555
+ blue: variant === 'primary'
1556
+ ? 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500'
1557
+ : 'bg-blue-200 hover:bg-blue-300 focus:ring-blue-400',
1558
+ };
1559
+ return (jsx("button", Object.assign({ className: `${base} ${variantStyles[variant]} ${palette[color]} ${className}` }, rest, { children: children })));
1560
+ }
1561
+
1562
+ function Checkbox(_a) {
1563
+ var { label } = _a, rest = __rest(_a, ["label"]);
1564
+ return (jsxs("label", { className: 'flex items-center gap-2 mb-4', children: [jsx("input", Object.assign({ type: 'checkbox' }, rest)), jsx("span", { children: label })] }));
1565
+ }
1566
+
1567
+ function Input(_a) {
1568
+ var { label, trailing } = _a, rest = __rest(_a, ["label", "trailing"]);
1569
+ 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] })] }));
1570
+ }
1571
+
1572
+ function Spinner() {
1573
+ return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
1574
+ }
1575
+
1576
+ // src/functions/config_utils/src/config_utils.ts
1577
+ /**
1578
+ * Attempt to load config.json if present, otherwise return empty object.
1579
+ */
1580
+ function getConfigJson() {
1581
+ return __awaiter(this, void 0, void 0, function* () {
1582
+ try {
1583
+ return (yield readJsonFile('config.json')) || {};
1584
+ }
1585
+ catch (_a) {
1586
+ return {};
1587
+ }
1588
+ });
1589
+ }
1590
+
1591
+ /**
1592
+ * Processes keywords by checking if keywords is a string and splitting it.
1593
+ * Then cleans each keyword using `eatAll` with a set of characters to remove.
1594
+ *
1595
+ * @param keywords - The keywords as a comma-separated string or as an array.
1596
+ * @returns An array of cleaned keywords.
1597
+ */
1598
+ function processKeywords(keywords) {
1599
+ let keywordArray;
1600
+ // If keywords is a string, split it on commas
1601
+ if (typeof keywords === "string") {
1602
+ keywordArray = keywords.split(",");
1603
+ }
1604
+ else {
1605
+ keywordArray = keywords;
1606
+ }
1607
+ // Clean each keyword by removing unwanted characters
1608
+ return keywordArray.map(keyword => eatAll(keyword, [",", "\n", "\t", " ", "#"]));
1609
+ }
1610
+ /**
1611
+ * Constructs a keyword string where each keyword is prefixed with a hash (#).
1612
+ *
1613
+ * @param keywords - An array of keywords.
1614
+ * @returns A string with each keyword prefixed by '#'.
1615
+ */
1616
+ function get_keyword_string(keywords) {
1617
+ keywords = processKeywords(keywords);
1618
+ let allString = "";
1619
+ for (const keyword of keywords) {
1620
+ allString += ` #${keyword}`;
1621
+ }
1622
+ return allString;
1623
+ }
1624
+
1625
+ 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, ensure_number, 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 };
1626
+ //# sourceMappingURL=index.js.map