@putkoff/abstract-utilities 1.0.5 → 1.0.19

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 (90) hide show
  1. package/dist/cjs/index.js +45 -27
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.js +134 -114
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/index.d.ts +0 -0
  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 -0
  10. package/dist/types/functions/config_utils/imports.d.ts +1 -1
  11. package/dist/types/functions/config_utils/index.d.ts +0 -0
  12. package/dist/types/functions/config_utils/src/config_utils.d.ts +0 -0
  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 +0 -0
  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 +0 -0
  27. package/dist/types/functions/index.d.ts +0 -0
  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 -0
  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 -0
  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 -0
  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 +11 -3
package/dist/esm/index.js CHANGED
@@ -1,8 +1,4 @@
1
1
  export { useCallback, useEffect, useRef, useState } from 'react';
2
- import path$1 from 'path';
3
- import * as fs from 'node:fs';
4
- import * as fsp from 'node:fs/promises';
5
- import * as path from 'node:path';
6
2
  import { jsx, jsxs } from 'react/jsx-runtime';
7
3
 
8
4
  function getSafeDocument() {
@@ -324,6 +320,25 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
324
320
  };
325
321
 
326
322
  // src/functions/read_utils/src/read_utils.ts
323
+ let fs = null;
324
+ let path$1 = null;
325
+ function getFsModules() {
326
+ return __awaiter(this, void 0, void 0, function* () {
327
+ var _a;
328
+ if (!fs && !path$1 && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
329
+ try {
330
+ // prevent bundlers from resolving these at build time
331
+ fs = (new Function("return require('fs')"))();
332
+ path$1 = (new Function("return require('path')"))();
333
+ }
334
+ catch (_b) {
335
+ fs = null;
336
+ path$1 = null;
337
+ }
338
+ }
339
+ return { fs, path: path$1 };
340
+ });
341
+ }
327
342
  /**
328
343
  * Reads a JSON file, either via Node’s fs (if available)
329
344
  * or via window.fetch in the browser. Never throws — returns
@@ -331,37 +346,36 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
331
346
  */
332
347
  function readJsonFile(relativeOrAbsolutePath) {
333
348
  return __awaiter(this, void 0, void 0, function* () {
334
- // 1) Try Node.js fs
335
- if (typeof process !== 'undefined' &&
336
- process.versions != null &&
337
- process.versions.node) {
349
+ var _a;
350
+ // 1) Try Node.js fs (only at runtime, not bundled)
351
+ if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
338
352
  try {
339
- const fs = yield import('fs');
340
- const path = yield import('path');
341
- const filePath = path.isAbsolute(relativeOrAbsolutePath)
342
- ? relativeOrAbsolutePath
343
- : path.resolve(process.cwd(), relativeOrAbsolutePath);
344
- const text = yield fs.promises.readFile(filePath, 'utf8');
345
- return JSON.parse(text);
353
+ const { fs, path } = yield getFsModules();
354
+ if (fs && path) {
355
+ const filePath = path.isAbsolute(relativeOrAbsolutePath)
356
+ ? relativeOrAbsolutePath
357
+ : path.resolve(process.cwd(), relativeOrAbsolutePath);
358
+ const text = fs.readFileSync(filePath, "utf8");
359
+ return JSON.parse(text);
360
+ }
346
361
  }
347
- catch (_a) {
348
- // swallow and fall back to browser
362
+ catch (_b) {
363
+ // swallow and fall back
349
364
  }
350
365
  }
351
366
  // 2) Try browser fetch
352
- const fetchFn = safeGlobalProp('fetch');
353
- if (typeof fetchFn !== 'function') {
367
+ const fetchFn = safeGlobalProp("fetch");
368
+ if (typeof fetchFn !== "function") {
354
369
  return null;
355
370
  }
356
- // Resolve URL against document.baseURI if possible
357
371
  let url = relativeOrAbsolutePath;
358
- const baseURI = safeGlobalProp('document', 'baseURI');
372
+ const baseURI = safeGlobalProp("document", "baseURI");
359
373
  if (baseURI) {
360
374
  try {
361
375
  url = new URL(relativeOrAbsolutePath, baseURI).href;
362
376
  }
363
- catch (_b) {
364
- // keep url as-is
377
+ catch (_c) {
378
+ /* keep url as-is */
365
379
  }
366
380
  }
367
381
  try {
@@ -370,7 +384,7 @@ function readJsonFile(relativeOrAbsolutePath) {
370
384
  return null;
371
385
  return (yield res.json());
372
386
  }
373
- catch (_c) {
387
+ catch (_d) {
374
388
  return null;
375
389
  }
376
390
  });
@@ -557,87 +571,8 @@ function fetchIndexHtmlContainer(filename_1) {
557
571
  });
558
572
  }
559
573
 
560
- function urlJoin(...parts) {
561
- var _a;
562
- const s = (parts.length === 1 && Array.isArray(parts[0]) ? parts[0] : parts);
563
- let r = "";
564
- for (let i = 0; i < s.length; i++) {
565
- let d = ((_a = s[i]) !== null && _a !== void 0 ? _a : "").toString();
566
- if (!d)
567
- continue;
568
- if (i === 0)
569
- r = d;
570
- else {
571
- d = d.replace(/^\/+/, "");
572
- r = r.replace(/\/+$/, "");
573
- r = `${r}/${d}`;
574
- }
575
- }
576
- return r;
577
- }
578
- /**
579
- * Returns a full URL.
580
- * If partial_url is already absolute (starts with http), it is returned as is.
581
- * Otherwise, it is combined with the base URL.
582
- */
583
- function get_full_url(partial_url, domain = null) {
584
- if (typeof partial_url !== 'string') {
585
- throw new Error('partial_url must be a string');
586
- }
587
- // If it already starts with http, assume it is absolute.
588
- if (partial_url.startsWith('http')) {
589
- return partial_url;
590
- }
591
- return urlJoin(domain, partial_url);
592
- }
593
- /**
594
- * Returns a full file system path.
595
- * If partial_path is already absolute, it is returned as is.
596
- * Otherwise, it is joined with the base directory.
597
- */
598
- function get_full_path(partial_path, parent_dir = null) {
599
- if (typeof partial_path !== 'string') {
600
- throw new Error('partial_path must be a string');
601
- }
602
- if (path$1.isAbsolute(partial_path)) {
603
- return partial_path;
604
- }
605
- return urlJoin(parent_dir, partial_path);
606
- }
607
- /**
608
- * Converts a local file system path into its corresponding URL.
609
- * It checks against the known directories in all_paths and replaces the matching base.
610
- */
611
- function path_to_url(filePath, all_paths) {
612
- if (typeof filePath !== 'string') {
613
- throw new Error('filePath must be a string');
614
- }
615
- for (const key in all_paths) {
616
- const mapping = all_paths[key];
617
- const normalizedBase = path$1.normalize(mapping.path);
618
- if (filePath.startsWith(normalizedBase)) {
619
- const relativePath = filePath.substring(normalizedBase.length);
620
- return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
621
- }
622
- }
623
- return null;
624
- }
625
- /**
626
- * Converts a URL into its corresponding local file system path.
627
- * It checks against the known URL prefixes in all_paths and replaces the matching base.
628
- */
629
- function url_to_path(urlStr, all_paths) {
630
- if (typeof urlStr !== 'string') {
631
- throw new Error('urlStr must be a string');
632
- }
633
- for (const key in all_paths) {
634
- const mapping = all_paths[key];
635
- if (urlStr.startsWith(mapping.url)) {
636
- const relativeUrl = urlStr.substring(mapping.url.length);
637
- return urlJoin(mapping.path, relativeUrl);
638
- }
639
- }
640
- return null;
574
+ function getDefaultExportFromCjs (x) {
575
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
641
576
  }
642
577
 
643
578
  function assertPath(path) {
@@ -1142,6 +1077,91 @@ posix.posix = posix;
1142
1077
 
1143
1078
  var pathBrowserify = posix;
1144
1079
 
1080
+ var path = /*@__PURE__*/getDefaultExportFromCjs(pathBrowserify);
1081
+
1082
+ function urlJoin(...parts) {
1083
+ var _a;
1084
+ const s = (parts.length === 1 && Array.isArray(parts[0]) ? parts[0] : parts);
1085
+ let r = "";
1086
+ for (let i = 0; i < s.length; i++) {
1087
+ let d = ((_a = s[i]) !== null && _a !== void 0 ? _a : "").toString();
1088
+ if (!d)
1089
+ continue;
1090
+ if (i === 0)
1091
+ r = d;
1092
+ else {
1093
+ d = d.replace(/^\/+/, "");
1094
+ r = r.replace(/\/+$/, "");
1095
+ r = `${r}/${d}`;
1096
+ }
1097
+ }
1098
+ return r;
1099
+ }
1100
+ /**
1101
+ * Returns a full URL.
1102
+ * If partial_url is already absolute (starts with http), it is returned as is.
1103
+ * Otherwise, it is combined with the base URL.
1104
+ */
1105
+ function get_full_url(partial_url, domain = null) {
1106
+ if (typeof partial_url !== 'string') {
1107
+ throw new Error('partial_url must be a string');
1108
+ }
1109
+ // If it already starts with http, assume it is absolute.
1110
+ if (partial_url.startsWith('http')) {
1111
+ return partial_url;
1112
+ }
1113
+ return urlJoin(domain, partial_url);
1114
+ }
1115
+ /**
1116
+ * Returns a full file system path.
1117
+ * If partial_path is already absolute, it is returned as is.
1118
+ * Otherwise, it is joined with the base directory.
1119
+ */
1120
+ function get_full_path(partial_path, parent_dir = null) {
1121
+ if (typeof partial_path !== 'string') {
1122
+ throw new Error('partial_path must be a string');
1123
+ }
1124
+ if (path.isAbsolute(partial_path)) {
1125
+ return partial_path;
1126
+ }
1127
+ return urlJoin(parent_dir, partial_path);
1128
+ }
1129
+ /**
1130
+ * Converts a local file system path into its corresponding URL.
1131
+ * It checks against the known directories in all_paths and replaces the matching base.
1132
+ */
1133
+ function path_to_url(filePath, all_paths) {
1134
+ if (typeof filePath !== 'string') {
1135
+ throw new Error('filePath must be a string');
1136
+ }
1137
+ for (const key in all_paths) {
1138
+ const mapping = all_paths[key];
1139
+ const normalizedBase = path.normalize(mapping.path);
1140
+ if (filePath.startsWith(normalizedBase)) {
1141
+ const relativePath = filePath.substring(normalizedBase.length);
1142
+ return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
1143
+ }
1144
+ }
1145
+ return null;
1146
+ }
1147
+ /**
1148
+ * Converts a URL into its corresponding local file system path.
1149
+ * It checks against the known URL prefixes in all_paths and replaces the matching base.
1150
+ */
1151
+ function url_to_path(urlStr, all_paths) {
1152
+ if (typeof urlStr !== 'string') {
1153
+ throw new Error('urlStr must be a string');
1154
+ }
1155
+ for (const key in all_paths) {
1156
+ const mapping = all_paths[key];
1157
+ if (urlStr.startsWith(mapping.url)) {
1158
+ const relativeUrl = urlStr.substring(mapping.url.length);
1159
+ return urlJoin(mapping.path, relativeUrl);
1160
+ }
1161
+ }
1162
+ return null;
1163
+ }
1164
+
1145
1165
  function getSubstring(obj, maxLength = null, minLength = null) {
1146
1166
  const objLength = obj.length;
1147
1167
  const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
@@ -1561,7 +1581,7 @@ function normalizeCategories(categories, opts) {
1561
1581
  }
1562
1582
  function extOf(input) {
1563
1583
  // Behaves like pathlib.Path(...).suffix.lower(): last extension only; lowercased.
1564
- let ext = path.extname(input || "");
1584
+ let ext = pathBrowserify.extname(input || "");
1565
1585
  if (!ext && input && input.startsWith(".")) {
1566
1586
  // user passed ".jpg" directly
1567
1587
  ext = input;
@@ -1638,7 +1658,7 @@ function getAllFileTypesSync(directory, categories, opts) {
1638
1658
  const base = directory;
1639
1659
  let stat;
1640
1660
  try {
1641
- stat = fs.statSync(base);
1661
+ stat = undefined(base);
1642
1662
  }
1643
1663
  catch (_a) {
1644
1664
  return [];
@@ -1649,14 +1669,14 @@ function getAllFileTypesSync(directory, categories, opts) {
1649
1669
  const wanted = unionExts(cats);
1650
1670
  const results = [];
1651
1671
  function walkSync(dir) {
1652
- const entries = fs.readdirSync(dir, { withFileTypes: true });
1672
+ const entries = undefined(dir, { withFileTypes: true });
1653
1673
  for (const ent of entries) {
1654
- const full = path.join(dir, ent.name);
1674
+ const full = pathBrowserify.join(dir, ent.name);
1655
1675
  if (ent.isDirectory()) {
1656
1676
  walkSync(full);
1657
1677
  }
1658
1678
  else if (ent.isFile()) {
1659
- const ext = path.extname(ent.name).toLowerCase();
1679
+ const ext = pathBrowserify.extname(ent.name).toLowerCase();
1660
1680
  if (wanted.has(ext))
1661
1681
  results.push(full);
1662
1682
  }
@@ -1673,7 +1693,7 @@ function getAllFileTypes(directory, categories, opts) {
1673
1693
  return __awaiter(this, void 0, void 0, function* () {
1674
1694
  let stat;
1675
1695
  try {
1676
- stat = yield fsp.stat(directory);
1696
+ stat = yield undefined(directory);
1677
1697
  }
1678
1698
  catch (_a) {
1679
1699
  return [];
@@ -1685,14 +1705,14 @@ function getAllFileTypes(directory, categories, opts) {
1685
1705
  const results = [];
1686
1706
  function walkAsync(dir) {
1687
1707
  return __awaiter(this, void 0, void 0, function* () {
1688
- const entries = yield fsp.readdir(dir, { withFileTypes: true });
1708
+ const entries = yield undefined(dir, { withFileTypes: true });
1689
1709
  for (const ent of entries) {
1690
- const full = path.join(dir, ent.name);
1710
+ const full = pathBrowserify.join(dir, ent.name);
1691
1711
  if (ent.isDirectory()) {
1692
1712
  yield walkAsync(full);
1693
1713
  }
1694
1714
  else if (ent.isFile()) {
1695
- const ext = path.extname(ent.name).toLowerCase();
1715
+ const ext = pathBrowserify.extname(ent.name).toLowerCase();
1696
1716
  if (wanted.has(ext))
1697
1717
  results.push(full);
1698
1718
  }