@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/cjs/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var react = require('react');
|
|
4
3
|
var path$1 = require('path');
|
|
5
4
|
var fs$1 = require('node:fs');
|
|
6
5
|
var fsp = require('node:fs/promises');
|
|
7
6
|
var path$2 = require('node:path');
|
|
8
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
9
7
|
|
|
10
8
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
11
9
|
function _interopNamespaceDefault(e) {
|
|
@@ -29,167 +27,6 @@ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
|
29
27
|
var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
|
|
30
28
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$2);
|
|
31
29
|
|
|
32
|
-
function getSafeDocument() {
|
|
33
|
-
return typeof document !== 'undefined' ? document : undefined;
|
|
34
|
-
}
|
|
35
|
-
function getDocumentProp(...keys) {
|
|
36
|
-
let obj = getSafeDocument();
|
|
37
|
-
for (const k of keys) {
|
|
38
|
-
if (obj == null || typeof obj !== 'object')
|
|
39
|
-
return undefined;
|
|
40
|
-
obj = obj[k];
|
|
41
|
-
}
|
|
42
|
-
return obj;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
47
|
-
* Returns `undefined` if any step is missing.
|
|
48
|
-
*/
|
|
49
|
-
function safeGlobalProp(...path) {
|
|
50
|
-
let obj = globalThis;
|
|
51
|
-
for (const key of path) {
|
|
52
|
-
if (obj == null || typeof obj !== "object" || !(key in obj)) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
obj = obj[key];
|
|
56
|
-
}
|
|
57
|
-
return obj;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Returns `window` if running in a browser, otherwise `undefined`.
|
|
62
|
-
*/
|
|
63
|
-
function getSafeLocalStorage() {
|
|
64
|
-
if (typeof window === 'undefined')
|
|
65
|
-
return undefined;
|
|
66
|
-
try {
|
|
67
|
-
return window.localStorage;
|
|
68
|
-
}
|
|
69
|
-
catch (_a) {
|
|
70
|
-
return undefined; // e.g. Safari private-mode block
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Call a Storage method by name, silencing any errors or missing storage.
|
|
75
|
-
*
|
|
76
|
-
* @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
|
|
77
|
-
* @param args The arguments you’d normally pass to that method.
|
|
78
|
-
* @returns The method’s return value, or undefined if storage/method isn’t available.
|
|
79
|
-
*/
|
|
80
|
-
function callStorage(method, ...args) {
|
|
81
|
-
const storage = getSafeLocalStorage();
|
|
82
|
-
if (!storage)
|
|
83
|
-
return undefined;
|
|
84
|
-
const fn = storage[method];
|
|
85
|
-
if (typeof fn !== 'function')
|
|
86
|
-
return undefined;
|
|
87
|
-
try {
|
|
88
|
-
// @ts-ignore – TS can’t infer that this is callable
|
|
89
|
-
return fn.apply(storage, args);
|
|
90
|
-
}
|
|
91
|
-
catch (_a) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
|
|
97
|
-
* Returns `undefined` on any error.
|
|
98
|
-
*/
|
|
99
|
-
function safeStorage(storageName, method, ...args) {
|
|
100
|
-
try {
|
|
101
|
-
const store = safeGlobalProp(storageName);
|
|
102
|
-
if (!store || typeof store[method] !== "function")
|
|
103
|
-
return undefined;
|
|
104
|
-
// @ts-ignore
|
|
105
|
-
return store[method](...args);
|
|
106
|
-
}
|
|
107
|
-
catch (_a) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Returns the global window object if it exists, otherwise undefined.
|
|
114
|
-
*/
|
|
115
|
-
function getSafeWindow() {
|
|
116
|
-
return typeof window !== 'undefined' ? window : undefined;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Safely call a method on window by name.
|
|
120
|
-
*
|
|
121
|
-
* @param method The Window method to call (e.g. "alert", "open", etc.).
|
|
122
|
-
* @param args Arguments to pass to that method.
|
|
123
|
-
* @returns The method’s return value, or undefined if
|
|
124
|
-
* window/method isn’t available or throws.
|
|
125
|
-
*/
|
|
126
|
-
function callWindowMethod(method, ...args) {
|
|
127
|
-
const w = getSafeWindow();
|
|
128
|
-
if (!w)
|
|
129
|
-
return undefined;
|
|
130
|
-
const fn = w[method];
|
|
131
|
-
if (typeof fn !== 'function')
|
|
132
|
-
return undefined;
|
|
133
|
-
try {
|
|
134
|
-
// cast to any so TS doesn’t complain about apply/invoke
|
|
135
|
-
return fn(...args);
|
|
136
|
-
}
|
|
137
|
-
catch (_a) {
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/** implementation */
|
|
142
|
-
function getWindowProp(...keys) {
|
|
143
|
-
let obj = getSafeWindow();
|
|
144
|
-
for (const k of keys) {
|
|
145
|
-
if (obj == null || typeof obj !== 'object')
|
|
146
|
-
return undefined;
|
|
147
|
-
obj = obj[k];
|
|
148
|
-
}
|
|
149
|
-
return obj;
|
|
150
|
-
}
|
|
151
|
-
function getWindowHost() {
|
|
152
|
-
return getWindowProp('location', 'host');
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
***Changes**:
|
|
157
|
-
*- Updated import path for `InputProps` to `../../types/interfaces`.
|
|
158
|
-
*
|
|
159
|
-
*3. **Token Utilities** (`src/functions/auth/token_utils.ts`):
|
|
160
|
-
* Copy from `/var/www/abstractendeavors/my-login-app/src/functions/auth_utils/token_utils.ts`.
|
|
161
|
-
*
|
|
162
|
-
*/
|
|
163
|
-
/** Read raw JWT from LocalStorage (or null if absent) */
|
|
164
|
-
function getToken() {
|
|
165
|
-
return callStorage('getItem', 'token');
|
|
166
|
-
}
|
|
167
|
-
function isLoggedIn() {
|
|
168
|
-
const tok = getToken();
|
|
169
|
-
return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Add a Bearer Authorization header.
|
|
173
|
-
* A shallow copy of headers is returned so callers can keep chaining.
|
|
174
|
-
*/
|
|
175
|
-
function getAuthorizationHeader(headers = {}, token = null) {
|
|
176
|
-
token = token !== null && token !== void 0 ? token : getToken();
|
|
177
|
-
headers = headers || {};
|
|
178
|
-
if (token)
|
|
179
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
180
|
-
return Object.assign({}, headers);
|
|
181
|
-
}
|
|
182
|
-
/** Throw + redirect if there’s no valid token; otherwise return it. */
|
|
183
|
-
function requireToken() {
|
|
184
|
-
const tok = getToken();
|
|
185
|
-
if (!tok || isTokenExpired(tok)) {
|
|
186
|
-
console.warn("→ No token or expired token, redirecting to login…");
|
|
187
|
-
localStorage.removeItem("token");
|
|
188
|
-
window.location.href = '/';
|
|
189
|
-
throw new Error("Redirecting to login…");
|
|
190
|
-
}
|
|
191
|
-
return tok;
|
|
192
|
-
}
|
|
193
30
|
/** True if token is structurally bad or its exp ≤ now. */
|
|
194
31
|
function isTokenExpired(token) {
|
|
195
32
|
try {
|
|
@@ -200,47 +37,6 @@ function isTokenExpired(token) {
|
|
|
200
37
|
return true; // treat malformed token as expired
|
|
201
38
|
}
|
|
202
39
|
}
|
|
203
|
-
/** Convenience wrapper: return username from the JWT (or null). */
|
|
204
|
-
function currentUsername() {
|
|
205
|
-
const tok = getToken();
|
|
206
|
-
if (!tok)
|
|
207
|
-
return null;
|
|
208
|
-
try {
|
|
209
|
-
const { username } = decodeJwt(tok);
|
|
210
|
-
return username !== null && username !== void 0 ? username : null;
|
|
211
|
-
}
|
|
212
|
-
catch (_a) {
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
function currentUsernames() {
|
|
217
|
-
var _a;
|
|
218
|
-
const tok = getToken();
|
|
219
|
-
if (!tok)
|
|
220
|
-
return null;
|
|
221
|
-
try {
|
|
222
|
-
const parts = tok.split(".");
|
|
223
|
-
if (parts.length !== 3)
|
|
224
|
-
return null;
|
|
225
|
-
let b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
226
|
-
b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
|
|
227
|
-
const jsonText = atob(b64);
|
|
228
|
-
const payload = JSON.parse(jsonText);
|
|
229
|
-
return (_a = payload.username) !== null && _a !== void 0 ? _a : null;
|
|
230
|
-
}
|
|
231
|
-
catch (_b) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
/** Remove the JWT from LocalStorage */
|
|
236
|
-
function removeToken() {
|
|
237
|
-
try {
|
|
238
|
-
callStorage('removeItem', 'token');
|
|
239
|
-
}
|
|
240
|
-
catch (err) {
|
|
241
|
-
console.warn("Failed to remove token:", err);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
40
|
/* ------------------------------------------------------------------ */
|
|
245
41
|
/* internals */
|
|
246
42
|
/* ------------------------------------------------------------------ */
|
|
@@ -329,18 +125,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
329
125
|
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
330
126
|
|
|
331
127
|
|
|
332
|
-
function __rest(s, e) {
|
|
333
|
-
var t = {};
|
|
334
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
335
|
-
t[p] = s[p];
|
|
336
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
337
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
338
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
339
|
-
t[p[i]] = s[p[i]];
|
|
340
|
-
}
|
|
341
|
-
return t;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
128
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
345
129
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
346
130
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -356,100 +140,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
356
140
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
357
141
|
};
|
|
358
142
|
|
|
359
|
-
// src/functions/read_utils/src/read_utils.ts
|
|
360
|
-
let fs = null;
|
|
361
|
-
let path = null;
|
|
362
|
-
function getFsModules() {
|
|
363
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
364
|
-
var _a;
|
|
365
|
-
if (!fs && !path && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
366
|
-
try {
|
|
367
|
-
// prevent bundlers from resolving these at build time
|
|
368
|
-
fs = (new Function("return require('fs')"))();
|
|
369
|
-
path = (new Function("return require('path')"))();
|
|
370
|
-
}
|
|
371
|
-
catch (_b) {
|
|
372
|
-
fs = null;
|
|
373
|
-
path = null;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return { fs, path };
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Reads a JSON file, either via Node’s fs (if available)
|
|
381
|
-
* or via window.fetch in the browser. Never throws — returns
|
|
382
|
-
* the parsed object or null on any error.
|
|
383
|
-
*/
|
|
384
|
-
function readJsonFile(relativeOrAbsolutePath) {
|
|
385
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
386
|
-
var _a;
|
|
387
|
-
// 1) Try Node.js fs (only at runtime, not bundled)
|
|
388
|
-
if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
389
|
-
try {
|
|
390
|
-
const { fs, path } = yield getFsModules();
|
|
391
|
-
if (fs && path) {
|
|
392
|
-
const filePath = path.isAbsolute(relativeOrAbsolutePath)
|
|
393
|
-
? relativeOrAbsolutePath
|
|
394
|
-
: path.resolve(process.cwd(), relativeOrAbsolutePath);
|
|
395
|
-
const text = fs.readFileSync(filePath, "utf8");
|
|
396
|
-
return JSON.parse(text);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
catch (_b) {
|
|
400
|
-
// swallow and fall back
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
// 2) Try browser fetch
|
|
404
|
-
const fetchFn = safeGlobalProp("fetch");
|
|
405
|
-
if (typeof fetchFn !== "function") {
|
|
406
|
-
return null;
|
|
407
|
-
}
|
|
408
|
-
let url = relativeOrAbsolutePath;
|
|
409
|
-
const baseURI = safeGlobalProp("document", "baseURI");
|
|
410
|
-
if (baseURI) {
|
|
411
|
-
try {
|
|
412
|
-
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
413
|
-
}
|
|
414
|
-
catch (_c) {
|
|
415
|
-
/* keep url as-is */
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
try {
|
|
419
|
-
const res = yield fetchFn(url);
|
|
420
|
-
if (!res.ok)
|
|
421
|
-
return null;
|
|
422
|
-
return (yield res.json());
|
|
423
|
-
}
|
|
424
|
-
catch (_d) {
|
|
425
|
-
return null;
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
function getConfigContent() {
|
|
430
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
431
|
-
try {
|
|
432
|
-
// `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
|
|
433
|
-
const cfg = yield readJsonFile('./config.json');
|
|
434
|
-
return cfg;
|
|
435
|
-
}
|
|
436
|
-
catch (_a) {
|
|
437
|
-
// swallow errors & return null so callers can detect “no config”
|
|
438
|
-
return null;
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
// 2) Pull a single key out of that object
|
|
443
|
-
function getConfigVar() {
|
|
444
|
-
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
445
|
-
const cfg = yield getConfigContent();
|
|
446
|
-
if (cfg && typeof cfg === 'object' && key in cfg) {
|
|
447
|
-
return cfg[key];
|
|
448
|
-
}
|
|
449
|
-
return undefined;
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
|
|
453
143
|
/**
|
|
454
144
|
* Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
|
|
455
145
|
*/
|
|
@@ -474,18 +164,13 @@ function getMethod(method = null, body = null) {
|
|
|
474
164
|
// Gets headers, skips JSON headers when body is FormData
|
|
475
165
|
function getHeaders(headers = {}, method = null, body = null) {
|
|
476
166
|
const result = Object.assign({}, headers);
|
|
477
|
-
//
|
|
478
|
-
if (!result.Authorization) {
|
|
479
|
-
const token = getToken();
|
|
480
|
-
Object.assign(result, getAuthorizationHeader(result, token));
|
|
481
|
-
}
|
|
482
|
-
method = getMethod(method, body);
|
|
483
|
-
// if it’s a multipart FormData, let the browser set the boundary header
|
|
167
|
+
// let browser set boundary
|
|
484
168
|
if (body instanceof FormData) {
|
|
485
169
|
return result;
|
|
486
170
|
}
|
|
487
|
-
|
|
488
|
-
if (['POST', 'PUT', 'PATCH'].includes(
|
|
171
|
+
const upper = method === null || method === void 0 ? void 0 : method.toUpperCase();
|
|
172
|
+
if (['POST', 'PUT', 'PATCH'].includes(upper !== null && upper !== void 0 ? upper : '') &&
|
|
173
|
+
!result['Content-Type']) {
|
|
489
174
|
result['Content-Type'] = 'application/json';
|
|
490
175
|
}
|
|
491
176
|
return result;
|
|
@@ -555,7 +240,7 @@ function fetchIt(endpoint_1) {
|
|
|
555
240
|
// 2) choose the URL
|
|
556
241
|
let url = endpoint;
|
|
557
242
|
// 3) prepare headers & body
|
|
558
|
-
headers = Object.assign(Object.assign(
|
|
243
|
+
headers = Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), headers);
|
|
559
244
|
const opts = {
|
|
560
245
|
method,
|
|
561
246
|
credentials: withCredentials ? "include" : "same-origin",
|
|
@@ -690,6 +375,9 @@ function url_to_path(urlStr, all_paths) {
|
|
|
690
375
|
}
|
|
691
376
|
return null;
|
|
692
377
|
}
|
|
378
|
+
function urljoin(...parts) {
|
|
379
|
+
return urlJoin(...parts);
|
|
380
|
+
}
|
|
693
381
|
|
|
694
382
|
function assertPath(path) {
|
|
695
383
|
if (typeof path !== 'string') {
|
|
@@ -1193,39 +881,126 @@ posix.posix = posix;
|
|
|
1193
881
|
|
|
1194
882
|
var pathBrowserify = posix;
|
|
1195
883
|
|
|
1196
|
-
function
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
884
|
+
function split_outside_brackets(s) {
|
|
885
|
+
let depth = 0;
|
|
886
|
+
let start = 0;
|
|
887
|
+
const out = [];
|
|
888
|
+
for (let i = 0; i < s.length; i++) {
|
|
889
|
+
const c = s[i];
|
|
890
|
+
if (c === "[")
|
|
891
|
+
depth++;
|
|
892
|
+
else if (c === "]")
|
|
893
|
+
depth--;
|
|
894
|
+
// split only when NOT inside brackets
|
|
895
|
+
if (c === "," && depth === 0) {
|
|
896
|
+
out.push(s.slice(start, i));
|
|
897
|
+
start = i + 1;
|
|
898
|
+
}
|
|
1211
899
|
}
|
|
1212
|
-
|
|
900
|
+
out.push(s.slice(start));
|
|
901
|
+
return out;
|
|
902
|
+
}
|
|
903
|
+
function parse_nested_list(s) {
|
|
904
|
+
// strip outer brackets
|
|
905
|
+
const inner = s.slice(1, -1).trim();
|
|
906
|
+
const parts = split_outside_brackets(inner);
|
|
907
|
+
const result = [];
|
|
908
|
+
for (let p of parts) {
|
|
909
|
+
p = p.trim();
|
|
910
|
+
if (p.startsWith("[") && p.endsWith("]")) {
|
|
911
|
+
// recursively parse nested list
|
|
912
|
+
result.push(parse_nested_list(p));
|
|
913
|
+
}
|
|
914
|
+
else {
|
|
915
|
+
result.push(p);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
return result;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function ensure_list(obj) {
|
|
922
|
+
if (obj == null)
|
|
923
|
+
return [];
|
|
924
|
+
if (Array.isArray(obj)) {
|
|
925
|
+
return obj.flatMap(item => ensure_list(item));
|
|
926
|
+
}
|
|
927
|
+
const s = String(obj).trim();
|
|
928
|
+
if (s.startsWith("[") && s.endsWith("]")) {
|
|
929
|
+
return parse_nested_list(s);
|
|
930
|
+
}
|
|
931
|
+
return split_outside_brackets(s).map(x => x.trim());
|
|
932
|
+
}
|
|
933
|
+
// coerce any single value into a number (0 if it can't)
|
|
934
|
+
function ensure_number(x) {
|
|
935
|
+
const n = Number(x);
|
|
936
|
+
return isNaN(n) ? 0 : n;
|
|
1213
937
|
}
|
|
1214
938
|
function ensure_string(obj) {
|
|
1215
939
|
return String(obj);
|
|
1216
940
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
941
|
+
function ensurelist(obj) {
|
|
942
|
+
return ensure_list(obj);
|
|
943
|
+
}
|
|
944
|
+
function assureList(obj) {
|
|
945
|
+
return ensure_list(obj);
|
|
946
|
+
}
|
|
947
|
+
function assure_list(obj) {
|
|
948
|
+
return ensure_list(obj);
|
|
949
|
+
}
|
|
950
|
+
function ensureList(obj) {
|
|
951
|
+
return ensure_list(obj);
|
|
952
|
+
}
|
|
953
|
+
function assurelist(obj) {
|
|
954
|
+
return ensure_list(obj);
|
|
955
|
+
}
|
|
956
|
+
function ensurenumber(x) {
|
|
957
|
+
return ensure_number(x);
|
|
958
|
+
}
|
|
959
|
+
function assureNumber(x) {
|
|
960
|
+
return ensure_number(x);
|
|
961
|
+
}
|
|
962
|
+
function ensureNumber(x) {
|
|
963
|
+
return ensure_number(x);
|
|
964
|
+
}
|
|
965
|
+
function assurenumber(x) {
|
|
966
|
+
return ensure_number(x);
|
|
967
|
+
}
|
|
968
|
+
function assure_number(x) {
|
|
969
|
+
return ensure_number(x);
|
|
970
|
+
}
|
|
971
|
+
function ensurestring(obj) {
|
|
972
|
+
return ensure_string(obj);
|
|
973
|
+
}
|
|
974
|
+
function ensureString(obj) {
|
|
975
|
+
return ensure_string(obj);
|
|
976
|
+
}
|
|
977
|
+
function assureString(obj) {
|
|
978
|
+
return ensure_string(obj);
|
|
979
|
+
}
|
|
980
|
+
function assurestring(obj) {
|
|
981
|
+
return ensure_string(obj);
|
|
982
|
+
}
|
|
983
|
+
function assure_string(obj) {
|
|
984
|
+
return ensure_string(obj);
|
|
985
|
+
}
|
|
986
|
+
function assurearray(obj) {
|
|
987
|
+
return ensure_list(obj);
|
|
988
|
+
}
|
|
989
|
+
function ensurearray(obj) {
|
|
990
|
+
return ensure_list(obj);
|
|
991
|
+
}
|
|
992
|
+
function ensure_array(obj) {
|
|
993
|
+
return ensure_list(obj);
|
|
994
|
+
}
|
|
995
|
+
function ensureArray(obj) {
|
|
996
|
+
return ensure_list(obj);
|
|
997
|
+
}
|
|
998
|
+
function assure_array(obj) {
|
|
999
|
+
return ensure_list(obj);
|
|
1000
|
+
}
|
|
1001
|
+
function assureArray(obj) {
|
|
1002
|
+
return ensure_list(obj);
|
|
1003
|
+
}
|
|
1229
1004
|
|
|
1230
1005
|
function cleanText(input) {
|
|
1231
1006
|
// Replace delimiters with spaces and split
|
|
@@ -1692,71 +1467,80 @@ function stripPrefixes(str, bases = []) {
|
|
|
1692
1467
|
}
|
|
1693
1468
|
return str;
|
|
1694
1469
|
}
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
if (
|
|
1705
|
-
|
|
1470
|
+
function tryEatPrefix(str, length, ...objs) {
|
|
1471
|
+
str = String(str);
|
|
1472
|
+
objs = ensure_list(objs);
|
|
1473
|
+
const prefix = str.slice(0, length);
|
|
1474
|
+
if (length < 0) {
|
|
1475
|
+
const start = str.length + length;
|
|
1476
|
+
const actualPrefix = str.slice(start);
|
|
1477
|
+
return objs.includes(actualPrefix) ? [str.slice(0, start), true] : [str, false];
|
|
1478
|
+
}
|
|
1479
|
+
if (objs.includes(prefix)) {
|
|
1480
|
+
return [str.slice(length), true];
|
|
1706
1481
|
}
|
|
1707
|
-
|
|
1482
|
+
return [str, false];
|
|
1483
|
+
}
|
|
1484
|
+
/** Python-equivalent eatInner */
|
|
1485
|
+
function eatInner(str, listObjects) {
|
|
1708
1486
|
str = String(str);
|
|
1709
|
-
|
|
1710
|
-
while
|
|
1487
|
+
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
1488
|
+
// Keep removing from left while leftmost char is in the set
|
|
1489
|
+
while (str.length > 0 && chars.includes(str[0])) {
|
|
1711
1490
|
str = str.slice(1);
|
|
1712
1491
|
}
|
|
1713
1492
|
return str;
|
|
1714
1493
|
}
|
|
1715
|
-
/**
|
|
1716
|
-
* Removes characters from the end of the string
|
|
1717
|
-
* if they are found in the list of characters.
|
|
1718
|
-
*
|
|
1719
|
-
* @param str - The input string.
|
|
1720
|
-
* @param listObjects - A string or an array of characters to remove.
|
|
1721
|
-
* @returns The modified string.
|
|
1722
|
-
*/
|
|
1494
|
+
/** Python-equivalent eatOuter */
|
|
1723
1495
|
function eatOuter(str, listObjects) {
|
|
1724
|
-
if (!Array.isArray(listObjects)) {
|
|
1725
|
-
listObjects = [listObjects];
|
|
1726
|
-
}
|
|
1727
|
-
// Ensure str is a string
|
|
1728
1496
|
str = String(str);
|
|
1729
|
-
|
|
1730
|
-
|
|
1497
|
+
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
1498
|
+
if (!str || chars.length === 0)
|
|
1499
|
+
return str;
|
|
1500
|
+
for (let i = 0; i < str.length; i++) {
|
|
1501
|
+
if (!str)
|
|
1502
|
+
return str;
|
|
1503
|
+
const last = str[str.length - 1];
|
|
1504
|
+
if (!chars.includes(last)) {
|
|
1505
|
+
return str;
|
|
1506
|
+
}
|
|
1731
1507
|
str = str.slice(0, -1);
|
|
1732
1508
|
}
|
|
1733
1509
|
return str;
|
|
1734
1510
|
}
|
|
1735
|
-
/**
|
|
1736
|
-
* Removes characters from both the beginning and the end of the string
|
|
1737
|
-
* if they are found in the list of characters.
|
|
1738
|
-
*
|
|
1739
|
-
* @param str - The input string.
|
|
1740
|
-
* @param listObjects - A string or an array of characters to remove.
|
|
1741
|
-
* @returns The modified string.
|
|
1742
|
-
*/
|
|
1511
|
+
/** Python-equivalent eatAll */
|
|
1743
1512
|
function eatAll(str, listObjects) {
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1513
|
+
str = String(str);
|
|
1514
|
+
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
1515
|
+
str = eatInner(str, chars);
|
|
1516
|
+
str = eatOuter(str, chars);
|
|
1517
|
+
return str;
|
|
1518
|
+
}
|
|
1519
|
+
// Plug in the actual version from your project
|
|
1520
|
+
function get_alpha_ints(opts) {
|
|
1521
|
+
// REPLACE WITH YOUR REAL IMPLEMENTATION
|
|
1522
|
+
return [];
|
|
1523
|
+
}
|
|
1524
|
+
/** Python-equivalent eatElse */
|
|
1525
|
+
function eatElse(stringObj, chars, ints = true, alpha = true, lower = true, capitalize = true, string = true, listObj = true) {
|
|
1526
|
+
stringObj = String(stringObj);
|
|
1527
|
+
const alphaInts = get_alpha_ints();
|
|
1528
|
+
let ls = ensure_list(chars || []).concat(alphaInts);
|
|
1529
|
+
while (true) {
|
|
1530
|
+
if (!stringObj)
|
|
1531
|
+
return stringObj;
|
|
1532
|
+
const startOk = !ls.includes(stringObj[0]);
|
|
1533
|
+
const endOk = !ls.includes(stringObj[stringObj.length - 1]);
|
|
1534
|
+
const shouldEat = startOk || endOk;
|
|
1535
|
+
if (!shouldEat)
|
|
1536
|
+
return stringObj;
|
|
1537
|
+
if (stringObj && startOk) {
|
|
1538
|
+
stringObj = stringObj.length === 1 ? "" : stringObj.slice(1);
|
|
1539
|
+
}
|
|
1540
|
+
if (stringObj && endOk) {
|
|
1541
|
+
stringObj = stringObj.length === 1 ? "" : stringObj.slice(0, -1);
|
|
1757
1542
|
}
|
|
1758
1543
|
}
|
|
1759
|
-
return result;
|
|
1760
1544
|
}
|
|
1761
1545
|
function tryParse(obj) {
|
|
1762
1546
|
try {
|
|
@@ -1780,6 +1564,15 @@ function create_list_string(array_obj) {
|
|
|
1780
1564
|
}
|
|
1781
1565
|
return string;
|
|
1782
1566
|
}
|
|
1567
|
+
function eatall(str, listObjects) {
|
|
1568
|
+
return eatAll(str, listObjects);
|
|
1569
|
+
}
|
|
1570
|
+
function eatinner(str, listObjects) {
|
|
1571
|
+
return eatInner(str, listObjects);
|
|
1572
|
+
}
|
|
1573
|
+
function eatouter(str, listObjects) {
|
|
1574
|
+
return eatOuter(str, listObjects);
|
|
1575
|
+
}
|
|
1783
1576
|
|
|
1784
1577
|
/**
|
|
1785
1578
|
* In the browser we already have a WHATWG URL constructor on window.
|
|
@@ -1814,9 +1607,11 @@ function get_basename(filePath) {
|
|
|
1814
1607
|
return '';
|
|
1815
1608
|
return pathBrowserify.basename(filePath);
|
|
1816
1609
|
}
|
|
1817
|
-
function get_filename(
|
|
1818
|
-
|
|
1819
|
-
|
|
1610
|
+
function get_filename(filePath) {
|
|
1611
|
+
if (!filePath)
|
|
1612
|
+
return '';
|
|
1613
|
+
const ext = pathBrowserify.extname(filePath);
|
|
1614
|
+
return pathBrowserify.basename(filePath, ext);
|
|
1820
1615
|
}
|
|
1821
1616
|
function get_extname(filePath) {
|
|
1822
1617
|
if (!filePath)
|
|
@@ -1854,32 +1649,36 @@ function get_relative_path(basePath, targetPath) {
|
|
|
1854
1649
|
}
|
|
1855
1650
|
}
|
|
1856
1651
|
/**
|
|
1857
|
-
* Join multiple path segments,
|
|
1652
|
+
* Join multiple path segments — clean, predictable, bulletproof.
|
|
1653
|
+
*
|
|
1654
|
+
* Accepts ANYTHING that ensure_list can handle:
|
|
1655
|
+
* • 'a,b,c'
|
|
1656
|
+
* • ['a', 'b,c']
|
|
1657
|
+
* • 'a/b/c'
|
|
1658
|
+
* • '/a/', 'b//c'
|
|
1659
|
+
* • mixed arrays, comma strings, whatever
|
|
1858
1660
|
*
|
|
1859
|
-
*
|
|
1860
|
-
* make_path('/foo','bar','baz')
|
|
1861
|
-
* make_path(['/foo','bar','baz'])
|
|
1661
|
+
* Always returns a clean POSIX path string. Never a list.
|
|
1862
1662
|
*/
|
|
1863
|
-
function make_path(...
|
|
1864
|
-
//
|
|
1865
|
-
const
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
let
|
|
1871
|
-
if (
|
|
1872
|
-
|
|
1663
|
+
function make_path(...parts) {
|
|
1664
|
+
// Normalize incoming segments into a flat list
|
|
1665
|
+
const segments = ensure_list(parts).map(x => String(x));
|
|
1666
|
+
let out = "";
|
|
1667
|
+
for (let i = 0; i < segments.length; i++) {
|
|
1668
|
+
const seg = segments[i];
|
|
1669
|
+
// Normalize a segment:
|
|
1670
|
+
let cleaned = eatOuter(seg, "/"); // trim trailing slashes
|
|
1671
|
+
if (!cleaned)
|
|
1672
|
+
continue;
|
|
1673
|
+
if (out === "") {
|
|
1674
|
+
out = cleaned;
|
|
1873
1675
|
}
|
|
1874
1676
|
else {
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
// remove any trailing slash on the accumulator
|
|
1878
|
-
real_path = real_path.replace(/\/+$/, '');
|
|
1879
|
-
real_path = `${real_path}/${segment}`;
|
|
1677
|
+
cleaned = eatInner(cleaned, "/"); // trim leading slashes
|
|
1678
|
+
out = `${out}/${cleaned}`;
|
|
1880
1679
|
}
|
|
1881
1680
|
}
|
|
1882
|
-
return
|
|
1681
|
+
return out;
|
|
1883
1682
|
}
|
|
1884
1683
|
function sanitizeFilename(filename) {
|
|
1885
1684
|
return filename
|
|
@@ -1893,7 +1692,7 @@ function sanitizeFilename(filename) {
|
|
|
1893
1692
|
function make_sanitized_path(...paths) {
|
|
1894
1693
|
let real_path = '';
|
|
1895
1694
|
for (let i = 0; i < paths.length; i++) {
|
|
1896
|
-
const sanitized = sanitizeFilename(
|
|
1695
|
+
const sanitized = sanitizeFilename(eatOuter(paths[i], '/'));
|
|
1897
1696
|
if (i === 0) {
|
|
1898
1697
|
real_path = sanitized;
|
|
1899
1698
|
}
|
|
@@ -1911,6 +1710,51 @@ function normalizeUrl(base, p) {
|
|
|
1911
1710
|
// collapse multiple “//” into one, but keep the “://” after protocol
|
|
1912
1711
|
return `${cleanBase}/${cleanPath}`.replace(/([^:])\/{2,}/g, '$1/');
|
|
1913
1712
|
}
|
|
1713
|
+
function pathjoin(...parts) {
|
|
1714
|
+
return make_path(...parts);
|
|
1715
|
+
}
|
|
1716
|
+
function pathJoin(...parts) {
|
|
1717
|
+
return make_path(...parts);
|
|
1718
|
+
}
|
|
1719
|
+
function makepath(...parts) {
|
|
1720
|
+
return make_path(...parts);
|
|
1721
|
+
}
|
|
1722
|
+
function makePath(...parts) {
|
|
1723
|
+
return make_path(...parts);
|
|
1724
|
+
}
|
|
1725
|
+
function path_join(...parts) {
|
|
1726
|
+
return make_path(...parts);
|
|
1727
|
+
}
|
|
1728
|
+
function getSplitext(filePath) {
|
|
1729
|
+
return get_splitext(filePath);
|
|
1730
|
+
}
|
|
1731
|
+
function getsplitext(filePath) {
|
|
1732
|
+
return get_splitext(filePath);
|
|
1733
|
+
}
|
|
1734
|
+
function getextname(filePath) {
|
|
1735
|
+
return get_extname(filePath);
|
|
1736
|
+
}
|
|
1737
|
+
function getExtname(filePath) {
|
|
1738
|
+
return get_extname(filePath);
|
|
1739
|
+
}
|
|
1740
|
+
function getfilename(filePath) {
|
|
1741
|
+
return get_filename(filePath);
|
|
1742
|
+
}
|
|
1743
|
+
function getFilename(filePath) {
|
|
1744
|
+
return get_filename(filePath);
|
|
1745
|
+
}
|
|
1746
|
+
function getbasename(filePath) {
|
|
1747
|
+
return get_basename(filePath);
|
|
1748
|
+
}
|
|
1749
|
+
function getBasename(filePath) {
|
|
1750
|
+
return get_basename(filePath);
|
|
1751
|
+
}
|
|
1752
|
+
function getdirname(filePath) {
|
|
1753
|
+
return get_dirname(filePath);
|
|
1754
|
+
}
|
|
1755
|
+
function getDirname(filePath) {
|
|
1756
|
+
return get_dirname(filePath);
|
|
1757
|
+
}
|
|
1914
1758
|
|
|
1915
1759
|
/**
|
|
1916
1760
|
* Returns the absolute path of the current file.
|
|
@@ -2205,39 +2049,221 @@ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit)
|
|
|
2205
2049
|
const isFiniteNum = (x) => Number.isFinite(x);
|
|
2206
2050
|
const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
|
|
2207
2051
|
|
|
2208
|
-
function
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
? 'bg-gray-600 hover:bg-gray-700 focus:ring-gray-500'
|
|
2220
|
-
: 'bg-gray-200 hover:bg-gray-300 focus:ring-gray-400',
|
|
2221
|
-
green: 'bg-green-600 text-white hover:bg-green-700 focus:ring-green-500',
|
|
2222
|
-
blue: variant === 'primary'
|
|
2223
|
-
? 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500'
|
|
2224
|
-
: 'bg-blue-200 hover:bg-blue-300 focus:ring-blue-400',
|
|
2225
|
-
};
|
|
2226
|
-
return (jsxRuntime.jsx("button", Object.assign({ className: `${base} ${variantStyles[variant]} ${palette[color]} ${className}` }, rest, { children: children })));
|
|
2052
|
+
function getSafeDocument() {
|
|
2053
|
+
return typeof document !== 'undefined' ? document : undefined;
|
|
2054
|
+
}
|
|
2055
|
+
function getDocumentProp(...keys) {
|
|
2056
|
+
let obj = getSafeDocument();
|
|
2057
|
+
for (const k of keys) {
|
|
2058
|
+
if (obj == null || typeof obj !== 'object')
|
|
2059
|
+
return undefined;
|
|
2060
|
+
obj = obj[k];
|
|
2061
|
+
}
|
|
2062
|
+
return obj;
|
|
2227
2063
|
}
|
|
2228
2064
|
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2065
|
+
/**
|
|
2066
|
+
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
2067
|
+
* Returns `undefined` if any step is missing.
|
|
2068
|
+
*/
|
|
2069
|
+
function safeGlobalProp(...path) {
|
|
2070
|
+
let obj = globalThis;
|
|
2071
|
+
for (const key of path) {
|
|
2072
|
+
if (obj == null || typeof obj !== "object" || !(key in obj)) {
|
|
2073
|
+
return undefined;
|
|
2074
|
+
}
|
|
2075
|
+
obj = obj[key];
|
|
2076
|
+
}
|
|
2077
|
+
return obj;
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
/**
|
|
2081
|
+
* Returns `window` if running in a browser, otherwise `undefined`.
|
|
2082
|
+
*/
|
|
2083
|
+
function getSafeLocalStorage() {
|
|
2084
|
+
if (typeof window === 'undefined')
|
|
2085
|
+
return undefined;
|
|
2086
|
+
try {
|
|
2087
|
+
return window.localStorage;
|
|
2088
|
+
}
|
|
2089
|
+
catch (_a) {
|
|
2090
|
+
return undefined; // e.g. Safari private-mode block
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Call a Storage method by name, silencing any errors or missing storage.
|
|
2095
|
+
*
|
|
2096
|
+
* @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
|
|
2097
|
+
* @param args The arguments you’d normally pass to that method.
|
|
2098
|
+
* @returns The method’s return value, or undefined if storage/method isn’t available.
|
|
2099
|
+
*/
|
|
2100
|
+
function callStorage(method, ...args) {
|
|
2101
|
+
const storage = getSafeLocalStorage();
|
|
2102
|
+
if (!storage)
|
|
2103
|
+
return undefined;
|
|
2104
|
+
const fn = storage[method];
|
|
2105
|
+
if (typeof fn !== 'function')
|
|
2106
|
+
return undefined;
|
|
2107
|
+
try {
|
|
2108
|
+
// @ts-ignore – TS can’t infer that this is callable
|
|
2109
|
+
return fn.apply(storage, args);
|
|
2110
|
+
}
|
|
2111
|
+
catch (_a) {
|
|
2112
|
+
return undefined;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
|
|
2117
|
+
* Returns `undefined` on any error.
|
|
2118
|
+
*/
|
|
2119
|
+
function safeStorage(storageName, method, ...args) {
|
|
2120
|
+
try {
|
|
2121
|
+
const store = safeGlobalProp(storageName);
|
|
2122
|
+
if (!store || typeof store[method] !== "function")
|
|
2123
|
+
return undefined;
|
|
2124
|
+
// @ts-ignore
|
|
2125
|
+
return store[method](...args);
|
|
2126
|
+
}
|
|
2127
|
+
catch (_a) {
|
|
2128
|
+
return undefined;
|
|
2129
|
+
}
|
|
2232
2130
|
}
|
|
2233
2131
|
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2132
|
+
/**
|
|
2133
|
+
* Returns the global window object if it exists, otherwise undefined.
|
|
2134
|
+
*/
|
|
2135
|
+
function getSafeWindow() {
|
|
2136
|
+
return typeof window !== 'undefined' ? window : undefined;
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Safely call a method on window by name.
|
|
2140
|
+
*
|
|
2141
|
+
* @param method The Window method to call (e.g. "alert", "open", etc.).
|
|
2142
|
+
* @param args Arguments to pass to that method.
|
|
2143
|
+
* @returns The method’s return value, or undefined if
|
|
2144
|
+
* window/method isn’t available or throws.
|
|
2145
|
+
*/
|
|
2146
|
+
function callWindowMethod(method, ...args) {
|
|
2147
|
+
const w = getSafeWindow();
|
|
2148
|
+
if (!w)
|
|
2149
|
+
return undefined;
|
|
2150
|
+
const fn = w[method];
|
|
2151
|
+
if (typeof fn !== 'function')
|
|
2152
|
+
return undefined;
|
|
2153
|
+
try {
|
|
2154
|
+
// cast to any so TS doesn’t complain about apply/invoke
|
|
2155
|
+
return fn(...args);
|
|
2156
|
+
}
|
|
2157
|
+
catch (_a) {
|
|
2158
|
+
return undefined;
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
/** implementation */
|
|
2162
|
+
function getWindowProp(...keys) {
|
|
2163
|
+
let obj = getSafeWindow();
|
|
2164
|
+
for (const k of keys) {
|
|
2165
|
+
if (obj == null || typeof obj !== 'object')
|
|
2166
|
+
return undefined;
|
|
2167
|
+
obj = obj[k];
|
|
2168
|
+
}
|
|
2169
|
+
return obj;
|
|
2170
|
+
}
|
|
2171
|
+
function getWindowHost() {
|
|
2172
|
+
return getWindowProp('location', 'host');
|
|
2237
2173
|
}
|
|
2238
2174
|
|
|
2239
|
-
|
|
2240
|
-
|
|
2175
|
+
// src/functions/read_utils/src/read_utils.ts
|
|
2176
|
+
let fs = null;
|
|
2177
|
+
let path = null;
|
|
2178
|
+
function getFsModules() {
|
|
2179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2180
|
+
var _a;
|
|
2181
|
+
if (!fs && !path && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
2182
|
+
try {
|
|
2183
|
+
// prevent bundlers from resolving these at build time
|
|
2184
|
+
fs = (new Function("return require('fs')"))();
|
|
2185
|
+
path = (new Function("return require('path')"))();
|
|
2186
|
+
}
|
|
2187
|
+
catch (_b) {
|
|
2188
|
+
fs = null;
|
|
2189
|
+
path = null;
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
return { fs, path };
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
/**
|
|
2196
|
+
* Reads a JSON file, either via Node’s fs (if available)
|
|
2197
|
+
* or via window.fetch in the browser. Never throws — returns
|
|
2198
|
+
* the parsed object or null on any error.
|
|
2199
|
+
*/
|
|
2200
|
+
function readJsonFile(relativeOrAbsolutePath) {
|
|
2201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2202
|
+
var _a;
|
|
2203
|
+
// 1) Try Node.js fs (only at runtime, not bundled)
|
|
2204
|
+
if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
2205
|
+
try {
|
|
2206
|
+
const { fs, path } = yield getFsModules();
|
|
2207
|
+
if (fs && path) {
|
|
2208
|
+
const filePath = path.isAbsolute(relativeOrAbsolutePath)
|
|
2209
|
+
? relativeOrAbsolutePath
|
|
2210
|
+
: path.resolve(process.cwd(), relativeOrAbsolutePath);
|
|
2211
|
+
const text = fs.readFileSync(filePath, "utf8");
|
|
2212
|
+
return JSON.parse(text);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
catch (_b) {
|
|
2216
|
+
// swallow and fall back
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
// 2) Try browser fetch
|
|
2220
|
+
const fetchFn = safeGlobalProp("fetch");
|
|
2221
|
+
if (typeof fetchFn !== "function") {
|
|
2222
|
+
return null;
|
|
2223
|
+
}
|
|
2224
|
+
let url = relativeOrAbsolutePath;
|
|
2225
|
+
const baseURI = safeGlobalProp("document", "baseURI");
|
|
2226
|
+
if (baseURI) {
|
|
2227
|
+
try {
|
|
2228
|
+
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
2229
|
+
}
|
|
2230
|
+
catch (_c) {
|
|
2231
|
+
/* keep url as-is */
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
try {
|
|
2235
|
+
const res = yield fetchFn(url);
|
|
2236
|
+
if (!res.ok)
|
|
2237
|
+
return null;
|
|
2238
|
+
return (yield res.json());
|
|
2239
|
+
}
|
|
2240
|
+
catch (_d) {
|
|
2241
|
+
return null;
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2245
|
+
function getConfigContent() {
|
|
2246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2247
|
+
try {
|
|
2248
|
+
// `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
|
|
2249
|
+
const cfg = yield readJsonFile('./config.json');
|
|
2250
|
+
return cfg;
|
|
2251
|
+
}
|
|
2252
|
+
catch (_a) {
|
|
2253
|
+
// swallow errors & return null so callers can detect “no config”
|
|
2254
|
+
return null;
|
|
2255
|
+
}
|
|
2256
|
+
});
|
|
2257
|
+
}
|
|
2258
|
+
// 2) Pull a single key out of that object
|
|
2259
|
+
function getConfigVar() {
|
|
2260
|
+
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
2261
|
+
const cfg = yield getConfigContent();
|
|
2262
|
+
if (cfg && typeof cfg === 'object' && key in cfg) {
|
|
2263
|
+
return cfg[key];
|
|
2264
|
+
}
|
|
2265
|
+
return undefined;
|
|
2266
|
+
});
|
|
2241
2267
|
}
|
|
2242
2268
|
|
|
2243
2269
|
// src/functions/config_utils/src/config_utils.ts
|
|
@@ -2348,28 +2374,10 @@ function get_keyword_string(keywords) {
|
|
|
2348
2374
|
return allString;
|
|
2349
2375
|
}
|
|
2350
2376
|
|
|
2351
|
-
Object.defineProperty(exports, "useCallback", {
|
|
2352
|
-
enumerable: true,
|
|
2353
|
-
get: function () { return react.useCallback; }
|
|
2354
|
-
});
|
|
2355
|
-
Object.defineProperty(exports, "useEffect", {
|
|
2356
|
-
enumerable: true,
|
|
2357
|
-
get: function () { return react.useEffect; }
|
|
2358
|
-
});
|
|
2359
|
-
Object.defineProperty(exports, "useRef", {
|
|
2360
|
-
enumerable: true,
|
|
2361
|
-
get: function () { return react.useRef; }
|
|
2362
|
-
});
|
|
2363
|
-
Object.defineProperty(exports, "useState", {
|
|
2364
|
-
enumerable: true,
|
|
2365
|
-
get: function () { return react.useState; }
|
|
2366
|
-
});
|
|
2367
2377
|
exports.API_PREFIX = API_PREFIX;
|
|
2368
2378
|
exports.ATTOSECOND = ATTOSECOND;
|
|
2369
2379
|
exports.BASE_URL = BASE_URL;
|
|
2370
|
-
exports.Button = Button;
|
|
2371
2380
|
exports.CENTISECOND = CENTISECOND;
|
|
2372
|
-
exports.Checkbox = Checkbox;
|
|
2373
2381
|
exports.DAY = DAY;
|
|
2374
2382
|
exports.DAY_IN_S = DAY_IN_S;
|
|
2375
2383
|
exports.DECISECOND = DECISECOND;
|
|
@@ -2382,7 +2390,6 @@ exports.FEET_PER_METER = FEET_PER_METER;
|
|
|
2382
2390
|
exports.FEMTOSECOND = FEMTOSECOND;
|
|
2383
2391
|
exports.HOUR = HOUR;
|
|
2384
2392
|
exports.HOUR_IN_S = HOUR_IN_S;
|
|
2385
|
-
exports.Input = Input;
|
|
2386
2393
|
exports.KMS_PER_METER = KMS_PER_METER;
|
|
2387
2394
|
exports.MEDIA_TYPES = MEDIA_TYPES;
|
|
2388
2395
|
exports.METERS_PER_FOOT = METERS_PER_FOOT;
|
|
@@ -2410,7 +2417,6 @@ exports.SECONDS_PER_HOUR = SECONDS_PER_HOUR;
|
|
|
2410
2417
|
exports.SECONDS_PER_MINUTE = SECONDS_PER_MINUTE;
|
|
2411
2418
|
exports.SUB_DIR = SUB_DIR;
|
|
2412
2419
|
exports.SpeedConverter = SpeedConverter;
|
|
2413
|
-
exports.Spinner = Spinner;
|
|
2414
2420
|
exports.TIME_ALIASES = TIME_ALIASES;
|
|
2415
2421
|
exports.TIME_FACTORS = TIME_FACTORS;
|
|
2416
2422
|
exports.TimeConverter = TimeConverter;
|
|
@@ -2426,6 +2432,10 @@ exports.assure_array = assure_array;
|
|
|
2426
2432
|
exports.assure_list = assure_list;
|
|
2427
2433
|
exports.assure_number = assure_number;
|
|
2428
2434
|
exports.assure_string = assure_string;
|
|
2435
|
+
exports.assurearray = assurearray;
|
|
2436
|
+
exports.assurelist = assurelist;
|
|
2437
|
+
exports.assurenumber = assurenumber;
|
|
2438
|
+
exports.assurestring = assurestring;
|
|
2429
2439
|
exports.callStorage = callStorage;
|
|
2430
2440
|
exports.callWindowMethod = callWindowMethod;
|
|
2431
2441
|
exports.canonDist = canonDist;
|
|
@@ -2441,14 +2451,15 @@ exports.convertDistance = convertDistance;
|
|
|
2441
2451
|
exports.convertSpeed = convertSpeed;
|
|
2442
2452
|
exports.convertTime = convertTime;
|
|
2443
2453
|
exports.create_list_string = create_list_string;
|
|
2444
|
-
exports.currentUsername = currentUsername;
|
|
2445
|
-
exports.currentUsernames = currentUsernames;
|
|
2446
2454
|
exports.decodeJwt = decodeJwt;
|
|
2447
2455
|
exports.distanceToMeters = distanceToMeters;
|
|
2448
2456
|
exports.eatAll = eatAll;
|
|
2449
|
-
exports.
|
|
2457
|
+
exports.eatElse = eatElse;
|
|
2450
2458
|
exports.eatInner = eatInner;
|
|
2451
2459
|
exports.eatOuter = eatOuter;
|
|
2460
|
+
exports.eatall = eatall;
|
|
2461
|
+
exports.eatinner = eatinner;
|
|
2462
|
+
exports.eatouter = eatouter;
|
|
2452
2463
|
exports.ensureArray = ensureArray;
|
|
2453
2464
|
exports.ensureList = ensureList;
|
|
2454
2465
|
exports.ensureNumber = ensureNumber;
|
|
@@ -2457,6 +2468,10 @@ exports.ensure_array = ensure_array;
|
|
|
2457
2468
|
exports.ensure_list = ensure_list;
|
|
2458
2469
|
exports.ensure_number = ensure_number;
|
|
2459
2470
|
exports.ensure_string = ensure_string;
|
|
2471
|
+
exports.ensurearray = ensurearray;
|
|
2472
|
+
exports.ensurelist = ensurelist;
|
|
2473
|
+
exports.ensurenumber = ensurenumber;
|
|
2474
|
+
exports.ensurestring = ensurestring;
|
|
2460
2475
|
exports.exponential = exponential;
|
|
2461
2476
|
exports.fetchIndexHtml = fetchIndexHtml;
|
|
2462
2477
|
exports.fetchIndexHtmlContainer = fetchIndexHtmlContainer;
|
|
@@ -2483,8 +2498,8 @@ exports.getAllFileTypes = getAllFileTypes;
|
|
|
2483
2498
|
exports.getAllFileTypesSync = getAllFileTypesSync;
|
|
2484
2499
|
exports.getAlphaNum = getAlphaNum;
|
|
2485
2500
|
exports.getAlphas = getAlphas;
|
|
2486
|
-
exports.getAuthorizationHeader = getAuthorizationHeader;
|
|
2487
2501
|
exports.getBaseDir = getBaseDir;
|
|
2502
|
+
exports.getBasename = getBasename;
|
|
2488
2503
|
exports.getBody = getBody;
|
|
2489
2504
|
exports.getChar = getChar;
|
|
2490
2505
|
exports.getCleanArray = getCleanArray;
|
|
@@ -2493,11 +2508,14 @@ exports.getConfig = getConfig;
|
|
|
2493
2508
|
exports.getConfigContent = getConfigContent;
|
|
2494
2509
|
exports.getConfigVar = getConfigVar;
|
|
2495
2510
|
exports.getDbConfigsPath = getDbConfigsPath;
|
|
2511
|
+
exports.getDirname = getDirname;
|
|
2496
2512
|
exports.getDistDir = getDistDir;
|
|
2497
2513
|
exports.getDocumentProp = getDocumentProp;
|
|
2498
2514
|
exports.getEnvDir = getEnvDir;
|
|
2499
2515
|
exports.getEnvPath = getEnvPath;
|
|
2516
|
+
exports.getExtname = getExtname;
|
|
2500
2517
|
exports.getFetchVars = getFetchVars;
|
|
2518
|
+
exports.getFilename = getFilename;
|
|
2501
2519
|
exports.getFunctionsDir = getFunctionsDir;
|
|
2502
2520
|
exports.getFunctionsUtilsDirectory = getFunctionsUtilsDirectory;
|
|
2503
2521
|
exports.getHeaders = getHeaders;
|
|
@@ -2516,9 +2534,9 @@ exports.getSafeLocalStorage = getSafeLocalStorage;
|
|
|
2516
2534
|
exports.getSafeWindow = getSafeWindow;
|
|
2517
2535
|
exports.getSchemasDirPath = getSchemasDirPath;
|
|
2518
2536
|
exports.getSchemasPath = getSchemasPath;
|
|
2537
|
+
exports.getSplitext = getSplitext;
|
|
2519
2538
|
exports.getSrcDir = getSrcDir;
|
|
2520
2539
|
exports.getSubstring = getSubstring;
|
|
2521
|
-
exports.getToken = getToken;
|
|
2522
2540
|
exports.getWindowHost = getWindowHost;
|
|
2523
2541
|
exports.getWindowProp = getWindowProp;
|
|
2524
2542
|
exports.get_all_file_types = get_all_file_types;
|
|
@@ -2539,8 +2557,12 @@ exports.get_window = get_window;
|
|
|
2539
2557
|
exports.get_window_location = get_window_location;
|
|
2540
2558
|
exports.get_window_parts = get_window_parts;
|
|
2541
2559
|
exports.get_window_pathname = get_window_pathname;
|
|
2560
|
+
exports.getbasename = getbasename;
|
|
2561
|
+
exports.getdirname = getdirname;
|
|
2562
|
+
exports.getextname = getextname;
|
|
2563
|
+
exports.getfilename = getfilename;
|
|
2564
|
+
exports.getsplitext = getsplitext;
|
|
2542
2565
|
exports.isFiniteNum = isFiniteNum;
|
|
2543
|
-
exports.isLoggedIn = isLoggedIn;
|
|
2544
2566
|
exports.isMediaType = isMediaType;
|
|
2545
2567
|
exports.isNum = isNum;
|
|
2546
2568
|
exports.isStrInString = isStrInString;
|
|
@@ -2548,17 +2570,20 @@ exports.isTokenExpired = isTokenExpired;
|
|
|
2548
2570
|
exports.isType = isType;
|
|
2549
2571
|
exports.is_media_type = is_media_type;
|
|
2550
2572
|
exports.loadConfig = loadConfig;
|
|
2573
|
+
exports.makePath = makePath;
|
|
2551
2574
|
exports.make_path = make_path;
|
|
2552
2575
|
exports.make_sanitized_path = make_sanitized_path;
|
|
2576
|
+
exports.makepath = makepath;
|
|
2553
2577
|
exports.metersToDistance = metersToDistance;
|
|
2554
2578
|
exports.mpsToSpeed = mpsToSpeed;
|
|
2555
2579
|
exports.normalizeUrl = normalizeUrl;
|
|
2556
2580
|
exports.parseResult = parseResult;
|
|
2581
|
+
exports.pathJoin = pathJoin;
|
|
2582
|
+
exports.path_join = path_join;
|
|
2557
2583
|
exports.path_to_url = path_to_url;
|
|
2584
|
+
exports.pathjoin = pathjoin;
|
|
2558
2585
|
exports.processKeywords = processKeywords;
|
|
2559
2586
|
exports.readJsonFile = readJsonFile;
|
|
2560
|
-
exports.removeToken = removeToken;
|
|
2561
|
-
exports.requireToken = requireToken;
|
|
2562
2587
|
exports.roundPercentage = roundPercentage;
|
|
2563
2588
|
exports.safeDivide = safeDivide;
|
|
2564
2589
|
exports.safeGlobalProp = safeGlobalProp;
|
|
@@ -2573,9 +2598,11 @@ exports.timeToSeconds = timeToSeconds;
|
|
|
2573
2598
|
exports.toMeters = toMeters;
|
|
2574
2599
|
exports.toSeconds = toSeconds;
|
|
2575
2600
|
exports.truncateString = truncateString;
|
|
2601
|
+
exports.tryEatPrefix = tryEatPrefix;
|
|
2576
2602
|
exports.tryParse = tryParse;
|
|
2577
2603
|
exports.urlJoin = urlJoin;
|
|
2578
2604
|
exports.url_to_path = url_to_path;
|
|
2605
|
+
exports.urljoin = urljoin;
|
|
2579
2606
|
exports.velocityFromMs = velocityFromMs;
|
|
2580
2607
|
exports.velocityToMs = velocityToMs;
|
|
2581
2608
|
//# sourceMappingURL=index.js.map
|