@putkoff/abstract-utilities 0.1.244 → 1.0.1

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.
Files changed (186) hide show
  1. package/dist/cjs/index.js +262 -346
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.js +261 -330
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/index.d.ts +14 -40
  6. package/dist/types/functions/auth_utils/imports.d.ts +0 -0
  7. package/dist/types/functions/auth_utils/index.d.ts +0 -0
  8. package/dist/types/functions/auth_utils/src/index.d.ts +0 -0
  9. package/dist/types/functions/auth_utils/src/token_utils.d.ts +0 -1
  10. package/dist/types/functions/config_utils/imports.d.ts +0 -0
  11. package/dist/types/functions/config_utils/index.d.ts +0 -0
  12. package/dist/types/functions/config_utils/src/config_utils.d.ts +6 -2
  13. package/dist/types/functions/config_utils/src/index.d.ts +0 -0
  14. package/dist/types/functions/constants_utils/index.d.ts +0 -0
  15. package/dist/types/functions/constants_utils/src/constants.d.ts +0 -0
  16. package/dist/types/functions/constants_utils/src/index.d.ts +0 -0
  17. package/dist/types/functions/env_utils/imports.d.ts +0 -0
  18. package/dist/types/functions/env_utils/index.d.ts +0 -0
  19. package/dist/types/functions/env_utils/src/index.d.ts +0 -0
  20. package/dist/types/functions/env_utils/src/window_utils.d.ts +0 -0
  21. package/dist/types/functions/fetch_utils/imports.d.ts +0 -0
  22. package/dist/types/functions/fetch_utils/index.d.ts +0 -0
  23. package/dist/types/functions/fetch_utils/src/fetch_utils.d.ts +2 -2
  24. package/dist/types/functions/fetch_utils/src/index.d.ts +0 -0
  25. package/dist/types/functions/fetch_utils/src/url_utils.d.ts +0 -0
  26. package/dist/types/functions/fetch_utils/src/utils.d.ts +1 -2
  27. package/dist/types/functions/index.d.ts +1 -2
  28. package/dist/types/functions/math_utils/index.d.ts +0 -0
  29. package/dist/types/functions/math_utils/safe_math.d.ts +0 -0
  30. package/dist/types/functions/path_utils/imports.d.ts +0 -0
  31. package/dist/types/functions/path_utils/index.d.ts +0 -0
  32. package/dist/types/functions/path_utils/src/base_dirs.d.ts +0 -0
  33. package/dist/types/functions/path_utils/src/function_dirs.d.ts +0 -0
  34. package/dist/types/functions/path_utils/src/index.d.ts +0 -0
  35. package/dist/types/functions/path_utils/src/misc_dirs.d.ts +0 -0
  36. package/dist/types/functions/path_utils/src/path_utils.d.ts +0 -4
  37. package/dist/types/functions/path_utils/src/paths.d.ts +0 -0
  38. package/dist/types/functions/path_utils/src/src_dirs.d.ts +0 -0
  39. package/dist/types/functions/read_utils/imports.d.ts +0 -0
  40. package/dist/types/functions/read_utils/index.d.ts +0 -0
  41. package/dist/types/functions/read_utils/src/index.d.ts +0 -0
  42. package/dist/types/functions/read_utils/src/utils.d.ts +0 -0
  43. package/dist/types/functions/rndm_utils/imports.d.ts +0 -0
  44. package/dist/types/functions/rndm_utils/index.d.ts +0 -0
  45. package/dist/types/functions/rndm_utils/src/index.d.ts +0 -0
  46. package/dist/types/functions/rndm_utils/src/utils.d.ts +0 -1
  47. package/dist/types/functions/safe_utils/imports.d.ts +0 -0
  48. package/dist/types/functions/safe_utils/index.d.ts +0 -0
  49. package/dist/types/functions/safe_utils/src/index.d.ts +0 -0
  50. package/dist/types/functions/safe_utils/src/safe_document.d.ts +0 -0
  51. package/dist/types/functions/safe_utils/src/safe_globals.d.ts +0 -0
  52. package/dist/types/functions/safe_utils/src/safe_storage.d.ts +0 -0
  53. package/dist/types/functions/safe_utils/src/safe_window.d.ts +0 -0
  54. package/dist/types/functions/string_utils/index.d.ts +0 -0
  55. package/dist/types/functions/string_utils/src/index.d.ts +0 -0
  56. package/dist/types/functions/string_utils/src/string_utils.d.ts +0 -2
  57. package/dist/types/functions/type_utils/imports.d.ts +0 -0
  58. package/dist/types/functions/type_utils/index.d.ts +0 -0
  59. package/dist/types/functions/type_utils/src/clean_utils.d.ts +0 -0
  60. package/dist/types/functions/type_utils/src/ensure_utils.d.ts +0 -0
  61. package/dist/types/functions/type_utils/src/imports.d.ts +0 -0
  62. package/dist/types/functions/type_utils/src/index.d.ts +0 -0
  63. package/dist/types/functions/type_utils/src/json_utils.d.ts +0 -0
  64. package/dist/types/functions/type_utils/src/mime_utils.d.ts +0 -0
  65. package/dist/types/functions/type_utils/src/type_utils.d.ts +0 -0
  66. package/dist/types/functions/ui_utils/imports.d.ts +0 -0
  67. package/dist/types/functions/ui_utils/index.d.ts +0 -0
  68. package/dist/types/functions/ui_utils/src/button.d.ts +0 -0
  69. package/dist/types/functions/ui_utils/src/checkbox.d.ts +0 -0
  70. package/dist/types/functions/ui_utils/src/index.d.ts +0 -0
  71. package/dist/types/functions/ui_utils/src/input.d.ts +0 -0
  72. package/dist/types/functions/ui_utils/src/spinner.d.ts +0 -0
  73. package/dist/types/functions/variable_utils/imports.d.ts +0 -0
  74. package/dist/types/functions/variable_utils/index.d.ts +0 -0
  75. package/dist/types/functions/variable_utils/src/index.d.ts +0 -0
  76. package/dist/types/functions/variable_utils/src/variable_utils.d.ts +0 -0
  77. package/dist/types/index.d.ts +0 -0
  78. package/dist/types/types/index.d.ts +0 -0
  79. package/dist/types/types/src/ChangePassword.d.ts +0 -0
  80. package/dist/types/types/src/Files.d.ts +0 -0
  81. package/dist/types/types/src/index.d.ts +0 -0
  82. package/dist/types/types/src/login.d.ts +0 -0
  83. package/dist/types/types/src/logout.d.ts +0 -0
  84. package/dist/types/types/src/utils.d.ts +0 -0
  85. package/dist/types/utils/imports.d.ts +0 -0
  86. package/dist/types/utils/index.d.ts +0 -0
  87. package/dist/types/utils/src/Input.d.ts +0 -0
  88. package/dist/types/utils/src/config.d.ts +0 -0
  89. package/dist/types/utils/src/index.d.ts +0 -0
  90. package/package.json +89 -72
  91. package/dist/functions/auth_utils/imports.js +0 -1
  92. package/dist/functions/auth_utils/index.js +0 -1
  93. package/dist/functions/auth_utils/src/index.js +0 -1
  94. package/dist/functions/auth_utils/src/token_utils.js +0 -104
  95. package/dist/functions/config_utils/imports.js +0 -2
  96. package/dist/functions/config_utils/index.js +0 -1
  97. package/dist/functions/config_utils/src/config_utils.js +0 -16
  98. package/dist/functions/config_utils/src/index.js +0 -1
  99. package/dist/functions/constants_utils/index.js +0 -1
  100. package/dist/functions/constants_utils/src/constants.js +0 -7
  101. package/dist/functions/constants_utils/src/index.js +0 -1
  102. package/dist/functions/env_utils/imports.js +0 -1
  103. package/dist/functions/env_utils/index.js +0 -1
  104. package/dist/functions/env_utils/src/index.js +0 -1
  105. package/dist/functions/env_utils/src/window_utils.js +0 -47
  106. package/dist/functions/fetch_utils/imports.js +0 -2
  107. package/dist/functions/fetch_utils/index.js +0 -1
  108. package/dist/functions/fetch_utils/src/fetch_utils.js +0 -65
  109. package/dist/functions/fetch_utils/src/index.js +0 -3
  110. package/dist/functions/fetch_utils/src/url_utils.js +0 -83
  111. package/dist/functions/fetch_utils/src/utils.js +0 -101
  112. package/dist/functions/index.js +0 -17
  113. package/dist/functions/math_utils/index.js +0 -1
  114. package/dist/functions/math_utils/safe_math.js +0 -26
  115. package/dist/functions/path_utils/imports.js +0 -28
  116. package/dist/functions/path_utils/index.js +0 -1
  117. package/dist/functions/path_utils/src/base_dirs.js +0 -17
  118. package/dist/functions/path_utils/src/function_dirs.js +0 -42
  119. package/dist/functions/path_utils/src/index.js +0 -6
  120. package/dist/functions/path_utils/src/misc_dirs.js +0 -15
  121. package/dist/functions/path_utils/src/path_utils.browser.js +0 -3
  122. package/dist/functions/path_utils/src/path_utils.js +0 -112
  123. package/dist/functions/path_utils/src/path_utils.node.js +0 -3
  124. package/dist/functions/path_utils/src/paths.js +0 -12
  125. package/dist/functions/path_utils/src/src_dirs.js +0 -25
  126. package/dist/functions/read_utils/imports.js +0 -1
  127. package/dist/functions/read_utils/index.js +0 -1
  128. package/dist/functions/read_utils/src/index.js +0 -1
  129. package/dist/functions/read_utils/src/read_utils.browser.js +0 -17
  130. package/dist/functions/read_utils/src/utils.browser.js +0 -32
  131. package/dist/functions/read_utils/src/utils.js +0 -70
  132. package/dist/functions/rndm_utils/imports.js +0 -1
  133. package/dist/functions/rndm_utils/index.js +0 -1
  134. package/dist/functions/rndm_utils/src/index.js +0 -1
  135. package/dist/functions/rndm_utils/src/utils.js +0 -13
  136. package/dist/functions/safe_utils/imports.js +0 -1
  137. package/dist/functions/safe_utils/index.js +0 -1
  138. package/dist/functions/safe_utils/src/index.js +0 -4
  139. package/dist/functions/safe_utils/src/safe_document.js +0 -12
  140. package/dist/functions/safe_utils/src/safe_globals.js +0 -14
  141. package/dist/functions/safe_utils/src/safe_storage.js +0 -52
  142. package/dist/functions/safe_utils/src/safe_window.js +0 -42
  143. package/dist/functions/string_utils/index.js +0 -1
  144. package/dist/functions/string_utils/src/index.js +0 -1
  145. package/dist/functions/string_utils/src/string_utils.js +0 -153
  146. package/dist/functions/type_utils/imports.js +0 -1
  147. package/dist/functions/type_utils/index.js +0 -1
  148. package/dist/functions/type_utils/src/clean_utils.js +0 -38
  149. package/dist/functions/type_utils/src/ensure_utils.js +0 -33
  150. package/dist/functions/type_utils/src/index.js +0 -5
  151. package/dist/functions/type_utils/src/json_utils.js +0 -22
  152. package/dist/functions/type_utils/src/mime_utils.js +0 -311
  153. package/dist/functions/type_utils/src/type_utils.js +0 -39
  154. package/dist/functions/ui_utils/imports.js +0 -5
  155. package/dist/functions/ui_utils/index.js +0 -1
  156. package/dist/functions/ui_utils/src/button.js +0 -22
  157. package/dist/functions/ui_utils/src/checkbox.js +0 -6
  158. package/dist/functions/ui_utils/src/index.js +0 -4
  159. package/dist/functions/ui_utils/src/input.js +0 -6
  160. package/dist/functions/ui_utils/src/spinner.js +0 -4
  161. package/dist/functions/url_utils/index.js +0 -1
  162. package/dist/functions/url_utils/uri_utils.js +0 -69
  163. package/dist/functions/variable_utils/imports.js +0 -1
  164. package/dist/functions/variable_utils/index.js +0 -1
  165. package/dist/functions/variable_utils/src/index.js +0 -1
  166. package/dist/functions/variable_utils/src/variable_utils.js +0 -34
  167. package/dist/functions.json +0 -1727
  168. package/dist/index.js +0 -2
  169. package/dist/types/functions/path_utils/src/path_utils.browser.d.ts +0 -2
  170. package/dist/types/functions/path_utils/src/path_utils.node.d.ts +0 -2
  171. package/dist/types/functions/read_utils/src/read_utils.browser.d.ts +0 -1
  172. package/dist/types/functions/read_utils/src/utils.browser.d.ts +0 -3
  173. package/dist/types/functions/url_utils/index.d.ts +0 -1
  174. package/dist/types/functions/url_utils/uri_utils.d.ts +0 -19
  175. package/dist/types/index.js +0 -1
  176. package/dist/types/src/ChangePassword.js +0 -1
  177. package/dist/types/src/Files.js +0 -1
  178. package/dist/types/src/index.js +0 -5
  179. package/dist/types/src/login.js +0 -1
  180. package/dist/types/src/logout.js +0 -1
  181. package/dist/types/src/utils.js +0 -1
  182. package/dist/utils/imports.js +0 -1
  183. package/dist/utils/index.js +0 -1
  184. package/dist/utils/src/Input.js +0 -2
  185. package/dist/utils/src/config.js +0 -12
  186. package/dist/utils/src/index.js +0 -3
package/dist/cjs/index.js CHANGED
@@ -168,17 +168,6 @@ function isLoggedIn() {
168
168
  const tok = getToken();
169
169
  return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
170
170
  }
171
- function removeToken() {
172
- let is_logged = isLoggedIn();
173
- if (is_logged) {
174
- callStorage('removeItem', "token");
175
- }
176
- is_logged = isLoggedIn();
177
- if (is_logged) {
178
- return false;
179
- }
180
- return true;
181
- }
182
171
  /**
183
172
  * Add a Bearer Authorization header.
184
173
  * A shallow copy of headers is returned so callers can keep chaining.
@@ -195,7 +184,7 @@ function requireToken() {
195
184
  const tok = getToken();
196
185
  if (!tok || isTokenExpired(tok)) {
197
186
  console.warn("→ No token or expired token, redirecting to login…");
198
- removeToken();
187
+ localStorage.removeItem("token");
199
188
  window.location.href = '/';
200
189
  throw new Error("Redirecting to login…");
201
190
  }
@@ -213,13 +202,16 @@ function isTokenExpired(token) {
213
202
  }
214
203
  /** Convenience wrapper: return username from the JWT (or null). */
215
204
  function currentUsername() {
216
- const token = getToken();
217
- let uName = null;
218
- if (token) {
219
- const decodedJwt = decodeJwt(token) || {};
220
- uName = (decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.username) || null;
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;
221
214
  }
222
- return uName;
223
215
  }
224
216
  function currentUsernames() {
225
217
  var _a;
@@ -363,37 +355,44 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
363
355
  */
364
356
  function readJsonFile(relativeOrAbsolutePath) {
365
357
  return __awaiter(this, void 0, void 0, function* () {
366
- if (typeof window === 'undefined') {
358
+ // 1) Try Node.js fs
359
+ if (typeof process !== 'undefined' &&
360
+ process.versions != null &&
361
+ process.versions.node) {
367
362
  try {
368
- const { readFile } = yield import('fs/promises');
369
- const { isAbsolute, resolve } = yield import('path');
370
- const filePath = isAbsolute(relativeOrAbsolutePath)
363
+ const fs = yield import('fs');
364
+ const path = yield import('path');
365
+ const filePath = path.isAbsolute(relativeOrAbsolutePath)
371
366
  ? relativeOrAbsolutePath
372
- : resolve((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) ? new URL('.', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))).pathname : '', relativeOrAbsolutePath);
373
- const text = yield readFile(filePath, 'utf8');
367
+ : path.resolve(process.cwd(), relativeOrAbsolutePath);
368
+ const text = yield fs.promises.readFile(filePath, 'utf8');
374
369
  return JSON.parse(text);
375
370
  }
376
371
  catch (_a) {
377
- return null;
372
+ // swallow and fall back to browser
378
373
  }
379
374
  }
380
- // Browser fallback
375
+ // 2) Try browser fetch
381
376
  const fetchFn = safeGlobalProp('fetch');
382
- if (typeof fetchFn !== 'function')
377
+ if (typeof fetchFn !== 'function') {
383
378
  return null;
379
+ }
380
+ // Resolve URL against document.baseURI if possible
384
381
  let url = relativeOrAbsolutePath;
385
382
  const baseURI = safeGlobalProp('document', 'baseURI');
386
383
  if (baseURI) {
387
384
  try {
388
385
  url = new URL(relativeOrAbsolutePath, baseURI).href;
389
386
  }
390
- catch (_b) { }
387
+ catch (_b) {
388
+ // keep url as-is
389
+ }
391
390
  }
392
391
  try {
393
392
  const res = yield fetchFn(url);
394
393
  if (!res.ok)
395
394
  return null;
396
- return yield res.json();
395
+ return (yield res.json());
397
396
  }
398
397
  catch (_c) {
399
398
  return null;
@@ -436,7 +435,6 @@ function getResult(obj) {
436
435
  }
437
436
  return current;
438
437
  }
439
- const get_result = getResult;
440
438
  // Determines HTTP method, defaults to GET or POST based on body
441
439
  function getMethod(method = null, body = null) {
442
440
  const validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'PULL'];
@@ -525,7 +523,7 @@ function checkResponse(res) {
525
523
  }
526
524
 
527
525
  function fetchIt(endpoint_1) {
528
- return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnResult = true) {
526
+ return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnReult = true) {
529
527
  method = (method || "GET").toUpperCase();
530
528
  // 2) choose the URL
531
529
  let url = endpoint;
@@ -541,20 +539,18 @@ function fetchIt(endpoint_1) {
541
539
  ? JSON.stringify(body)
542
540
  : undefined,
543
541
  };
544
- let res = yield fetch(url, opts);
542
+ console.debug("➡️ secureFetchIt →", url, opts);
543
+ const res = yield fetch(url, opts);
545
544
  if (!res.ok) {
546
545
  const err = yield res.text();
547
546
  throw new Error(`HTTP ${res.status}: ${err}`);
548
547
  }
549
548
  if (blob)
550
549
  return res.blob();
551
- if (returnResult || returnJson) {
552
- let JsonRes = parseResult(res);
553
- if (returnResult) {
554
- JsonRes = getResult(JsonRes);
555
- }
556
- return JsonRes;
557
- }
550
+ if (returnReult)
551
+ return getResult(res.json());
552
+ if (returnJson)
553
+ return res.json();
558
554
  return res;
559
555
  });
560
556
  }
@@ -1170,6 +1166,135 @@ posix.posix = posix;
1170
1166
 
1171
1167
  var pathBrowserify = posix;
1172
1168
 
1169
+ function getSubstring(obj, maxLength = null, minLength = null) {
1170
+ const objLength = obj.length;
1171
+ const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
1172
+ const effectiveMinLength = minLength !== null && minLength !== void 0 ? minLength : 0;
1173
+ // Ensure bounds are valid
1174
+ const clampedMaxLength = Math.min(Math.max(effectiveMaxLength, 0), objLength);
1175
+ const clampedMinLength = Math.min(Math.max(effectiveMinLength, 0), objLength);
1176
+ // If minLength exceeds maxLength, return empty string or adjust logic as needed
1177
+ if (clampedMinLength >= clampedMaxLength) {
1178
+ return '';
1179
+ }
1180
+ return obj.substring(clampedMinLength, clampedMaxLength);
1181
+ }
1182
+ function truncateString(obj, maxLength = 20) {
1183
+ const objLength = obj.length;
1184
+ if (objLength > maxLength && maxLength) {
1185
+ obj = getSubstring(obj, maxLength) + '...';
1186
+ }
1187
+ return obj;
1188
+ }
1189
+ // string_utils/src/string_utils.ts
1190
+ function stripPrefixes(str, bases = []) {
1191
+ /* NEW: coerce whatever arrives into a string */
1192
+ str = String(str);
1193
+ const prefixes = (Array.isArray(bases) ? bases : [bases])
1194
+ .filter(Boolean)
1195
+ .sort((a, b) => b.length - a.length); // longest first
1196
+ let changed = true;
1197
+ while (changed) {
1198
+ changed = false;
1199
+ for (const prefix of prefixes) {
1200
+ if (str.startsWith(prefix)) {
1201
+ str = str.slice(prefix.length);
1202
+ changed = true;
1203
+ break; // restart from longest prefix
1204
+ }
1205
+ }
1206
+ }
1207
+ return str;
1208
+ }
1209
+ /**
1210
+ * Removes characters from the beginning of the string
1211
+ * if they are found in the list of characters.
1212
+ *
1213
+ * @param str - The input string.
1214
+ * @param listObjects - A string or an array of characters to remove.
1215
+ * @returns The modified string.
1216
+ */
1217
+ function eatInner(str, listObjects) {
1218
+ if (!Array.isArray(listObjects)) {
1219
+ listObjects = [listObjects];
1220
+ }
1221
+ // Ensure str is a string
1222
+ str = String(str);
1223
+ // Remove characters from the beginning while they are in listObjects
1224
+ while (str.length > 0 && listObjects.includes(str[0])) {
1225
+ str = str.slice(1);
1226
+ }
1227
+ return str;
1228
+ }
1229
+ /**
1230
+ * Removes characters from the end of the string
1231
+ * if they are found in the list of characters.
1232
+ *
1233
+ * @param str - The input string.
1234
+ * @param listObjects - A string or an array of characters to remove.
1235
+ * @returns The modified string.
1236
+ */
1237
+ function eatOuter(str, listObjects) {
1238
+ if (!Array.isArray(listObjects)) {
1239
+ listObjects = [listObjects];
1240
+ }
1241
+ // Ensure str is a string
1242
+ str = String(str);
1243
+ // Remove characters from the end while they are in listObjects
1244
+ while (str.length > 0 && listObjects.includes(str[str.length - 1])) {
1245
+ str = str.slice(0, -1);
1246
+ }
1247
+ return str;
1248
+ }
1249
+ /**
1250
+ * Removes characters from both the beginning and the end of the string
1251
+ * if they are found in the list of characters.
1252
+ *
1253
+ * @param str - The input string.
1254
+ * @param listObjects - A string or an array of characters to remove.
1255
+ * @returns The modified string.
1256
+ */
1257
+ function eatAll(str, listObjects) {
1258
+ return eatOuter(eatInner(str, listObjects), listObjects);
1259
+ }
1260
+ function eatEnd(obj, endings = ['/']) {
1261
+ let result = obj;
1262
+ let modified = true;
1263
+ while (modified) {
1264
+ modified = false;
1265
+ for (const ending of endings) {
1266
+ if (result.endsWith(ending)) {
1267
+ result = result.slice(0, -ending.length);
1268
+ modified = true;
1269
+ break;
1270
+ }
1271
+ }
1272
+ }
1273
+ return result;
1274
+ }
1275
+ function tryParse(obj) {
1276
+ try {
1277
+ obj = JSON.stringify(obj);
1278
+ }
1279
+ catch (err) {
1280
+ try {
1281
+ obj = JSON.parse(obj);
1282
+ }
1283
+ catch (err) {
1284
+ }
1285
+ }
1286
+ return obj;
1287
+ }
1288
+ function create_list_string(array_obj) {
1289
+ let string = '';
1290
+ for (const obj in array_obj) {
1291
+ const array_value = array_obj[obj];
1292
+ const parsed_value = tryParse(array_value);
1293
+ string += `${obj} == ${parsed_value}\n`;
1294
+ }
1295
+ return string;
1296
+ }
1297
+
1173
1298
  function ensure_list(obj) {
1174
1299
  const objArray = Array.isArray(obj) ? obj : [obj];
1175
1300
  return objArray;
@@ -1610,159 +1735,6 @@ const confirm_type = confirmType;
1610
1735
  const is_media_type = isMediaType;
1611
1736
  const get_mime_type = getMimeType;
1612
1737
 
1613
- function getSubstring(obj, maxLength = null, minLength = null) {
1614
- const objLength = obj.length;
1615
- const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
1616
- const effectiveMinLength = minLength !== null && minLength !== void 0 ? minLength : 0;
1617
- // Ensure bounds are valid
1618
- const clampedMaxLength = Math.min(Math.max(effectiveMaxLength, 0), objLength);
1619
- const clampedMinLength = Math.min(Math.max(effectiveMinLength, 0), objLength);
1620
- // If minLength exceeds maxLength, return empty string or adjust logic as needed
1621
- if (clampedMinLength >= clampedMaxLength) {
1622
- return '';
1623
- }
1624
- return obj.substring(clampedMinLength, clampedMaxLength);
1625
- }
1626
- function truncateString(obj, maxLength = 20) {
1627
- const objLength = obj.length;
1628
- if (objLength > maxLength && maxLength) {
1629
- obj = getSubstring(obj, maxLength) + '...';
1630
- }
1631
- return obj;
1632
- }
1633
- function capitalize_str(string) {
1634
- string = assureString(string);
1635
- const string_len = string.length;
1636
- let init_char = string.toUpperCase();
1637
- if (string_len > 0) {
1638
- init_char = string[0].toUpperCase();
1639
- }
1640
- let rest_chars = '';
1641
- if (string_len > 1) {
1642
- rest_chars = string.slice(1).toLowerCase();
1643
- }
1644
- const fin_chars = `${init_char}${rest_chars}`;
1645
- return fin_chars;
1646
- }
1647
- function capitalize(string) {
1648
- let nu_string = '';
1649
- string = assureString(string);
1650
- let objs = string.replace('-', '_').split('_');
1651
- for (const obj of objs) {
1652
- let str_obj = capitalize_str(obj);
1653
- nu_string = `${nu_string} ${str_obj}`;
1654
- }
1655
- return eatAll(nu_string, [' ']);
1656
- }
1657
- // string_utils/src/string_utils.ts
1658
- function stripPrefixes(str, bases = []) {
1659
- /* NEW: coerce whatever arrives into a string */
1660
- str = String(str);
1661
- const prefixes = (Array.isArray(bases) ? bases : [bases])
1662
- .filter(Boolean)
1663
- .sort((a, b) => b.length - a.length); // longest first
1664
- let changed = true;
1665
- while (changed) {
1666
- changed = false;
1667
- for (const prefix of prefixes) {
1668
- if (str.startsWith(prefix)) {
1669
- str = str.slice(prefix.length);
1670
- changed = true;
1671
- break; // restart from longest prefix
1672
- }
1673
- }
1674
- }
1675
- return str;
1676
- }
1677
- /**
1678
- * Removes characters from the beginning of the string
1679
- * if they are found in the list of characters.
1680
- *
1681
- * @param str - The input string.
1682
- * @param listObjects - A string or an array of characters to remove.
1683
- * @returns The modified string.
1684
- */
1685
- function eatInner(str, listObjects) {
1686
- if (!Array.isArray(listObjects)) {
1687
- listObjects = [listObjects];
1688
- }
1689
- // Ensure str is a string
1690
- str = String(str);
1691
- // Remove characters from the beginning while they are in listObjects
1692
- while (str.length > 0 && listObjects.includes(str[0])) {
1693
- str = str.slice(1);
1694
- }
1695
- return str;
1696
- }
1697
- /**
1698
- * Removes characters from the end of the string
1699
- * if they are found in the list of characters.
1700
- *
1701
- * @param str - The input string.
1702
- * @param listObjects - A string or an array of characters to remove.
1703
- * @returns The modified string.
1704
- */
1705
- function eatOuter(str, listObjects) {
1706
- if (!Array.isArray(listObjects)) {
1707
- listObjects = [listObjects];
1708
- }
1709
- // Ensure str is a string
1710
- str = String(str);
1711
- // Remove characters from the end while they are in listObjects
1712
- while (str.length > 0 && listObjects.includes(str[str.length - 1])) {
1713
- str = str.slice(0, -1);
1714
- }
1715
- return str;
1716
- }
1717
- /**
1718
- * Removes characters from both the beginning and the end of the string
1719
- * if they are found in the list of characters.
1720
- *
1721
- * @param str - The input string.
1722
- * @param listObjects - A string or an array of characters to remove.
1723
- * @returns The modified string.
1724
- */
1725
- function eatAll(str, listObjects) {
1726
- return eatOuter(eatInner(str, listObjects), listObjects);
1727
- }
1728
- function eatEnd(obj, endings = ['/']) {
1729
- let result = obj;
1730
- let modified = true;
1731
- while (modified) {
1732
- modified = false;
1733
- for (const ending of endings) {
1734
- if (result.endsWith(ending)) {
1735
- result = result.slice(0, -ending.length);
1736
- modified = true;
1737
- break;
1738
- }
1739
- }
1740
- }
1741
- return result;
1742
- }
1743
- function tryParse(obj) {
1744
- try {
1745
- obj = JSON.stringify(obj);
1746
- }
1747
- catch (err) {
1748
- try {
1749
- obj = JSON.parse(obj);
1750
- }
1751
- catch (err) {
1752
- }
1753
- }
1754
- return obj;
1755
- }
1756
- function create_list_string(array_obj) {
1757
- let string = '';
1758
- for (const obj in array_obj) {
1759
- const array_value = array_obj[obj];
1760
- const parsed_value = tryParse(array_value);
1761
- string += `${obj} == ${parsed_value}\n`;
1762
- }
1763
- return string;
1764
- }
1765
-
1766
1738
  /**
1767
1739
  * In the browser we already have a WHATWG URL constructor on window.
1768
1740
  * Here we re-export it as “url” so other modules can import it.
@@ -1783,12 +1755,9 @@ function fileURLToPath(fileUrl) {
1783
1755
  }
1784
1756
  }
1785
1757
  function getAbsolutePath() {
1786
- if (typeof window !== 'undefined')
1787
- return '';
1788
1758
  return fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
1789
1759
  }
1790
1760
 
1791
- // path_utils.browser.ts
1792
1761
  function get_dirname(filePath) {
1793
1762
  if (!filePath)
1794
1763
  return '';
@@ -1844,23 +1813,6 @@ function make_path(...paths) {
1844
1813
  }
1845
1814
  return real_path;
1846
1815
  }
1847
- function makePath(...paths) {
1848
- var _a;
1849
- const pathArray = ensure_list(paths);
1850
- let real_path = '';
1851
- for (let i = 0; i < pathArray.length; i++) {
1852
- let seg = String((_a = pathArray[i]) !== null && _a !== void 0 ? _a : '');
1853
- if (i === 0) {
1854
- real_path = seg;
1855
- }
1856
- else {
1857
- seg = eatInner(seg, ['/']);
1858
- real_path = eatOuter(real_path, ['/']);
1859
- real_path = `${real_path}/${seg}`;
1860
- }
1861
- }
1862
- return real_path || '';
1863
- }
1864
1816
  function sanitizeFilename(filename) {
1865
1817
  return filename
1866
1818
  .toLowerCase()
@@ -1870,13 +1822,6 @@ function sanitizeFilename(filename) {
1870
1822
  .replace(/-+/g, '-') // Collapse multiple hyphens into one
1871
1823
  .replace(/^-|-$/, ''); // Remove leading/trailing hyphens
1872
1824
  }
1873
- function get_relative_path(directory, fullPath) {
1874
- return pathBrowserify.relative(directory, fullPath);
1875
- }
1876
- // Safer resolver that strips .. at the front only, but prefer server-side checks.
1877
- function get_safe_path(p) {
1878
- return pathBrowserify.normalize(p).replace(/^(\.\.[/\\])+/, '');
1879
- }
1880
1825
  function make_sanitized_path(...paths) {
1881
1826
  let real_path = '';
1882
1827
  for (let i = 0; i < paths.length; i++) {
@@ -1890,13 +1835,13 @@ function make_sanitized_path(...paths) {
1890
1835
  }
1891
1836
  return real_path || '';
1892
1837
  }
1893
- /** FIXED: your regexes were strings. This correctly joins without duplicate slashes. */
1894
1838
  function normalizeUrl(base, p) {
1895
1839
  if (!p)
1896
- return base.replace(/\/+$/g, '');
1897
- const cleanBase = base.replace(/\/+$/g, '');
1898
- const cleanPath = p.replace(/^\/+/g, '');
1899
- return `${cleanBase}/${cleanPath}`.replace(/([^:])\/{2,}/g, '$1/'); // keep protocol //
1840
+ return base;
1841
+ const cleanBase = base.replace(/\/+$/, ''); // regex literal
1842
+ const cleanPath = p.replace(/^\/+/, '');
1843
+ // collapse multiple “//” into one, but keep the “://” after protocol
1844
+ return `${cleanBase}/${cleanPath}`.replace(/([^:])\/{2,}/g, '$1/');
1900
1845
  }
1901
1846
 
1902
1847
  /**
@@ -1997,7 +1942,32 @@ function alertit(obj = null) {
1997
1942
  }
1998
1943
  alert(msg);
1999
1944
  }
2000
- const alertIt = alertit;
1945
+
1946
+ // take N args and coerce them all to numbers
1947
+ function safeNums(...args) {
1948
+ return args.map(ensure_number);
1949
+ }
1950
+ // divide the first value by each of the following
1951
+ function safeDivide(...args) {
1952
+ const [head, ...rest] = safeNums(...args);
1953
+ // if we don’t have a head or any divisor is zero, bail
1954
+ if (head === 0 || rest.some((d) => d === 0))
1955
+ return 0;
1956
+ return rest.reduce((acc, d) => acc / d, head);
1957
+ }
1958
+ // multiply all the values together
1959
+ function safeMultiply(...args) {
1960
+ const nums = safeNums(...args);
1961
+ // if any number is zero, result is zero
1962
+ if (nums.includes(0))
1963
+ return 0;
1964
+ return nums.reduce((acc, n) => acc * n, 1);
1965
+ }
1966
+ // round a value to two decimals by percent
1967
+ function roundPercentage(x) {
1968
+ const pct = safeMultiply(ensure_number(x), 100);
1969
+ return safeDivide(Math.round(pct), 100);
1970
+ }
2001
1971
 
2002
1972
  function Button(_a) {
2003
1973
  var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
@@ -2035,17 +2005,74 @@ function Spinner() {
2035
2005
  }
2036
2006
 
2037
2007
  // src/functions/config_utils/src/config_utils.ts
2038
- /**
2039
- * Attempt to load config.json if present, otherwise return empty object.
2040
- */
2041
- function getConfigJson() {
2042
- return __awaiter(this, void 0, void 0, function* () {
2008
+ let _cachedConfig = null;
2009
+ function loadConfig() {
2010
+ return __awaiter(this, arguments, void 0, function* (filePath = null) {
2011
+ var _a;
2012
+ if (_cachedConfig) {
2013
+ return _cachedConfig;
2014
+ }
2015
+ // 1) figure out where config.json lives
2016
+ let configUrl;
2017
+ if (filePath) {
2018
+ configUrl = filePath;
2019
+ }
2020
+ else if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) }) !== 'undefined' && typeof (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) === 'string') {
2021
+ // ES module: resolve relative to this file
2022
+ try {
2023
+ configUrl = new URL('./config.json', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))).href;
2024
+ }
2025
+ catch (_b) {
2026
+ configUrl = 'config.json';
2027
+ }
2028
+ }
2029
+ else {
2030
+ // browser fallback
2031
+ const baseURI = safeGlobalProp('document', 'baseURI');
2032
+ try {
2033
+ configUrl =
2034
+ typeof baseURI === 'string'
2035
+ ? new URL('config.json', baseURI).href
2036
+ : 'config.json';
2037
+ }
2038
+ catch (_c) {
2039
+ configUrl = 'config.json';
2040
+ }
2041
+ }
2042
+ // 2) if we have a fetch, try HTTP(S)
2043
+ const fetchFn = safeGlobalProp('fetch');
2044
+ if (typeof fetchFn === 'function') {
2045
+ try {
2046
+ const res = yield fetchFn(configUrl);
2047
+ if (res.ok) {
2048
+ const json = yield res.json();
2049
+ // cache & return
2050
+ _cachedConfig = (_a = json) !== null && _a !== void 0 ? _a : {};
2051
+ return _cachedConfig;
2052
+ }
2053
+ }
2054
+ catch (_d) {
2055
+ /* swallow */
2056
+ }
2057
+ }
2058
+ // 3) Node fallback: try reading from disk (requires your readJsonFile util)
2043
2059
  try {
2044
- return (yield readJsonFile('config.json')) || {};
2060
+ const disk = yield readJsonFile(configUrl);
2061
+ _cachedConfig = disk !== null && disk !== void 0 ? disk : {};
2062
+ return _cachedConfig;
2045
2063
  }
2046
- catch (_a) {
2047
- return {};
2064
+ catch (_e) {
2065
+ /* swallow */
2048
2066
  }
2067
+ // 4) if all else fails, return an empty config
2068
+ _cachedConfig = {};
2069
+ return _cachedConfig;
2070
+ });
2071
+ }
2072
+ function getConfig(key) {
2073
+ return __awaiter(this, void 0, void 0, function* () {
2074
+ const cfg = yield loadConfig();
2075
+ return key != null ? cfg[key] : cfg;
2049
2076
  });
2050
2077
  }
2051
2078
 
@@ -2083,102 +2110,6 @@ function get_keyword_string(keywords) {
2083
2110
  return allString;
2084
2111
  }
2085
2112
 
2086
- // take N args and coerce them all to numbers
2087
- function safeNums(...args) {
2088
- return args.map(ensure_number);
2089
- }
2090
- // divide the first value by each of the following
2091
- function safeDivide(...args) {
2092
- const [head, ...rest] = safeNums(...args);
2093
- // if we don’t have a head or any divisor is zero, bail
2094
- if (head === 0 || rest.some((d) => d === 0))
2095
- return 0;
2096
- return rest.reduce((acc, d) => acc / d, head);
2097
- }
2098
- // multiply all the values together
2099
- function safeMultiply(...args) {
2100
- const nums = safeNums(...args);
2101
- // if any number is zero, result is zero
2102
- if (nums.includes(0))
2103
- return 0;
2104
- return nums.reduce((acc, n) => acc * n, 1);
2105
- }
2106
- // round a value to two decimals by percent
2107
- function roundPercentage(x) {
2108
- const pct = safeMultiply(ensure_number(x), 100);
2109
- return safeDivide(Math.round(pct), 100);
2110
- }
2111
-
2112
- // urlTools.ts
2113
- // Minimal, safe encoders/decoders + helpers to build/parse URLs
2114
- /** Encode a single query value/key safely */
2115
- const encode = (v) => encodeURIComponent(String(v !== null && v !== void 0 ? v : ""));
2116
- /** Decode a single query value/key safely (never throws) */
2117
- const decodeSafe = (v) => {
2118
- if (v == null)
2119
- return "";
2120
- try {
2121
- return decodeURIComponent(v);
2122
- }
2123
- catch (_a) {
2124
- // handles bad % sequences or already-decoded strings
2125
- return v;
2126
- }
2127
- };
2128
- /** Decode strings that might be double-encoded (up to 2 passes) */
2129
- const decodeMaybeDouble = (v) => {
2130
- const once = decodeSafe(v);
2131
- const twice = decodeSafe(once);
2132
- return twice.length < once.length ? twice : once;
2133
- };
2134
- /** Convert + to spaces (legacy www-form behavior) then decode */
2135
- const decodeFormComponent = (v) => decodeSafe(v.replace(/\+/g, " "));
2136
- /** Build a URL with query params (skips null/undefined) */
2137
- const buildUrl = (base, params) => {
2138
- const u = new URL(base, typeof window !== "undefined" ? window.location.origin : "http://localhost");
2139
- if (params) {
2140
- for (const [k, val] of Object.entries(params)) {
2141
- if (val === null || val === undefined)
2142
- continue;
2143
- // arrays -> multiple entries
2144
- if (Array.isArray(val)) {
2145
- val.forEach(v => u.searchParams.append(k, String(v)));
2146
- }
2147
- else {
2148
- u.searchParams.set(k, String(val));
2149
- }
2150
- }
2151
- }
2152
- return u.toString();
2153
- };
2154
- /** Parse a query string into an object (first value wins; arrays if repeat=true) */
2155
- const parseQuery = (qs, opts) => {
2156
- var _a;
2157
- const { repeat = false, form = false } = opts || {};
2158
- const out = {};
2159
- const s = qs.startsWith("?") ? qs.slice(1) : qs;
2160
- if (!s)
2161
- return out;
2162
- for (const part of s.split("&")) {
2163
- if (!part)
2164
- continue;
2165
- const [kRaw, vRaw = ""] = part.split("=");
2166
- const K = form ? decodeFormComponent(kRaw) : decodeSafe(kRaw);
2167
- const V = form ? decodeFormComponent(vRaw) : decodeSafe(vRaw);
2168
- if (repeat) {
2169
- ((_a = out[K]) !== null && _a !== void 0 ? _a : (out[K] = [])).push(V);
2170
- }
2171
- else {
2172
- out[K] = V;
2173
- }
2174
- }
2175
- return out;
2176
- };
2177
- /** Quick helper: percent-encode whole strings for placement in URLs */
2178
- const encodeTextForUrl = (text) => encode(text);
2179
- /** Quick helper: decode long blobs coming from share-intents/UTMs */
2180
- const decodeShareBlob = (blob) => decodeMaybeDouble(blob).replace(/\r\n/g, "\n");
2181
-
2182
2113
  Object.defineProperty(exports, "useCallback", {
2183
2114
  enumerable: true,
2184
2115
  get: function () { return react.useCallback; }
@@ -2208,7 +2139,6 @@ exports.PROD_PREFIX = PROD_PREFIX;
2208
2139
  exports.PROTOCOL = PROTOCOL;
2209
2140
  exports.SUB_DIR = SUB_DIR;
2210
2141
  exports.Spinner = Spinner;
2211
- exports.alertIt = alertIt;
2212
2142
  exports.alertit = alertit;
2213
2143
  exports.assureArray = assureArray;
2214
2144
  exports.assureList = assureList;
@@ -2218,11 +2148,8 @@ exports.assure_array = assure_array;
2218
2148
  exports.assure_list = assure_list;
2219
2149
  exports.assure_number = assure_number;
2220
2150
  exports.assure_string = assure_string;
2221
- exports.buildUrl = buildUrl;
2222
2151
  exports.callStorage = callStorage;
2223
2152
  exports.callWindowMethod = callWindowMethod;
2224
- exports.capitalize = capitalize;
2225
- exports.capitalize_str = capitalize_str;
2226
2153
  exports.checkResponse = checkResponse;
2227
2154
  exports.cleanArray = cleanArray;
2228
2155
  exports.cleanText = cleanText;
@@ -2231,17 +2158,11 @@ exports.confirm_type = confirm_type;
2231
2158
  exports.create_list_string = create_list_string;
2232
2159
  exports.currentUsername = currentUsername;
2233
2160
  exports.currentUsernames = currentUsernames;
2234
- exports.decodeFormComponent = decodeFormComponent;
2235
2161
  exports.decodeJwt = decodeJwt;
2236
- exports.decodeMaybeDouble = decodeMaybeDouble;
2237
- exports.decodeSafe = decodeSafe;
2238
- exports.decodeShareBlob = decodeShareBlob;
2239
2162
  exports.eatAll = eatAll;
2240
2163
  exports.eatEnd = eatEnd;
2241
2164
  exports.eatInner = eatInner;
2242
2165
  exports.eatOuter = eatOuter;
2243
- exports.encode = encode;
2244
- exports.encodeTextForUrl = encodeTextForUrl;
2245
2166
  exports.ensureArray = ensureArray;
2246
2167
  exports.ensureList = ensureList;
2247
2168
  exports.ensureNumber = ensureNumber;
@@ -2277,8 +2198,8 @@ exports.getBody = getBody;
2277
2198
  exports.getChar = getChar;
2278
2199
  exports.getCleanArray = getCleanArray;
2279
2200
  exports.getComponentsUtilsDirectory = getComponentsUtilsDirectory;
2201
+ exports.getConfig = getConfig;
2280
2202
  exports.getConfigContent = getConfigContent;
2281
- exports.getConfigJson = getConfigJson;
2282
2203
  exports.getConfigVar = getConfigVar;
2283
2204
  exports.getDbConfigsPath = getDbConfigsPath;
2284
2205
  exports.getDistDir = getDistDir;
@@ -2321,9 +2242,6 @@ exports.get_keyword_string = get_keyword_string;
2321
2242
  exports.get_media_exts = get_media_exts;
2322
2243
  exports.get_media_map = get_media_map;
2323
2244
  exports.get_mime_type = get_mime_type;
2324
- exports.get_relative_path = get_relative_path;
2325
- exports.get_result = get_result;
2326
- exports.get_safe_path = get_safe_path;
2327
2245
  exports.get_splitext = get_splitext;
2328
2246
  exports.get_window = get_window;
2329
2247
  exports.get_window_location = get_window_location;
@@ -2336,16 +2254,14 @@ exports.isStrInString = isStrInString;
2336
2254
  exports.isTokenExpired = isTokenExpired;
2337
2255
  exports.isType = isType;
2338
2256
  exports.is_media_type = is_media_type;
2339
- exports.makePath = makePath;
2257
+ exports.loadConfig = loadConfig;
2340
2258
  exports.make_path = make_path;
2341
2259
  exports.make_sanitized_path = make_sanitized_path;
2342
2260
  exports.normalizeUrl = normalizeUrl;
2343
- exports.parseQuery = parseQuery;
2344
2261
  exports.parseResult = parseResult;
2345
2262
  exports.path_to_url = path_to_url;
2346
2263
  exports.processKeywords = processKeywords;
2347
2264
  exports.readJsonFile = readJsonFile;
2348
- exports.removeToken = removeToken;
2349
2265
  exports.requireToken = requireToken;
2350
2266
  exports.roundPercentage = roundPercentage;
2351
2267
  exports.safeDivide = safeDivide;