@putkoff/abstract-utilities 1.0.50 → 1.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +504 -477
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +479 -454
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +78 -93
- package/dist/types/client/auth/index.d.ts +1 -0
- package/dist/types/client/auth/src/index.d.ts +1 -0
- package/dist/types/client/auth/src/token_client.d.ts +15 -0
- package/dist/types/client/fetch/src/fetch_auth.d.ts +3 -0
- package/dist/types/client/fetch/src/index.d.ts +1 -0
- package/dist/types/client/index.d.ts +2 -0
- package/dist/types/client/ui_utils/index.d.ts +1 -0
- package/dist/types/client/ui_utils/src/button.d.ts +6 -0
- package/dist/types/client/ui_utils/src/checkbox.d.ts +4 -0
- package/dist/types/client/ui_utils/src/index.d.ts +4 -0
- package/dist/types/client/ui_utils/src/input.d.ts +5 -0
- package/dist/types/client/ui_utils/src/spinner.d.ts +1 -0
- package/dist/types/functions/auth_utils/imports.d.ts +0 -0
- package/dist/types/functions/auth_utils/index.d.ts +0 -0
- package/dist/types/functions/auth_utils/src/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/jwt_core.d.ts +7 -0
- package/dist/types/functions/auth_utils/src/token_utils (Copy).d.ts +7 -0
- package/dist/types/functions/auth_utils/src/token_utils.d.ts +0 -0
- package/dist/types/functions/config_utils/imports.d.ts +0 -0
- package/dist/types/functions/config_utils/index.d.ts +0 -0
- package/dist/types/functions/config_utils/src/config_utils.d.ts +0 -0
- package/dist/types/functions/config_utils/src/index.d.ts +0 -0
- package/dist/types/functions/constants_utils/index.d.ts +0 -0
- package/dist/types/functions/constants_utils/src/constants.d.ts +0 -0
- package/dist/types/functions/constants_utils/src/index.d.ts +0 -0
- package/dist/types/functions/env_utils/imports.d.ts +0 -0
- package/dist/types/functions/env_utils/index.d.ts +0 -0
- package/dist/types/functions/env_utils/src/index.d.ts +0 -0
- package/dist/types/functions/env_utils/src/window_utils.d.ts +0 -0
- package/dist/types/functions/fetch_utils/imports.d.ts +0 -1
- package/dist/types/functions/fetch_utils/index.d.ts +0 -0
- package/dist/types/functions/fetch_utils/src/fetch_utils.d.ts +0 -0
- package/dist/types/functions/fetch_utils/src/index.d.ts +0 -0
- package/dist/types/functions/fetch_utils/src/url_utils.d.ts +1 -0
- package/dist/types/functions/fetch_utils/src/utils.d.ts +0 -0
- package/dist/types/functions/index.d.ts +0 -2
- package/dist/types/functions/math_utils/constants.d.ts +0 -0
- package/dist/types/functions/math_utils/conversions.d.ts +0 -0
- package/dist/types/functions/math_utils/index.d.ts +0 -0
- package/dist/types/functions/math_utils/safe_math.d.ts +0 -0
- package/dist/types/functions/math_utils/scaleInterfaces.d.ts +0 -0
- package/dist/types/functions/path_utils/imports.d.ts +0 -0
- package/dist/types/functions/path_utils/index.d.ts +0 -0
- package/dist/types/functions/path_utils/src/base_dirs.d.ts +0 -0
- package/dist/types/functions/path_utils/src/function_dirs.d.ts +0 -0
- package/dist/types/functions/path_utils/src/index.d.ts +0 -0
- package/dist/types/functions/path_utils/src/misc_dirs.d.ts +0 -0
- package/dist/types/functions/path_utils/src/path_utils.d.ts +42 -6
- package/dist/types/functions/path_utils/src/paths.d.ts +0 -0
- package/dist/types/functions/path_utils/src/src_dirs.d.ts +0 -0
- package/dist/types/functions/read_utils/imports.d.ts +0 -0
- package/dist/types/functions/read_utils/index.d.ts +0 -0
- package/dist/types/functions/read_utils/src/index.d.ts +0 -0
- package/dist/types/functions/read_utils/src/utils.d.ts +0 -0
- package/dist/types/functions/rndm_utils/imports.d.ts +0 -0
- package/dist/types/functions/rndm_utils/index.d.ts +0 -0
- package/dist/types/functions/rndm_utils/src/index.d.ts +0 -0
- package/dist/types/functions/rndm_utils/src/utils.d.ts +0 -0
- package/dist/types/functions/safe_utils/imports.d.ts +0 -0
- package/dist/types/functions/safe_utils/index.d.ts +0 -0
- package/dist/types/functions/safe_utils/src/index.d.ts +0 -0
- package/dist/types/functions/safe_utils/src/safe_document.d.ts +0 -0
- package/dist/types/functions/safe_utils/src/safe_globals.d.ts +0 -0
- package/dist/types/functions/safe_utils/src/safe_storage.d.ts +0 -0
- package/dist/types/functions/safe_utils/src/safe_window.d.ts +0 -0
- package/dist/types/functions/string_utils/index.d.ts +0 -0
- package/dist/types/functions/string_utils/src/index.d.ts +0 -0
- package/dist/types/functions/string_utils/src/string_utils.d.ts +12 -28
- package/dist/types/functions/type_utils/imports.d.ts +0 -0
- package/dist/types/functions/type_utils/index.d.ts +0 -0
- package/dist/types/functions/type_utils/src/clean_utils.d.ts +0 -0
- package/dist/types/functions/type_utils/src/ensure_utils.d.ts +22 -14
- package/dist/types/functions/type_utils/src/imports.d.ts +0 -0
- package/dist/types/functions/type_utils/src/index.d.ts +0 -0
- package/dist/types/functions/type_utils/src/json_utils.d.ts +0 -0
- package/dist/types/functions/type_utils/src/list_utils.d.ts +4 -0
- package/dist/types/functions/type_utils/src/mime_utils.d.ts +0 -0
- package/dist/types/functions/type_utils/src/type_utils.d.ts +0 -0
- package/dist/types/functions/ui_utils/imports.d.ts +0 -0
- package/dist/types/functions/ui_utils/index.d.ts +0 -0
- package/dist/types/functions/ui_utils/src/button.d.ts +0 -0
- package/dist/types/functions/ui_utils/src/checkbox.d.ts +0 -0
- package/dist/types/functions/ui_utils/src/index.d.ts +0 -0
- package/dist/types/functions/ui_utils/src/input.d.ts +0 -0
- package/dist/types/functions/ui_utils/src/spinner.d.ts +0 -0
- package/dist/types/functions/variable_utils/imports.d.ts +0 -0
- package/dist/types/functions/variable_utils/index.d.ts +0 -0
- package/dist/types/functions/variable_utils/src/index.d.ts +0 -0
- package/dist/types/functions/variable_utils/src/variable_utils.d.ts +0 -0
- package/dist/types/index.d.ts +0 -0
- package/dist/types/types/index.d.ts +0 -0
- package/dist/types/types/src/ChangePassword.d.ts +0 -0
- package/dist/types/types/src/Files.d.ts +0 -0
- package/dist/types/types/src/index.d.ts +0 -0
- package/dist/types/types/src/login.d.ts +0 -0
- package/dist/types/types/src/logout.d.ts +0 -0
- package/dist/types/types/src/utils.d.ts +0 -0
- package/dist/types/ui/Navbar/DropDowns/DropDownElements.d.ts +8 -0
- package/dist/types/ui/Navbar/DropDowns/ForumsDropdown.d.ts +2 -0
- package/dist/types/ui/Navbar/DropDowns/index.d.ts +3 -0
- package/dist/types/ui/Navbar/NavBar.d.ts +8 -0
- package/dist/types/ui/Navbar/index.d.ts +3 -0
- package/dist/types/ui/index.d.ts +1 -0
- package/dist/types/utils/imports.d.ts +0 -0
- package/dist/types/utils/index.d.ts +0 -0
- package/dist/types/utils/src/Input.d.ts +0 -0
- package/dist/types/utils/src/config.d.ts +0 -0
- package/dist/types/utils/src/index.d.ts +0 -0
- package/package.json +11 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
1
|
function _mergeNamespaces(n, m) {
|
|
5
2
|
m.forEach(function (e) {
|
|
6
3
|
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
@@ -16,167 +13,6 @@ function _mergeNamespaces(n, m) {
|
|
|
16
13
|
return Object.freeze(n);
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
function getSafeDocument() {
|
|
20
|
-
return typeof document !== 'undefined' ? document : undefined;
|
|
21
|
-
}
|
|
22
|
-
function getDocumentProp(...keys) {
|
|
23
|
-
let obj = getSafeDocument();
|
|
24
|
-
for (const k of keys) {
|
|
25
|
-
if (obj == null || typeof obj !== 'object')
|
|
26
|
-
return undefined;
|
|
27
|
-
obj = obj[k];
|
|
28
|
-
}
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
34
|
-
* Returns `undefined` if any step is missing.
|
|
35
|
-
*/
|
|
36
|
-
function safeGlobalProp(...path) {
|
|
37
|
-
let obj = globalThis;
|
|
38
|
-
for (const key of path) {
|
|
39
|
-
if (obj == null || typeof obj !== "object" || !(key in obj)) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
obj = obj[key];
|
|
43
|
-
}
|
|
44
|
-
return obj;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Returns `window` if running in a browser, otherwise `undefined`.
|
|
49
|
-
*/
|
|
50
|
-
function getSafeLocalStorage() {
|
|
51
|
-
if (typeof window === 'undefined')
|
|
52
|
-
return undefined;
|
|
53
|
-
try {
|
|
54
|
-
return window.localStorage;
|
|
55
|
-
}
|
|
56
|
-
catch (_a) {
|
|
57
|
-
return undefined; // e.g. Safari private-mode block
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Call a Storage method by name, silencing any errors or missing storage.
|
|
62
|
-
*
|
|
63
|
-
* @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
|
|
64
|
-
* @param args The arguments you’d normally pass to that method.
|
|
65
|
-
* @returns The method’s return value, or undefined if storage/method isn’t available.
|
|
66
|
-
*/
|
|
67
|
-
function callStorage(method, ...args) {
|
|
68
|
-
const storage = getSafeLocalStorage();
|
|
69
|
-
if (!storage)
|
|
70
|
-
return undefined;
|
|
71
|
-
const fn = storage[method];
|
|
72
|
-
if (typeof fn !== 'function')
|
|
73
|
-
return undefined;
|
|
74
|
-
try {
|
|
75
|
-
// @ts-ignore – TS can’t infer that this is callable
|
|
76
|
-
return fn.apply(storage, args);
|
|
77
|
-
}
|
|
78
|
-
catch (_a) {
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
|
|
84
|
-
* Returns `undefined` on any error.
|
|
85
|
-
*/
|
|
86
|
-
function safeStorage(storageName, method, ...args) {
|
|
87
|
-
try {
|
|
88
|
-
const store = safeGlobalProp(storageName);
|
|
89
|
-
if (!store || typeof store[method] !== "function")
|
|
90
|
-
return undefined;
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
return store[method](...args);
|
|
93
|
-
}
|
|
94
|
-
catch (_a) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Returns the global window object if it exists, otherwise undefined.
|
|
101
|
-
*/
|
|
102
|
-
function getSafeWindow() {
|
|
103
|
-
return typeof window !== 'undefined' ? window : undefined;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Safely call a method on window by name.
|
|
107
|
-
*
|
|
108
|
-
* @param method The Window method to call (e.g. "alert", "open", etc.).
|
|
109
|
-
* @param args Arguments to pass to that method.
|
|
110
|
-
* @returns The method’s return value, or undefined if
|
|
111
|
-
* window/method isn’t available or throws.
|
|
112
|
-
*/
|
|
113
|
-
function callWindowMethod(method, ...args) {
|
|
114
|
-
const w = getSafeWindow();
|
|
115
|
-
if (!w)
|
|
116
|
-
return undefined;
|
|
117
|
-
const fn = w[method];
|
|
118
|
-
if (typeof fn !== 'function')
|
|
119
|
-
return undefined;
|
|
120
|
-
try {
|
|
121
|
-
// cast to any so TS doesn’t complain about apply/invoke
|
|
122
|
-
return fn(...args);
|
|
123
|
-
}
|
|
124
|
-
catch (_a) {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/** implementation */
|
|
129
|
-
function getWindowProp(...keys) {
|
|
130
|
-
let obj = getSafeWindow();
|
|
131
|
-
for (const k of keys) {
|
|
132
|
-
if (obj == null || typeof obj !== 'object')
|
|
133
|
-
return undefined;
|
|
134
|
-
obj = obj[k];
|
|
135
|
-
}
|
|
136
|
-
return obj;
|
|
137
|
-
}
|
|
138
|
-
function getWindowHost() {
|
|
139
|
-
return getWindowProp('location', 'host');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
***Changes**:
|
|
144
|
-
*- Updated import path for `InputProps` to `../../types/interfaces`.
|
|
145
|
-
*
|
|
146
|
-
*3. **Token Utilities** (`src/functions/auth/token_utils.ts`):
|
|
147
|
-
* Copy from `/var/www/abstractendeavors/my-login-app/src/functions/auth_utils/token_utils.ts`.
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
/** Read raw JWT from LocalStorage (or null if absent) */
|
|
151
|
-
function getToken() {
|
|
152
|
-
return callStorage('getItem', 'token');
|
|
153
|
-
}
|
|
154
|
-
function isLoggedIn() {
|
|
155
|
-
const tok = getToken();
|
|
156
|
-
return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Add a Bearer Authorization header.
|
|
160
|
-
* A shallow copy of headers is returned so callers can keep chaining.
|
|
161
|
-
*/
|
|
162
|
-
function getAuthorizationHeader(headers = {}, token = null) {
|
|
163
|
-
token = token !== null && token !== void 0 ? token : getToken();
|
|
164
|
-
headers = headers || {};
|
|
165
|
-
if (token)
|
|
166
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
167
|
-
return Object.assign({}, headers);
|
|
168
|
-
}
|
|
169
|
-
/** Throw + redirect if there’s no valid token; otherwise return it. */
|
|
170
|
-
function requireToken() {
|
|
171
|
-
const tok = getToken();
|
|
172
|
-
if (!tok || isTokenExpired(tok)) {
|
|
173
|
-
console.warn("→ No token or expired token, redirecting to login…");
|
|
174
|
-
localStorage.removeItem("token");
|
|
175
|
-
window.location.href = '/';
|
|
176
|
-
throw new Error("Redirecting to login…");
|
|
177
|
-
}
|
|
178
|
-
return tok;
|
|
179
|
-
}
|
|
180
16
|
/** True if token is structurally bad or its exp ≤ now. */
|
|
181
17
|
function isTokenExpired(token) {
|
|
182
18
|
try {
|
|
@@ -187,47 +23,6 @@ function isTokenExpired(token) {
|
|
|
187
23
|
return true; // treat malformed token as expired
|
|
188
24
|
}
|
|
189
25
|
}
|
|
190
|
-
/** Convenience wrapper: return username from the JWT (or null). */
|
|
191
|
-
function currentUsername() {
|
|
192
|
-
const tok = getToken();
|
|
193
|
-
if (!tok)
|
|
194
|
-
return null;
|
|
195
|
-
try {
|
|
196
|
-
const { username } = decodeJwt(tok);
|
|
197
|
-
return username !== null && username !== void 0 ? username : null;
|
|
198
|
-
}
|
|
199
|
-
catch (_a) {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function currentUsernames() {
|
|
204
|
-
var _a;
|
|
205
|
-
const tok = getToken();
|
|
206
|
-
if (!tok)
|
|
207
|
-
return null;
|
|
208
|
-
try {
|
|
209
|
-
const parts = tok.split(".");
|
|
210
|
-
if (parts.length !== 3)
|
|
211
|
-
return null;
|
|
212
|
-
let b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
213
|
-
b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
|
|
214
|
-
const jsonText = atob(b64);
|
|
215
|
-
const payload = JSON.parse(jsonText);
|
|
216
|
-
return (_a = payload.username) !== null && _a !== void 0 ? _a : null;
|
|
217
|
-
}
|
|
218
|
-
catch (_b) {
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/** Remove the JWT from LocalStorage */
|
|
223
|
-
function removeToken() {
|
|
224
|
-
try {
|
|
225
|
-
callStorage('removeItem', 'token');
|
|
226
|
-
}
|
|
227
|
-
catch (err) {
|
|
228
|
-
console.warn("Failed to remove token:", err);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
26
|
/* ------------------------------------------------------------------ */
|
|
232
27
|
/* internals */
|
|
233
28
|
/* ------------------------------------------------------------------ */
|
|
@@ -316,18 +111,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
316
111
|
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
317
112
|
|
|
318
113
|
|
|
319
|
-
function __rest(s, e) {
|
|
320
|
-
var t = {};
|
|
321
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
322
|
-
t[p] = s[p];
|
|
323
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
324
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
325
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
326
|
-
t[p[i]] = s[p[i]];
|
|
327
|
-
}
|
|
328
|
-
return t;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
114
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
332
115
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
333
116
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -343,100 +126,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
343
126
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
344
127
|
};
|
|
345
128
|
|
|
346
|
-
// src/functions/read_utils/src/read_utils.ts
|
|
347
|
-
let fs = null;
|
|
348
|
-
let path$2 = null;
|
|
349
|
-
function getFsModules() {
|
|
350
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
351
|
-
var _a;
|
|
352
|
-
if (!fs && !path$2 && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
353
|
-
try {
|
|
354
|
-
// prevent bundlers from resolving these at build time
|
|
355
|
-
fs = (new Function("return require('fs')"))();
|
|
356
|
-
path$2 = (new Function("return require('path')"))();
|
|
357
|
-
}
|
|
358
|
-
catch (_b) {
|
|
359
|
-
fs = null;
|
|
360
|
-
path$2 = null;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return { fs, path: path$2 };
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Reads a JSON file, either via Node’s fs (if available)
|
|
368
|
-
* or via window.fetch in the browser. Never throws — returns
|
|
369
|
-
* the parsed object or null on any error.
|
|
370
|
-
*/
|
|
371
|
-
function readJsonFile(relativeOrAbsolutePath) {
|
|
372
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
373
|
-
var _a;
|
|
374
|
-
// 1) Try Node.js fs (only at runtime, not bundled)
|
|
375
|
-
if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
376
|
-
try {
|
|
377
|
-
const { fs, path } = yield getFsModules();
|
|
378
|
-
if (fs && path) {
|
|
379
|
-
const filePath = path.isAbsolute(relativeOrAbsolutePath)
|
|
380
|
-
? relativeOrAbsolutePath
|
|
381
|
-
: path.resolve(process.cwd(), relativeOrAbsolutePath);
|
|
382
|
-
const text = fs.readFileSync(filePath, "utf8");
|
|
383
|
-
return JSON.parse(text);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
catch (_b) {
|
|
387
|
-
// swallow and fall back
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
// 2) Try browser fetch
|
|
391
|
-
const fetchFn = safeGlobalProp("fetch");
|
|
392
|
-
if (typeof fetchFn !== "function") {
|
|
393
|
-
return null;
|
|
394
|
-
}
|
|
395
|
-
let url = relativeOrAbsolutePath;
|
|
396
|
-
const baseURI = safeGlobalProp("document", "baseURI");
|
|
397
|
-
if (baseURI) {
|
|
398
|
-
try {
|
|
399
|
-
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
400
|
-
}
|
|
401
|
-
catch (_c) {
|
|
402
|
-
/* keep url as-is */
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
try {
|
|
406
|
-
const res = yield fetchFn(url);
|
|
407
|
-
if (!res.ok)
|
|
408
|
-
return null;
|
|
409
|
-
return (yield res.json());
|
|
410
|
-
}
|
|
411
|
-
catch (_d) {
|
|
412
|
-
return null;
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
function getConfigContent() {
|
|
417
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
418
|
-
try {
|
|
419
|
-
// `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
|
|
420
|
-
const cfg = yield readJsonFile('./config.json');
|
|
421
|
-
return cfg;
|
|
422
|
-
}
|
|
423
|
-
catch (_a) {
|
|
424
|
-
// swallow errors & return null so callers can detect “no config”
|
|
425
|
-
return null;
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
// 2) Pull a single key out of that object
|
|
430
|
-
function getConfigVar() {
|
|
431
|
-
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
432
|
-
const cfg = yield getConfigContent();
|
|
433
|
-
if (cfg && typeof cfg === 'object' && key in cfg) {
|
|
434
|
-
return cfg[key];
|
|
435
|
-
}
|
|
436
|
-
return undefined;
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
|
|
440
129
|
/**
|
|
441
130
|
* Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
|
|
442
131
|
*/
|
|
@@ -461,18 +150,13 @@ function getMethod(method = null, body = null) {
|
|
|
461
150
|
// Gets headers, skips JSON headers when body is FormData
|
|
462
151
|
function getHeaders(headers = {}, method = null, body = null) {
|
|
463
152
|
const result = Object.assign({}, headers);
|
|
464
|
-
//
|
|
465
|
-
if (!result.Authorization) {
|
|
466
|
-
const token = getToken();
|
|
467
|
-
Object.assign(result, getAuthorizationHeader(result, token));
|
|
468
|
-
}
|
|
469
|
-
method = getMethod(method, body);
|
|
470
|
-
// if it’s a multipart FormData, let the browser set the boundary header
|
|
153
|
+
// let browser set boundary
|
|
471
154
|
if (body instanceof FormData) {
|
|
472
155
|
return result;
|
|
473
156
|
}
|
|
474
|
-
|
|
475
|
-
if (['POST', 'PUT', 'PATCH'].includes(
|
|
157
|
+
const upper = method === null || method === void 0 ? void 0 : method.toUpperCase();
|
|
158
|
+
if (['POST', 'PUT', 'PATCH'].includes(upper !== null && upper !== void 0 ? upper : '') &&
|
|
159
|
+
!result['Content-Type']) {
|
|
476
160
|
result['Content-Type'] = 'application/json';
|
|
477
161
|
}
|
|
478
162
|
return result;
|
|
@@ -542,7 +226,7 @@ function fetchIt(endpoint_1) {
|
|
|
542
226
|
// 2) choose the URL
|
|
543
227
|
let url = endpoint;
|
|
544
228
|
// 3) prepare headers & body
|
|
545
|
-
headers = Object.assign(Object.assign(
|
|
229
|
+
headers = Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), headers);
|
|
546
230
|
const opts = {
|
|
547
231
|
method,
|
|
548
232
|
credentials: withCredentials ? "include" : "same-origin",
|
|
@@ -1101,11 +785,11 @@ posix.posix = posix;
|
|
|
1101
785
|
|
|
1102
786
|
var pathBrowserify = posix;
|
|
1103
787
|
|
|
1104
|
-
var path = /*@__PURE__*/getDefaultExportFromCjs(pathBrowserify);
|
|
788
|
+
var path$1 = /*@__PURE__*/getDefaultExportFromCjs(pathBrowserify);
|
|
1105
789
|
|
|
1106
|
-
var path$
|
|
790
|
+
var path$2 = /*#__PURE__*/_mergeNamespaces({
|
|
1107
791
|
__proto__: null,
|
|
1108
|
-
default: path
|
|
792
|
+
default: path$1
|
|
1109
793
|
}, [pathBrowserify]);
|
|
1110
794
|
|
|
1111
795
|
function urlJoin(...parts) {
|
|
@@ -1150,7 +834,7 @@ function get_full_path(partial_path, parent_dir = null) {
|
|
|
1150
834
|
if (typeof partial_path !== 'string') {
|
|
1151
835
|
throw new Error('partial_path must be a string');
|
|
1152
836
|
}
|
|
1153
|
-
if (path.isAbsolute(partial_path)) {
|
|
837
|
+
if (path$1.isAbsolute(partial_path)) {
|
|
1154
838
|
return partial_path;
|
|
1155
839
|
}
|
|
1156
840
|
return urlJoin(parent_dir, partial_path);
|
|
@@ -1165,7 +849,7 @@ function path_to_url(filePath, all_paths) {
|
|
|
1165
849
|
}
|
|
1166
850
|
for (const key in all_paths) {
|
|
1167
851
|
const mapping = all_paths[key];
|
|
1168
|
-
const normalizedBase = path.normalize(mapping.path);
|
|
852
|
+
const normalizedBase = path$1.normalize(mapping.path);
|
|
1169
853
|
if (filePath.startsWith(normalizedBase)) {
|
|
1170
854
|
const relativePath = filePath.substring(normalizedBase.length);
|
|
1171
855
|
return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
|
|
@@ -1190,40 +874,130 @@ function url_to_path(urlStr, all_paths) {
|
|
|
1190
874
|
}
|
|
1191
875
|
return null;
|
|
1192
876
|
}
|
|
877
|
+
function urljoin(...parts) {
|
|
878
|
+
return urlJoin(...parts);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
function split_outside_brackets(s) {
|
|
882
|
+
let depth = 0;
|
|
883
|
+
let start = 0;
|
|
884
|
+
const out = [];
|
|
885
|
+
for (let i = 0; i < s.length; i++) {
|
|
886
|
+
const c = s[i];
|
|
887
|
+
if (c === "[")
|
|
888
|
+
depth++;
|
|
889
|
+
else if (c === "]")
|
|
890
|
+
depth--;
|
|
891
|
+
// split only when NOT inside brackets
|
|
892
|
+
if (c === "," && depth === 0) {
|
|
893
|
+
out.push(s.slice(start, i));
|
|
894
|
+
start = i + 1;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
out.push(s.slice(start));
|
|
898
|
+
return out;
|
|
899
|
+
}
|
|
900
|
+
function parse_nested_list(s) {
|
|
901
|
+
// strip outer brackets
|
|
902
|
+
const inner = s.slice(1, -1).trim();
|
|
903
|
+
const parts = split_outside_brackets(inner);
|
|
904
|
+
const result = [];
|
|
905
|
+
for (let p of parts) {
|
|
906
|
+
p = p.trim();
|
|
907
|
+
if (p.startsWith("[") && p.endsWith("]")) {
|
|
908
|
+
// recursively parse nested list
|
|
909
|
+
result.push(parse_nested_list(p));
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
result.push(p);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return result;
|
|
916
|
+
}
|
|
1193
917
|
|
|
1194
918
|
function ensure_list(obj) {
|
|
1195
|
-
|
|
1196
|
-
|
|
919
|
+
if (obj == null)
|
|
920
|
+
return [];
|
|
921
|
+
if (Array.isArray(obj)) {
|
|
922
|
+
return obj.flatMap(item => ensure_list(item));
|
|
923
|
+
}
|
|
924
|
+
const s = String(obj).trim();
|
|
925
|
+
if (s.startsWith("[") && s.endsWith("]")) {
|
|
926
|
+
return parse_nested_list(s);
|
|
927
|
+
}
|
|
928
|
+
return split_outside_brackets(s).map(x => x.trim());
|
|
1197
929
|
}
|
|
1198
930
|
// coerce any single value into a number (0 if it can't)
|
|
1199
931
|
function ensure_number(x) {
|
|
1200
932
|
const n = Number(x);
|
|
1201
933
|
return isNaN(n) ? 0 : n;
|
|
1202
934
|
}
|
|
1203
|
-
function
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
return
|
|
935
|
+
function ensure_string(obj) {
|
|
936
|
+
return String(obj);
|
|
937
|
+
}
|
|
938
|
+
function ensurelist(obj) {
|
|
939
|
+
return ensure_list(obj);
|
|
940
|
+
}
|
|
941
|
+
function assureList(obj) {
|
|
942
|
+
return ensure_list(obj);
|
|
943
|
+
}
|
|
944
|
+
function assure_list(obj) {
|
|
945
|
+
return ensure_list(obj);
|
|
946
|
+
}
|
|
947
|
+
function ensureList(obj) {
|
|
948
|
+
return ensure_list(obj);
|
|
949
|
+
}
|
|
950
|
+
function assurelist(obj) {
|
|
951
|
+
return ensure_list(obj);
|
|
952
|
+
}
|
|
953
|
+
function ensurenumber(x) {
|
|
954
|
+
return ensure_number(x);
|
|
955
|
+
}
|
|
956
|
+
function assureNumber(x) {
|
|
957
|
+
return ensure_number(x);
|
|
958
|
+
}
|
|
959
|
+
function ensureNumber(x) {
|
|
960
|
+
return ensure_number(x);
|
|
961
|
+
}
|
|
962
|
+
function assurenumber(x) {
|
|
963
|
+
return ensure_number(x);
|
|
964
|
+
}
|
|
965
|
+
function assure_number(x) {
|
|
966
|
+
return ensure_number(x);
|
|
967
|
+
}
|
|
968
|
+
function ensurestring(obj) {
|
|
969
|
+
return ensure_string(obj);
|
|
970
|
+
}
|
|
971
|
+
function ensureString(obj) {
|
|
972
|
+
return ensure_string(obj);
|
|
973
|
+
}
|
|
974
|
+
function assureString(obj) {
|
|
975
|
+
return ensure_string(obj);
|
|
976
|
+
}
|
|
977
|
+
function assurestring(obj) {
|
|
978
|
+
return ensure_string(obj);
|
|
979
|
+
}
|
|
980
|
+
function assure_string(obj) {
|
|
981
|
+
return ensure_string(obj);
|
|
982
|
+
}
|
|
983
|
+
function assurearray(obj) {
|
|
984
|
+
return ensure_list(obj);
|
|
985
|
+
}
|
|
986
|
+
function ensurearray(obj) {
|
|
987
|
+
return ensure_list(obj);
|
|
988
|
+
}
|
|
989
|
+
function ensure_array(obj) {
|
|
990
|
+
return ensure_list(obj);
|
|
991
|
+
}
|
|
992
|
+
function ensureArray(obj) {
|
|
993
|
+
return ensure_list(obj);
|
|
994
|
+
}
|
|
995
|
+
function assure_array(obj) {
|
|
996
|
+
return ensure_list(obj);
|
|
1211
997
|
}
|
|
1212
|
-
function
|
|
1213
|
-
return
|
|
998
|
+
function assureArray(obj) {
|
|
999
|
+
return ensure_list(obj);
|
|
1214
1000
|
}
|
|
1215
|
-
const assureList = ensure_list;
|
|
1216
|
-
const assureString = ensure_string;
|
|
1217
|
-
const assureNumber = ensure_number;
|
|
1218
|
-
const assureArray = ensure_array;
|
|
1219
|
-
const assure_list = ensure_list;
|
|
1220
|
-
const assure_string = ensure_string;
|
|
1221
|
-
const assure_number = ensure_number;
|
|
1222
|
-
const assure_array = ensure_array;
|
|
1223
|
-
const ensureList = ensure_list;
|
|
1224
|
-
const ensureString = ensure_string;
|
|
1225
|
-
const ensureNumber = ensure_number;
|
|
1226
|
-
const ensureArray = ensure_array;
|
|
1227
1001
|
|
|
1228
1002
|
function cleanText(input) {
|
|
1229
1003
|
// Replace delimiters with spaces and split
|
|
@@ -1582,7 +1356,7 @@ function getMimeType(pathOrExt) {
|
|
|
1582
1356
|
}
|
|
1583
1357
|
function getAllFileTypesSync(directory, categories, opts) {
|
|
1584
1358
|
// 🧩 Skip entirely if fs isn't available
|
|
1585
|
-
if (!fsp || !path$
|
|
1359
|
+
if (!fsp || !path$2)
|
|
1586
1360
|
return [];
|
|
1587
1361
|
try {
|
|
1588
1362
|
const stat = statSync(directory);
|
|
@@ -1615,7 +1389,7 @@ function getAllFileTypesSync(directory, categories, opts) {
|
|
|
1615
1389
|
function getAllFileTypes(directory, categories, opts) {
|
|
1616
1390
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1617
1391
|
// 🧩 Skip entirely if fsp isn't available
|
|
1618
|
-
if (!fsp || !path$
|
|
1392
|
+
if (!fsp || !path$2)
|
|
1619
1393
|
return [];
|
|
1620
1394
|
try {
|
|
1621
1395
|
const stat$1 = yield stat(directory);
|
|
@@ -1720,71 +1494,80 @@ function stripPrefixes(str, bases = []) {
|
|
|
1720
1494
|
}
|
|
1721
1495
|
return str;
|
|
1722
1496
|
}
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
if (
|
|
1733
|
-
|
|
1497
|
+
function tryEatPrefix(str, length, ...objs) {
|
|
1498
|
+
str = String(str);
|
|
1499
|
+
objs = ensure_list(objs);
|
|
1500
|
+
const prefix = str.slice(0, length);
|
|
1501
|
+
if (length < 0) {
|
|
1502
|
+
const start = str.length + length;
|
|
1503
|
+
const actualPrefix = str.slice(start);
|
|
1504
|
+
return objs.includes(actualPrefix) ? [str.slice(0, start), true] : [str, false];
|
|
1505
|
+
}
|
|
1506
|
+
if (objs.includes(prefix)) {
|
|
1507
|
+
return [str.slice(length), true];
|
|
1734
1508
|
}
|
|
1735
|
-
|
|
1509
|
+
return [str, false];
|
|
1510
|
+
}
|
|
1511
|
+
/** Python-equivalent eatInner */
|
|
1512
|
+
function eatInner(str, listObjects) {
|
|
1736
1513
|
str = String(str);
|
|
1737
|
-
|
|
1738
|
-
while
|
|
1514
|
+
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
1515
|
+
// Keep removing from left while leftmost char is in the set
|
|
1516
|
+
while (str.length > 0 && chars.includes(str[0])) {
|
|
1739
1517
|
str = str.slice(1);
|
|
1740
1518
|
}
|
|
1741
1519
|
return str;
|
|
1742
1520
|
}
|
|
1743
|
-
/**
|
|
1744
|
-
* Removes characters from the end of the string
|
|
1745
|
-
* if they are found in the list of characters.
|
|
1746
|
-
*
|
|
1747
|
-
* @param str - The input string.
|
|
1748
|
-
* @param listObjects - A string or an array of characters to remove.
|
|
1749
|
-
* @returns The modified string.
|
|
1750
|
-
*/
|
|
1521
|
+
/** Python-equivalent eatOuter */
|
|
1751
1522
|
function eatOuter(str, listObjects) {
|
|
1752
|
-
if (!Array.isArray(listObjects)) {
|
|
1753
|
-
listObjects = [listObjects];
|
|
1754
|
-
}
|
|
1755
|
-
// Ensure str is a string
|
|
1756
1523
|
str = String(str);
|
|
1757
|
-
|
|
1758
|
-
|
|
1524
|
+
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
1525
|
+
if (!str || chars.length === 0)
|
|
1526
|
+
return str;
|
|
1527
|
+
for (let i = 0; i < str.length; i++) {
|
|
1528
|
+
if (!str)
|
|
1529
|
+
return str;
|
|
1530
|
+
const last = str[str.length - 1];
|
|
1531
|
+
if (!chars.includes(last)) {
|
|
1532
|
+
return str;
|
|
1533
|
+
}
|
|
1759
1534
|
str = str.slice(0, -1);
|
|
1760
1535
|
}
|
|
1761
1536
|
return str;
|
|
1762
1537
|
}
|
|
1763
|
-
/**
|
|
1764
|
-
* Removes characters from both the beginning and the end of the string
|
|
1765
|
-
* if they are found in the list of characters.
|
|
1766
|
-
*
|
|
1767
|
-
* @param str - The input string.
|
|
1768
|
-
* @param listObjects - A string or an array of characters to remove.
|
|
1769
|
-
* @returns The modified string.
|
|
1770
|
-
*/
|
|
1538
|
+
/** Python-equivalent eatAll */
|
|
1771
1539
|
function eatAll(str, listObjects) {
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1540
|
+
str = String(str);
|
|
1541
|
+
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
1542
|
+
str = eatInner(str, chars);
|
|
1543
|
+
str = eatOuter(str, chars);
|
|
1544
|
+
return str;
|
|
1545
|
+
}
|
|
1546
|
+
// Plug in the actual version from your project
|
|
1547
|
+
function get_alpha_ints(opts) {
|
|
1548
|
+
// REPLACE WITH YOUR REAL IMPLEMENTATION
|
|
1549
|
+
return [];
|
|
1550
|
+
}
|
|
1551
|
+
/** Python-equivalent eatElse */
|
|
1552
|
+
function eatElse(stringObj, chars, ints = true, alpha = true, lower = true, capitalize = true, string = true, listObj = true) {
|
|
1553
|
+
stringObj = String(stringObj);
|
|
1554
|
+
const alphaInts = get_alpha_ints();
|
|
1555
|
+
let ls = ensure_list(chars || []).concat(alphaInts);
|
|
1556
|
+
while (true) {
|
|
1557
|
+
if (!stringObj)
|
|
1558
|
+
return stringObj;
|
|
1559
|
+
const startOk = !ls.includes(stringObj[0]);
|
|
1560
|
+
const endOk = !ls.includes(stringObj[stringObj.length - 1]);
|
|
1561
|
+
const shouldEat = startOk || endOk;
|
|
1562
|
+
if (!shouldEat)
|
|
1563
|
+
return stringObj;
|
|
1564
|
+
if (stringObj && startOk) {
|
|
1565
|
+
stringObj = stringObj.length === 1 ? "" : stringObj.slice(1);
|
|
1566
|
+
}
|
|
1567
|
+
if (stringObj && endOk) {
|
|
1568
|
+
stringObj = stringObj.length === 1 ? "" : stringObj.slice(0, -1);
|
|
1785
1569
|
}
|
|
1786
1570
|
}
|
|
1787
|
-
return result;
|
|
1788
1571
|
}
|
|
1789
1572
|
function tryParse(obj) {
|
|
1790
1573
|
try {
|
|
@@ -1808,6 +1591,15 @@ function create_list_string(array_obj) {
|
|
|
1808
1591
|
}
|
|
1809
1592
|
return string;
|
|
1810
1593
|
}
|
|
1594
|
+
function eatall(str, listObjects) {
|
|
1595
|
+
return eatAll(str, listObjects);
|
|
1596
|
+
}
|
|
1597
|
+
function eatinner(str, listObjects) {
|
|
1598
|
+
return eatInner(str, listObjects);
|
|
1599
|
+
}
|
|
1600
|
+
function eatouter(str, listObjects) {
|
|
1601
|
+
return eatOuter(str, listObjects);
|
|
1602
|
+
}
|
|
1811
1603
|
|
|
1812
1604
|
/**
|
|
1813
1605
|
* In the browser we already have a WHATWG URL constructor on window.
|
|
@@ -1842,9 +1634,11 @@ function get_basename(filePath) {
|
|
|
1842
1634
|
return '';
|
|
1843
1635
|
return pathBrowserify.basename(filePath);
|
|
1844
1636
|
}
|
|
1845
|
-
function get_filename(
|
|
1846
|
-
|
|
1847
|
-
|
|
1637
|
+
function get_filename(filePath) {
|
|
1638
|
+
if (!filePath)
|
|
1639
|
+
return '';
|
|
1640
|
+
const ext = pathBrowserify.extname(filePath);
|
|
1641
|
+
return pathBrowserify.basename(filePath, ext);
|
|
1848
1642
|
}
|
|
1849
1643
|
function get_extname(filePath) {
|
|
1850
1644
|
if (!filePath)
|
|
@@ -1882,32 +1676,36 @@ function get_relative_path(basePath, targetPath) {
|
|
|
1882
1676
|
}
|
|
1883
1677
|
}
|
|
1884
1678
|
/**
|
|
1885
|
-
* Join multiple path segments,
|
|
1679
|
+
* Join multiple path segments — clean, predictable, bulletproof.
|
|
1886
1680
|
*
|
|
1887
|
-
*
|
|
1888
|
-
*
|
|
1889
|
-
*
|
|
1681
|
+
* Accepts ANYTHING that ensure_list can handle:
|
|
1682
|
+
* • 'a,b,c'
|
|
1683
|
+
* • ['a', 'b,c']
|
|
1684
|
+
* • 'a/b/c'
|
|
1685
|
+
* • '/a/', 'b//c'
|
|
1686
|
+
* • mixed arrays, comma strings, whatever
|
|
1687
|
+
*
|
|
1688
|
+
* Always returns a clean POSIX path string. Never a list.
|
|
1890
1689
|
*/
|
|
1891
|
-
function make_path(...
|
|
1892
|
-
//
|
|
1893
|
-
const
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
let
|
|
1899
|
-
if (
|
|
1900
|
-
|
|
1690
|
+
function make_path(...parts) {
|
|
1691
|
+
// Normalize incoming segments into a flat list
|
|
1692
|
+
const segments = ensure_list(parts).map(x => String(x));
|
|
1693
|
+
let out = "";
|
|
1694
|
+
for (let i = 0; i < segments.length; i++) {
|
|
1695
|
+
const seg = segments[i];
|
|
1696
|
+
// Normalize a segment:
|
|
1697
|
+
let cleaned = eatOuter(seg, "/"); // trim trailing slashes
|
|
1698
|
+
if (!cleaned)
|
|
1699
|
+
continue;
|
|
1700
|
+
if (out === "") {
|
|
1701
|
+
out = cleaned;
|
|
1901
1702
|
}
|
|
1902
1703
|
else {
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
// remove any trailing slash on the accumulator
|
|
1906
|
-
real_path = real_path.replace(/\/+$/, '');
|
|
1907
|
-
real_path = `${real_path}/${segment}`;
|
|
1704
|
+
cleaned = eatInner(cleaned, "/"); // trim leading slashes
|
|
1705
|
+
out = `${out}/${cleaned}`;
|
|
1908
1706
|
}
|
|
1909
1707
|
}
|
|
1910
|
-
return
|
|
1708
|
+
return out;
|
|
1911
1709
|
}
|
|
1912
1710
|
function sanitizeFilename(filename) {
|
|
1913
1711
|
return filename
|
|
@@ -1921,7 +1719,7 @@ function sanitizeFilename(filename) {
|
|
|
1921
1719
|
function make_sanitized_path(...paths) {
|
|
1922
1720
|
let real_path = '';
|
|
1923
1721
|
for (let i = 0; i < paths.length; i++) {
|
|
1924
|
-
const sanitized = sanitizeFilename(
|
|
1722
|
+
const sanitized = sanitizeFilename(eatOuter(paths[i], '/'));
|
|
1925
1723
|
if (i === 0) {
|
|
1926
1724
|
real_path = sanitized;
|
|
1927
1725
|
}
|
|
@@ -1939,6 +1737,51 @@ function normalizeUrl(base, p) {
|
|
|
1939
1737
|
// collapse multiple “//” into one, but keep the “://” after protocol
|
|
1940
1738
|
return `${cleanBase}/${cleanPath}`.replace(/([^:])\/{2,}/g, '$1/');
|
|
1941
1739
|
}
|
|
1740
|
+
function pathjoin(...parts) {
|
|
1741
|
+
return make_path(...parts);
|
|
1742
|
+
}
|
|
1743
|
+
function pathJoin(...parts) {
|
|
1744
|
+
return make_path(...parts);
|
|
1745
|
+
}
|
|
1746
|
+
function makepath(...parts) {
|
|
1747
|
+
return make_path(...parts);
|
|
1748
|
+
}
|
|
1749
|
+
function makePath(...parts) {
|
|
1750
|
+
return make_path(...parts);
|
|
1751
|
+
}
|
|
1752
|
+
function path_join(...parts) {
|
|
1753
|
+
return make_path(...parts);
|
|
1754
|
+
}
|
|
1755
|
+
function getSplitext(filePath) {
|
|
1756
|
+
return get_splitext(filePath);
|
|
1757
|
+
}
|
|
1758
|
+
function getsplitext(filePath) {
|
|
1759
|
+
return get_splitext(filePath);
|
|
1760
|
+
}
|
|
1761
|
+
function getextname(filePath) {
|
|
1762
|
+
return get_extname(filePath);
|
|
1763
|
+
}
|
|
1764
|
+
function getExtname(filePath) {
|
|
1765
|
+
return get_extname(filePath);
|
|
1766
|
+
}
|
|
1767
|
+
function getfilename(filePath) {
|
|
1768
|
+
return get_filename(filePath);
|
|
1769
|
+
}
|
|
1770
|
+
function getFilename(filePath) {
|
|
1771
|
+
return get_filename(filePath);
|
|
1772
|
+
}
|
|
1773
|
+
function getbasename(filePath) {
|
|
1774
|
+
return get_basename(filePath);
|
|
1775
|
+
}
|
|
1776
|
+
function getBasename(filePath) {
|
|
1777
|
+
return get_basename(filePath);
|
|
1778
|
+
}
|
|
1779
|
+
function getdirname(filePath) {
|
|
1780
|
+
return get_dirname(filePath);
|
|
1781
|
+
}
|
|
1782
|
+
function getDirname(filePath) {
|
|
1783
|
+
return get_dirname(filePath);
|
|
1784
|
+
}
|
|
1942
1785
|
|
|
1943
1786
|
/**
|
|
1944
1787
|
* Returns the absolute path of the current file.
|
|
@@ -2233,39 +2076,221 @@ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit)
|
|
|
2233
2076
|
const isFiniteNum = (x) => Number.isFinite(x);
|
|
2234
2077
|
const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
|
|
2235
2078
|
|
|
2236
|
-
function
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2079
|
+
function getSafeDocument() {
|
|
2080
|
+
return typeof document !== 'undefined' ? document : undefined;
|
|
2081
|
+
}
|
|
2082
|
+
function getDocumentProp(...keys) {
|
|
2083
|
+
let obj = getSafeDocument();
|
|
2084
|
+
for (const k of keys) {
|
|
2085
|
+
if (obj == null || typeof obj !== 'object')
|
|
2086
|
+
return undefined;
|
|
2087
|
+
obj = obj[k];
|
|
2088
|
+
}
|
|
2089
|
+
return obj;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
/**
|
|
2093
|
+
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
2094
|
+
* Returns `undefined` if any step is missing.
|
|
2095
|
+
*/
|
|
2096
|
+
function safeGlobalProp(...path) {
|
|
2097
|
+
let obj = globalThis;
|
|
2098
|
+
for (const key of path) {
|
|
2099
|
+
if (obj == null || typeof obj !== "object" || !(key in obj)) {
|
|
2100
|
+
return undefined;
|
|
2101
|
+
}
|
|
2102
|
+
obj = obj[key];
|
|
2103
|
+
}
|
|
2104
|
+
return obj;
|
|
2255
2105
|
}
|
|
2256
2106
|
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2107
|
+
/**
|
|
2108
|
+
* Returns `window` if running in a browser, otherwise `undefined`.
|
|
2109
|
+
*/
|
|
2110
|
+
function getSafeLocalStorage() {
|
|
2111
|
+
if (typeof window === 'undefined')
|
|
2112
|
+
return undefined;
|
|
2113
|
+
try {
|
|
2114
|
+
return window.localStorage;
|
|
2115
|
+
}
|
|
2116
|
+
catch (_a) {
|
|
2117
|
+
return undefined; // e.g. Safari private-mode block
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Call a Storage method by name, silencing any errors or missing storage.
|
|
2122
|
+
*
|
|
2123
|
+
* @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
|
|
2124
|
+
* @param args The arguments you’d normally pass to that method.
|
|
2125
|
+
* @returns The method’s return value, or undefined if storage/method isn’t available.
|
|
2126
|
+
*/
|
|
2127
|
+
function callStorage(method, ...args) {
|
|
2128
|
+
const storage = getSafeLocalStorage();
|
|
2129
|
+
if (!storage)
|
|
2130
|
+
return undefined;
|
|
2131
|
+
const fn = storage[method];
|
|
2132
|
+
if (typeof fn !== 'function')
|
|
2133
|
+
return undefined;
|
|
2134
|
+
try {
|
|
2135
|
+
// @ts-ignore – TS can’t infer that this is callable
|
|
2136
|
+
return fn.apply(storage, args);
|
|
2137
|
+
}
|
|
2138
|
+
catch (_a) {
|
|
2139
|
+
return undefined;
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
/**
|
|
2143
|
+
* Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
|
|
2144
|
+
* Returns `undefined` on any error.
|
|
2145
|
+
*/
|
|
2146
|
+
function safeStorage(storageName, method, ...args) {
|
|
2147
|
+
try {
|
|
2148
|
+
const store = safeGlobalProp(storageName);
|
|
2149
|
+
if (!store || typeof store[method] !== "function")
|
|
2150
|
+
return undefined;
|
|
2151
|
+
// @ts-ignore
|
|
2152
|
+
return store[method](...args);
|
|
2153
|
+
}
|
|
2154
|
+
catch (_a) {
|
|
2155
|
+
return undefined;
|
|
2156
|
+
}
|
|
2260
2157
|
}
|
|
2261
2158
|
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2159
|
+
/**
|
|
2160
|
+
* Returns the global window object if it exists, otherwise undefined.
|
|
2161
|
+
*/
|
|
2162
|
+
function getSafeWindow() {
|
|
2163
|
+
return typeof window !== 'undefined' ? window : undefined;
|
|
2164
|
+
}
|
|
2165
|
+
/**
|
|
2166
|
+
* Safely call a method on window by name.
|
|
2167
|
+
*
|
|
2168
|
+
* @param method The Window method to call (e.g. "alert", "open", etc.).
|
|
2169
|
+
* @param args Arguments to pass to that method.
|
|
2170
|
+
* @returns The method’s return value, or undefined if
|
|
2171
|
+
* window/method isn’t available or throws.
|
|
2172
|
+
*/
|
|
2173
|
+
function callWindowMethod(method, ...args) {
|
|
2174
|
+
const w = getSafeWindow();
|
|
2175
|
+
if (!w)
|
|
2176
|
+
return undefined;
|
|
2177
|
+
const fn = w[method];
|
|
2178
|
+
if (typeof fn !== 'function')
|
|
2179
|
+
return undefined;
|
|
2180
|
+
try {
|
|
2181
|
+
// cast to any so TS doesn’t complain about apply/invoke
|
|
2182
|
+
return fn(...args);
|
|
2183
|
+
}
|
|
2184
|
+
catch (_a) {
|
|
2185
|
+
return undefined;
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
/** implementation */
|
|
2189
|
+
function getWindowProp(...keys) {
|
|
2190
|
+
let obj = getSafeWindow();
|
|
2191
|
+
for (const k of keys) {
|
|
2192
|
+
if (obj == null || typeof obj !== 'object')
|
|
2193
|
+
return undefined;
|
|
2194
|
+
obj = obj[k];
|
|
2195
|
+
}
|
|
2196
|
+
return obj;
|
|
2197
|
+
}
|
|
2198
|
+
function getWindowHost() {
|
|
2199
|
+
return getWindowProp('location', 'host');
|
|
2265
2200
|
}
|
|
2266
2201
|
|
|
2267
|
-
|
|
2268
|
-
|
|
2202
|
+
// src/functions/read_utils/src/read_utils.ts
|
|
2203
|
+
let fs = null;
|
|
2204
|
+
let path = null;
|
|
2205
|
+
function getFsModules() {
|
|
2206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2207
|
+
var _a;
|
|
2208
|
+
if (!fs && !path && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
2209
|
+
try {
|
|
2210
|
+
// prevent bundlers from resolving these at build time
|
|
2211
|
+
fs = (new Function("return require('fs')"))();
|
|
2212
|
+
path = (new Function("return require('path')"))();
|
|
2213
|
+
}
|
|
2214
|
+
catch (_b) {
|
|
2215
|
+
fs = null;
|
|
2216
|
+
path = null;
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
return { fs, path };
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Reads a JSON file, either via Node’s fs (if available)
|
|
2224
|
+
* or via window.fetch in the browser. Never throws — returns
|
|
2225
|
+
* the parsed object or null on any error.
|
|
2226
|
+
*/
|
|
2227
|
+
function readJsonFile(relativeOrAbsolutePath) {
|
|
2228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2229
|
+
var _a;
|
|
2230
|
+
// 1) Try Node.js fs (only at runtime, not bundled)
|
|
2231
|
+
if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
2232
|
+
try {
|
|
2233
|
+
const { fs, path } = yield getFsModules();
|
|
2234
|
+
if (fs && path) {
|
|
2235
|
+
const filePath = path.isAbsolute(relativeOrAbsolutePath)
|
|
2236
|
+
? relativeOrAbsolutePath
|
|
2237
|
+
: path.resolve(process.cwd(), relativeOrAbsolutePath);
|
|
2238
|
+
const text = fs.readFileSync(filePath, "utf8");
|
|
2239
|
+
return JSON.parse(text);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
catch (_b) {
|
|
2243
|
+
// swallow and fall back
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
// 2) Try browser fetch
|
|
2247
|
+
const fetchFn = safeGlobalProp("fetch");
|
|
2248
|
+
if (typeof fetchFn !== "function") {
|
|
2249
|
+
return null;
|
|
2250
|
+
}
|
|
2251
|
+
let url = relativeOrAbsolutePath;
|
|
2252
|
+
const baseURI = safeGlobalProp("document", "baseURI");
|
|
2253
|
+
if (baseURI) {
|
|
2254
|
+
try {
|
|
2255
|
+
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
2256
|
+
}
|
|
2257
|
+
catch (_c) {
|
|
2258
|
+
/* keep url as-is */
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
try {
|
|
2262
|
+
const res = yield fetchFn(url);
|
|
2263
|
+
if (!res.ok)
|
|
2264
|
+
return null;
|
|
2265
|
+
return (yield res.json());
|
|
2266
|
+
}
|
|
2267
|
+
catch (_d) {
|
|
2268
|
+
return null;
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2272
|
+
function getConfigContent() {
|
|
2273
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2274
|
+
try {
|
|
2275
|
+
// `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
|
|
2276
|
+
const cfg = yield readJsonFile('./config.json');
|
|
2277
|
+
return cfg;
|
|
2278
|
+
}
|
|
2279
|
+
catch (_a) {
|
|
2280
|
+
// swallow errors & return null so callers can detect “no config”
|
|
2281
|
+
return null;
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
// 2) Pull a single key out of that object
|
|
2286
|
+
function getConfigVar() {
|
|
2287
|
+
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
2288
|
+
const cfg = yield getConfigContent();
|
|
2289
|
+
if (cfg && typeof cfg === 'object' && key in cfg) {
|
|
2290
|
+
return cfg[key];
|
|
2291
|
+
}
|
|
2292
|
+
return undefined;
|
|
2293
|
+
});
|
|
2269
2294
|
}
|
|
2270
2295
|
|
|
2271
2296
|
// src/functions/config_utils/src/config_utils.ts
|
|
@@ -2376,5 +2401,5 @@ function get_keyword_string(keywords) {
|
|
|
2376
2401
|
return allString;
|
|
2377
2402
|
}
|
|
2378
2403
|
|
|
2379
|
-
export { API_PREFIX, ATTOSECOND, BASE_URL,
|
|
2404
|
+
export { API_PREFIX, ATTOSECOND, BASE_URL, CENTISECOND, DAY, DAY_IN_S, DECISECOND, DEV_PREFIX, DIST_ALIASES, DIST_FACTORS, DOMAIN_NAME, DistanceConverter, FEET_PER_METER, FEMTOSECOND, HOUR, HOUR_IN_S, KMS_PER_METER, MEDIA_TYPES, METERS_PER_FOOT, METERS_PER_KM, METERS_PER_MILE, MICROSECOND, MILES_PER_METER, MILISECOND, MIME_TYPES, MINUTE, MIN_IN_S, MONTH, MONTH_IN_S, MPerS_TO_MiPerH, MiPerH_TO_MPerS, NANOSECOND, PI, PI2, PICOSECOND, PROD_PREFIX, PROTOCOL, SECOND, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SUB_DIR, SpeedConverter, TIME_ALIASES, TIME_FACTORS, TimeConverter, YEAR, YEAR_IN_S, ZEPTOSECOND, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, assurearray, assurelist, assurenumber, assurestring, callStorage, callWindowMethod, canonDist, canonTime, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, confirmType, confirm_type, convertDistance, convertSpeed, convertTime, create_list_string, decodeJwt, distanceToMeters, eatAll, eatElse, eatInner, eatOuter, eatall, eatinner, eatouter, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, ensurearray, ensurelist, ensurenumber, ensurestring, exponential, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fmt, formatNumber, fromMeters, fromMps, fromSeconds, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAllFileTypes, getAllFileTypesSync, getAlphaNum, getAlphas, getBaseDir, getBasename, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDirname, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getExtname, getFetchVars, getFilename, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMediaExts, getMediaMap, getMethod, getMimeType, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSplitext, getSrcDir, getSubstring, getWindowHost, getWindowProp, get_all_file_types, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_media_exts, get_media_map, get_mime_type, get_relative_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, getbasename, getdirname, getextname, getfilename, getsplitext, isFiniteNum, isMediaType, isNum, isStrInString, isTokenExpired, isType, is_media_type, loadConfig, makePath, make_path, make_sanitized_path, makepath, metersToDistance, mpsToSpeed, normalizeUrl, parseResult, pathJoin, path_join, path_to_url, pathjoin, processKeywords, readJsonFile, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, secondsToTime, speedToMps, stripPrefixes, timeToSeconds, toMeters, toSeconds, truncateString, tryEatPrefix, tryParse, urlJoin, url_to_path, urljoin, velocityFromMs, velocityToMs };
|
|
2380
2405
|
//# sourceMappingURL=index.js.map
|