@putkoff/abstract-utilities 1.0.102 → 1.0.113

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 (188) hide show
  1. package/dist/cjs/client.js.map +1 -1
  2. package/dist/cjs/print_utils-DzyRoj6m.js.map +1 -1
  3. package/dist/cjs/safe_storage-CJgWghnh.js.map +1 -1
  4. package/dist/esm/client.js.map +1 -1
  5. package/dist/esm/print_utils-qqcMhSul.js.map +1 -1
  6. package/dist/esm/safe_storage-CMuv35Vo.js.map +1 -1
  7. package/dist/types/client/auth/index.d.ts +1 -1
  8. package/dist/types/client/auth/index.js +3 -0
  9. package/dist/types/client/auth/src/index.d.ts +1 -1
  10. package/dist/types/client/auth/src/index.js +3 -0
  11. package/dist/types/client/auth/src/token_client.js +73 -0
  12. package/dist/types/client/fetch/src/fetch_auth.d.ts +1 -1
  13. package/dist/types/client/fetch/src/fetch_auth.js +26 -0
  14. package/dist/types/client/fetch/src/index.d.ts +1 -1
  15. package/dist/types/client/fetch/src/index.js +2 -0
  16. package/dist/types/client/index.d.ts +2 -2
  17. package/dist/types/client/index.js +4 -0
  18. package/dist/types/client/ui_utils/index.d.ts +1 -1
  19. package/dist/types/client/ui_utils/index.js +2 -0
  20. package/dist/types/client/ui_utils/src/button.js +34 -0
  21. package/dist/types/client/ui_utils/src/checkbox.js +18 -0
  22. package/dist/types/client/ui_utils/src/index.d.ts +4 -4
  23. package/dist/types/client/ui_utils/src/index.js +4 -0
  24. package/dist/types/client/ui_utils/src/input.js +18 -0
  25. package/dist/types/client/ui_utils/src/spinner.js +5 -0
  26. package/dist/types/functions/auth_utils/imports.d.ts +2 -2
  27. package/dist/types/functions/auth_utils/imports.js +1 -0
  28. package/dist/types/functions/auth_utils/index.d.ts +1 -1
  29. package/dist/types/functions/auth_utils/index.js +1 -0
  30. package/dist/types/functions/auth_utils/src/index.d.ts +1 -1
  31. package/dist/types/functions/auth_utils/src/index.js +1 -0
  32. package/dist/types/functions/auth_utils/src/jwt_core.d.ts +1 -1
  33. package/dist/types/functions/auth_utils/src/jwt_core.js +25 -0
  34. package/dist/types/functions/auth_utils/src/token_utils (Copy).d.ts +1 -1
  35. package/dist/types/functions/auth_utils/src/token_utils (Copy).js +25 -0
  36. package/dist/types/functions/auth_utils/src/token_utils.d.ts +1 -1
  37. package/dist/types/functions/auth_utils/src/token_utils.js +105 -0
  38. package/dist/types/functions/config_utils/imports.d.ts +3 -3
  39. package/dist/types/functions/config_utils/imports.js +2 -0
  40. package/dist/types/functions/config_utils/index.d.ts +1 -1
  41. package/dist/types/functions/config_utils/index.js +1 -0
  42. package/dist/types/functions/config_utils/src/config_utils.d.ts +1 -1
  43. package/dist/types/functions/config_utils/src/config_utils.js +83 -0
  44. package/dist/types/functions/config_utils/src/index.d.ts +1 -1
  45. package/dist/types/functions/config_utils/src/index.js +1 -0
  46. package/dist/types/functions/constants_utils/index.d.ts +1 -1
  47. package/dist/types/functions/constants_utils/index.js +1 -0
  48. package/dist/types/functions/constants_utils/src/constants.js +7 -0
  49. package/dist/types/functions/constants_utils/src/index.d.ts +1 -1
  50. package/dist/types/functions/constants_utils/src/index.js +1 -0
  51. package/dist/types/functions/env_utils/imports.d.ts +1 -1
  52. package/dist/types/functions/env_utils/imports.js +1 -0
  53. package/dist/types/functions/env_utils/index.d.ts +1 -1
  54. package/dist/types/functions/env_utils/index.js +1 -0
  55. package/dist/types/functions/env_utils/src/index.d.ts +1 -1
  56. package/dist/types/functions/env_utils/src/index.js +1 -0
  57. package/dist/types/functions/env_utils/src/window_utils.js +47 -0
  58. package/dist/types/functions/fetch_utils/imports.d.ts +2 -2
  59. package/dist/types/functions/fetch_utils/imports.js +1 -0
  60. package/dist/types/functions/fetch_utils/index.d.ts +1 -1
  61. package/dist/types/functions/fetch_utils/index.js +1 -0
  62. package/dist/types/functions/fetch_utils/src/fetch_utils.js +70 -0
  63. package/dist/types/functions/fetch_utils/src/index.d.ts +3 -3
  64. package/dist/types/functions/fetch_utils/src/index.js +3 -0
  65. package/dist/types/functions/fetch_utils/src/url_utils.js +86 -0
  66. package/dist/types/functions/fetch_utils/src/utils.d.ts +1 -1
  67. package/dist/types/functions/fetch_utils/src/utils.js +102 -0
  68. package/dist/types/functions/index.d.ts +17 -17
  69. package/dist/types/functions/index.js +17 -0
  70. package/dist/types/functions/inspect_utils/imports.js +1 -0
  71. package/dist/types/functions/inspect_utils/index.d.ts +2 -2
  72. package/dist/types/functions/inspect_utils/index.js +2 -0
  73. package/dist/types/functions/inspect_utils/src/caller_utils.js +28 -0
  74. package/dist/types/functions/inspect_utils/src/index.d.ts +1 -1
  75. package/dist/types/functions/inspect_utils/src/index.js +1 -0
  76. package/dist/types/functions/math_utils/bigint_utils.js +36 -0
  77. package/dist/types/functions/math_utils/constants.js +37 -0
  78. package/dist/types/functions/math_utils/conversions.d.ts +1 -1
  79. package/dist/types/functions/math_utils/conversions.js +129 -0
  80. package/dist/types/functions/math_utils/index.d.ts +6 -6
  81. package/dist/types/functions/math_utils/index.js +6 -0
  82. package/dist/types/functions/math_utils/safe_math.js +35 -0
  83. package/dist/types/functions/math_utils/scaleInterfaces.js +3 -0
  84. package/dist/types/functions/math_utils/time_utils.js +4 -0
  85. package/dist/types/functions/path_utils/imports.d.ts +2 -2
  86. package/dist/types/functions/path_utils/imports.js +27 -0
  87. package/dist/types/functions/path_utils/index.d.ts +1 -1
  88. package/dist/types/functions/path_utils/index.js +1 -0
  89. package/dist/types/functions/path_utils/src/base_dirs.js +17 -0
  90. package/dist/types/functions/path_utils/src/function_dirs.js +42 -0
  91. package/dist/types/functions/path_utils/src/index.d.ts +6 -6
  92. package/dist/types/functions/path_utils/src/index.js +6 -0
  93. package/dist/types/functions/path_utils/src/misc_dirs.js +15 -0
  94. package/dist/types/functions/path_utils/src/path_utils.js +160 -0
  95. package/dist/types/functions/path_utils/src/paths.js +12 -0
  96. package/dist/types/functions/path_utils/src/src_dirs.js +25 -0
  97. package/dist/types/functions/print_utils/imports.d.ts +1 -1
  98. package/dist/types/functions/print_utils/imports.js +1 -0
  99. package/dist/types/functions/print_utils/index.d.ts +1 -1
  100. package/dist/types/functions/print_utils/index.js +1 -0
  101. package/dist/types/functions/print_utils/src/index.d.ts +1 -1
  102. package/dist/types/functions/print_utils/src/index.js +1 -0
  103. package/dist/types/functions/print_utils/src/print_utils.js +14 -0
  104. package/dist/types/functions/read_utils/imports.d.ts +1 -1
  105. package/dist/types/functions/read_utils/imports.js +1 -0
  106. package/dist/types/functions/read_utils/index.d.ts +1 -1
  107. package/dist/types/functions/read_utils/index.js +1 -0
  108. package/dist/types/functions/read_utils/src/index.d.ts +3 -3
  109. package/dist/types/functions/read_utils/src/index.js +3 -0
  110. package/dist/types/functions/read_utils/src/readJsonFile.browser.js +26 -0
  111. package/dist/types/functions/read_utils/src/readJsonFile.js +35 -0
  112. package/dist/types/functions/read_utils/src/readJsonFile.node.js +13 -0
  113. package/dist/types/functions/rndm_utils/imports.d.ts +1 -0
  114. package/dist/types/functions/rndm_utils/imports.js +1 -0
  115. package/dist/types/functions/rndm_utils/index.d.ts +1 -1
  116. package/dist/types/functions/rndm_utils/index.js +1 -0
  117. package/dist/types/functions/rndm_utils/src/index.d.ts +1 -1
  118. package/dist/types/functions/rndm_utils/src/index.js +1 -0
  119. package/dist/types/functions/rndm_utils/src/utils.js +12 -0
  120. package/dist/types/functions/safe_utils/imports.d.ts +1 -1
  121. package/dist/types/functions/safe_utils/imports.js +1 -0
  122. package/dist/types/functions/safe_utils/index.d.ts +1 -1
  123. package/dist/types/functions/safe_utils/index.js +1 -0
  124. package/dist/types/functions/safe_utils/src/index.d.ts +4 -4
  125. package/dist/types/functions/safe_utils/src/index.js +4 -0
  126. package/dist/types/functions/safe_utils/src/safe_document.js +12 -0
  127. package/dist/types/functions/safe_utils/src/safe_globals.js +14 -0
  128. package/dist/types/functions/safe_utils/src/safe_storage.js +50 -0
  129. package/dist/types/functions/safe_utils/src/safe_window.js +42 -0
  130. package/dist/types/functions/size_utils/index.d.ts +1 -1
  131. package/dist/types/functions/size_utils/index.js +1 -0
  132. package/dist/types/functions/size_utils/src/index.d.ts +1 -1
  133. package/dist/types/functions/size_utils/src/index.js +1 -0
  134. package/dist/types/functions/size_utils/src/sizeUtils.js +44 -0
  135. package/dist/types/functions/string_utils/index.d.ts +1 -1
  136. package/dist/types/functions/string_utils/index.js +1 -0
  137. package/dist/types/functions/string_utils/src/index.d.ts +2 -2
  138. package/dist/types/functions/string_utils/src/index.js +2 -0
  139. package/dist/types/functions/string_utils/src/quote_utils.js +17 -0
  140. package/dist/types/functions/string_utils/src/string_utils.js +186 -0
  141. package/dist/types/functions/type_utils/imports.d.ts +1 -0
  142. package/dist/types/functions/type_utils/imports.js +1 -0
  143. package/dist/types/functions/type_utils/index.d.ts +1 -1
  144. package/dist/types/functions/type_utils/index.js +1 -0
  145. package/dist/types/functions/type_utils/src/clean_utils.js +38 -0
  146. package/dist/types/functions/type_utils/src/ensure_utils.js +84 -0
  147. package/dist/types/functions/type_utils/src/imports.d.ts +1 -0
  148. package/dist/types/functions/type_utils/src/imports.js +1 -0
  149. package/dist/types/functions/type_utils/src/index.d.ts +6 -6
  150. package/dist/types/functions/type_utils/src/index.js +6 -0
  151. package/dist/types/functions/type_utils/src/json_utils.js +93 -0
  152. package/dist/types/functions/type_utils/src/list_utils.js +83 -0
  153. package/dist/types/functions/type_utils/src/mime_utils.js +314 -0
  154. package/dist/types/functions/type_utils/src/null_utils.js +21 -0
  155. package/dist/types/functions/type_utils/src/type_utils.js +39 -0
  156. package/dist/types/functions/variable_utils/imports.d.ts +1 -1
  157. package/dist/types/functions/variable_utils/imports.js +1 -0
  158. package/dist/types/functions/variable_utils/index.d.ts +1 -1
  159. package/dist/types/functions/variable_utils/index.js +1 -0
  160. package/dist/types/functions/variable_utils/src/index.d.ts +1 -1
  161. package/dist/types/functions/variable_utils/src/index.js +1 -0
  162. package/dist/types/functions/variable_utils/src/variable_utils.js +34 -0
  163. package/dist/types/index.d.ts +2 -2
  164. package/dist/types/index.js +2 -0
  165. package/dist/types/server/index.d.ts +1 -1
  166. package/dist/types/server/index.js +2 -0
  167. package/dist/types/server/src/index.d.ts +1 -1
  168. package/dist/types/server/src/index.js +2 -0
  169. package/dist/types/server/src/mime_utils.js +314 -0
  170. package/dist/types/types/index.d.ts +1 -1
  171. package/dist/types/types/index.js +1 -0
  172. package/dist/types/types/path-browserify.d.ts +3 -2
  173. package/dist/types/types/path-browserify.js +1 -0
  174. package/dist/types/types/src/Files.js +1 -0
  175. package/dist/types/types/src/index.d.ts +4 -4
  176. package/dist/types/types/src/index.js +4 -0
  177. package/dist/types/types/src/login.js +1 -0
  178. package/dist/types/types/src/logout.js +1 -0
  179. package/dist/types/types/src/utils.js +1 -0
  180. package/dist/types/utils/imports.d.ts +1 -1
  181. package/dist/types/utils/imports.js +1 -0
  182. package/dist/types/utils/index.d.ts +1 -1
  183. package/dist/types/utils/index.js +1 -0
  184. package/dist/types/utils/src/Input.js +2 -0
  185. package/dist/types/utils/src/config.js +27 -0
  186. package/dist/types/utils/src/index.d.ts +2 -2
  187. package/dist/types/utils/src/index.js +2 -0
  188. package/package.json +13 -2
@@ -0,0 +1,47 @@
1
+ import { BASE_URL, DEV_PREFIX } from './../imports';
2
+ export function get_window() {
3
+ try {
4
+ if (typeof window !== 'undefined') {
5
+ return window;
6
+ }
7
+ }
8
+ catch (err) {
9
+ alert(err);
10
+ }
11
+ return null;
12
+ }
13
+ export function get_window_location() {
14
+ try {
15
+ const Window = get_window();
16
+ if (!Window) {
17
+ return BASE_URL;
18
+ }
19
+ return Window.location;
20
+ }
21
+ catch (err) {
22
+ alert(err);
23
+ }
24
+ return null;
25
+ }
26
+ export function get_window_pathname() {
27
+ try {
28
+ const Window = get_window();
29
+ if (!Window) {
30
+ return DEV_PREFIX;
31
+ }
32
+ return Window.location.pathname;
33
+ }
34
+ catch (err) {
35
+ alert(err);
36
+ }
37
+ return null;
38
+ }
39
+ export function get_window_parts() {
40
+ try {
41
+ return get_window_location();
42
+ }
43
+ catch (err) {
44
+ alert(err);
45
+ }
46
+ return null;
47
+ }
@@ -1,2 +1,2 @@
1
- export { readJsonFile, getConfigContent } from './../read_utils';
2
- export type { LogoutButtonProps, FetchVariables, UrlKey } from './../../types';
1
+ export { readJsonFile, getConfigContent } from './../read_utils/index.js';
2
+ export type { LogoutButtonProps, FetchVariables, UrlKey } from './../../types/index.js';
@@ -0,0 +1 @@
1
+ export { readJsonFile, getConfigContent } from './../read_utils';
@@ -1 +1 @@
1
- export * from './src';
1
+ export * from './src/index.js';
@@ -0,0 +1 @@
1
+ export * from './src';
@@ -0,0 +1,70 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getResult } from './utils';
11
+ export function fetchIt(endpoint_1) {
12
+ return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnReult = true) {
13
+ method = (method || "GET").toUpperCase();
14
+ // 1) auto-detect absolute URLs
15
+ const isAbsolute = typeof endpoint === "string" && /^https?:\/\//i.test(endpoint);
16
+ // 2) choose the URL
17
+ const url = endpoint;
18
+ // 3) prepare headers & body
19
+ headers = Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), headers);
20
+ const opts = {
21
+ method,
22
+ credentials: withCredentials ? "include" : "same-origin",
23
+ headers,
24
+ body: body instanceof FormData
25
+ ? body
26
+ : body != null && method !== "GET"
27
+ ? JSON.stringify(body)
28
+ : undefined,
29
+ };
30
+ console.debug("➡️ secureFetchIt →", url, opts);
31
+ const res = yield fetch(url, opts);
32
+ if (!res.ok) {
33
+ const err = yield res.text();
34
+ throw new Error(`HTTP ${res.status}: ${err}`);
35
+ }
36
+ if (blob)
37
+ return res.blob();
38
+ if (returnReult)
39
+ return getResult(res.json());
40
+ if (returnJson)
41
+ return res.json();
42
+ return res;
43
+ });
44
+ }
45
+ // Constructs HTML directory path
46
+ export function getHtmlDirectory(directory, filename) {
47
+ return `${directory}/${filename}.html`;
48
+ }
49
+ // Fetches HTML content
50
+ export function fetchIndexHtml(filename_1) {
51
+ return __awaiter(this, arguments, void 0, function* (filename, directory = 'sf_index', base = 'html') {
52
+ const url = `/${base}/${directory}/${filename}.html`;
53
+ const response = yield fetch(url);
54
+ return yield response.text();
55
+ });
56
+ }
57
+ // Fetches and injects HTML content into container
58
+ export function fetchIndexHtmlContainer(filename_1) {
59
+ return __awaiter(this, arguments, void 0, function* (filename, doc = document, directory = 'html') {
60
+ const container = `${filename}-container`;
61
+ const html = yield fetchIndexHtml(filename, directory);
62
+ const el = doc.getElementById(container);
63
+ if (el) {
64
+ el.innerHTML = html;
65
+ }
66
+ else {
67
+ console.warn(`⚠️ No container found for: #${container}`);
68
+ }
69
+ });
70
+ }
@@ -1,3 +1,3 @@
1
- export * from './fetch_utils';
2
- export * from './utils';
3
- export * from './url_utils';
1
+ export * from './fetch_utils.js';
2
+ export * from './utils.js';
3
+ export * from './url_utils.js';
@@ -0,0 +1,3 @@
1
+ export * from './fetch_utils';
2
+ export * from './utils';
3
+ export * from './url_utils';
@@ -0,0 +1,86 @@
1
+ import path from 'path';
2
+ export function urlJoin(...parts) {
3
+ var _a;
4
+ const s = (parts.length === 1 && Array.isArray(parts[0]) ? parts[0] : parts);
5
+ let r = "";
6
+ for (let i = 0; i < s.length; i++) {
7
+ let d = ((_a = s[i]) !== null && _a !== void 0 ? _a : "").toString();
8
+ if (!d)
9
+ continue;
10
+ if (i === 0)
11
+ r = d;
12
+ else {
13
+ d = d.replace(/^\/+/, "");
14
+ r = r.replace(/\/+$/, "");
15
+ r = `${r}/${d}`;
16
+ }
17
+ }
18
+ return r;
19
+ }
20
+ /**
21
+ * Returns a full URL.
22
+ * If partial_url is already absolute (starts with http), it is returned as is.
23
+ * Otherwise, it is combined with the base URL.
24
+ */
25
+ export function get_full_url(partial_url, domain = null) {
26
+ if (typeof partial_url !== 'string') {
27
+ throw new Error('partial_url must be a string');
28
+ }
29
+ // If it already starts with http, assume it is absolute.
30
+ if (partial_url.startsWith('http')) {
31
+ return partial_url;
32
+ }
33
+ return urlJoin(domain, partial_url);
34
+ }
35
+ /**
36
+ * Returns a full file system path.
37
+ * If partial_path is already absolute, it is returned as is.
38
+ * Otherwise, it is joined with the base directory.
39
+ */
40
+ export function get_full_path(partial_path, parent_dir = null) {
41
+ if (typeof partial_path !== 'string') {
42
+ throw new Error('partial_path must be a string');
43
+ }
44
+ if (path.isAbsolute(partial_path)) {
45
+ return partial_path;
46
+ }
47
+ return urlJoin(parent_dir, partial_path);
48
+ }
49
+ /**
50
+ * Converts a local file system path into its corresponding URL.
51
+ * It checks against the known directories in all_paths and replaces the matching base.
52
+ */
53
+ export function path_to_url(filePath, all_paths) {
54
+ if (typeof filePath !== 'string') {
55
+ throw new Error('filePath must be a string');
56
+ }
57
+ for (const key in all_paths) {
58
+ const mapping = all_paths[key];
59
+ const normalizedBase = path.normalize(mapping.path);
60
+ if (filePath.startsWith(normalizedBase)) {
61
+ const relativePath = filePath.substring(normalizedBase.length);
62
+ return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
63
+ }
64
+ }
65
+ return null;
66
+ }
67
+ /**
68
+ * Converts a URL into its corresponding local file system path.
69
+ * It checks against the known URL prefixes in all_paths and replaces the matching base.
70
+ */
71
+ export function url_to_path(urlStr, all_paths) {
72
+ if (typeof urlStr !== 'string') {
73
+ throw new Error('urlStr must be a string');
74
+ }
75
+ for (const key in all_paths) {
76
+ const mapping = all_paths[key];
77
+ if (urlStr.startsWith(mapping.url)) {
78
+ const relativeUrl = urlStr.substring(mapping.url.length);
79
+ return urlJoin(mapping.path, relativeUrl);
80
+ }
81
+ }
82
+ return null;
83
+ }
84
+ export function urljoin(...parts) {
85
+ return urlJoin(...parts);
86
+ }
@@ -1,4 +1,4 @@
1
- import { FetchVariables } from './../imports';
1
+ import { FetchVariables } from './../imports.js';
2
2
  /**
3
3
  * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
4
4
  */
@@ -0,0 +1,102 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
12
+ */
13
+ export function getResult(obj) {
14
+ let current = obj;
15
+ while (current &&
16
+ typeof current === "object" &&
17
+ Object.prototype.hasOwnProperty.call(current, "result")) {
18
+ current = current.result;
19
+ }
20
+ return current;
21
+ }
22
+ // Determines HTTP method, defaults to GET or POST based on body
23
+ export function getMethod(method = null, body = null) {
24
+ const validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'PULL'];
25
+ method = (method || '').toUpperCase();
26
+ if (!validMethods.includes(method)) {
27
+ method = body ? 'POST' : 'GET';
28
+ }
29
+ return method;
30
+ }
31
+ // Gets headers, skips JSON headers when body is FormData
32
+ export function getHeaders(headers = {}, method = null, body = null) {
33
+ const result = Object.assign({}, headers);
34
+ // let browser set boundary
35
+ if (body instanceof FormData) {
36
+ return result;
37
+ }
38
+ const upper = method === null || method === void 0 ? void 0 : method.toUpperCase();
39
+ if (['POST', 'PUT', 'PATCH'].includes(upper !== null && upper !== void 0 ? upper : '') &&
40
+ !result['Content-Type']) {
41
+ result['Content-Type'] = 'application/json';
42
+ }
43
+ return result;
44
+ }
45
+ // Prepares request body, serializes to JSON for non-GET requests
46
+ export function getBody(body = null, method = null) {
47
+ method = getMethod(method, body);
48
+ if (method === 'GET') {
49
+ return undefined;
50
+ }
51
+ if (body) {
52
+ try {
53
+ return JSON.stringify(body);
54
+ }
55
+ catch (err) {
56
+ return body;
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+ // Prepares fetch variables, passes FormData intact
62
+ export function getFetchVars(headers = null, method = null, body = null) {
63
+ method = getMethod(method, body);
64
+ headers = getHeaders(headers || {}, method, body);
65
+ // only JSON-stringify non-FormData bodies
66
+ if (!(body instanceof FormData)) {
67
+ body = getBody(body, method);
68
+ }
69
+ return { method, headers, body };
70
+ }
71
+ /*
72
+ * parseResult no longer needs to worry about JSON vs HTML redirect errors;
73
+ * all 401/403 have already been handled above.
74
+ */
75
+ export function parseResult(res) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ // runs checkResponse first, will throw if session is expired
78
+ res = checkResponse(res);
79
+ if (!res.ok) {
80
+ // for any other non-401 errors, you can still surface them
81
+ const errorText = yield res.text();
82
+ throw new Error(errorText || res.statusText);
83
+ }
84
+ // now safely parse JSON
85
+ return res.json();
86
+ });
87
+ }
88
+ /**
89
+ * Intercept 401/403 and force a clean redirect to login
90
+ * without ever showing an alert.
91
+ */
92
+ export function checkResponse(res) {
93
+ if (res.status === 401 || res.status === 403) {
94
+ // 1) clear out the stale token
95
+ localStorage.removeItem("token");
96
+ // 2) replace history so "back" doesn’t re-trigger the protected route
97
+ window.history.replaceState({}, "", "/secure-files");
98
+ // 3) short-circuit all further fetch logic
99
+ throw new Error("SessionExpired");
100
+ }
101
+ return res;
102
+ }
@@ -1,17 +1,17 @@
1
- export * from './auth_utils';
2
- export * from './constants_utils';
3
- export * from './env_utils';
4
- export * from './fetch_utils';
5
- export * from './path_utils';
6
- export * from './rndm_utils';
7
- export * from './string_utils';
8
- export * from './math_utils';
9
- export * from './type_utils';
10
- export * from './config_utils';
11
- export * from './read_utils';
12
- export * from './safe_utils';
13
- export * from './read_utils';
14
- export * from './variable_utils';
15
- export * from './size_utils';
16
- export * from './print_utils';
17
- export * from './inspect_utils';
1
+ export * from './auth_utils/index.js';
2
+ export * from './constants_utils/index.js';
3
+ export * from './env_utils/index.js';
4
+ export * from './fetch_utils/index.js';
5
+ export * from './path_utils/index.js';
6
+ export * from './rndm_utils/index.js';
7
+ export * from './string_utils/index.js';
8
+ export * from './math_utils/index.js';
9
+ export * from './type_utils/index.js';
10
+ export * from './config_utils/index.js';
11
+ export * from './read_utils/index.js';
12
+ export * from './safe_utils/index.js';
13
+ export * from './read_utils/index.js';
14
+ export * from './variable_utils/index.js';
15
+ export * from './size_utils/index.js';
16
+ export * from './print_utils/index.js';
17
+ export * from './inspect_utils/index.js';
@@ -0,0 +1,17 @@
1
+ export * from './auth_utils';
2
+ export * from './constants_utils';
3
+ export * from './env_utils';
4
+ export * from './fetch_utils';
5
+ export * from './path_utils';
6
+ export * from './rndm_utils';
7
+ export * from './string_utils';
8
+ export * from './math_utils';
9
+ export * from './type_utils';
10
+ export * from './config_utils';
11
+ export * from './read_utils';
12
+ export * from './safe_utils';
13
+ export * from './read_utils';
14
+ export * from './variable_utils';
15
+ export * from './size_utils';
16
+ export * from './print_utils';
17
+ export * from './inspect_utils';
@@ -0,0 +1 @@
1
+ export { inspect } from "util";
@@ -1,2 +1,2 @@
1
- export * from './src';
2
- export * from './imports';
1
+ export * from './src/index.js';
2
+ export * from './imports.js';
@@ -0,0 +1,2 @@
1
+ export * from './src';
2
+ export * from './imports';
@@ -0,0 +1,28 @@
1
+ export function getLastCaller(skip = ["debugPrint"]) {
2
+ var _a;
3
+ const stack = new Error().stack;
4
+ if (!stack)
5
+ return null;
6
+ const lines = stack
7
+ .split("\n")
8
+ .map(l => l.trim())
9
+ .slice(1); // drop "Error"
10
+ for (const line of lines) {
11
+ // Example:
12
+ // at processSingleAddress (/path/file.ts:142:7)
13
+ const match = line.match(/at (.+?) \((.+?):(\d+):(\d+)\)/) ||
14
+ line.match(/at (.+?):(\d+):(\d+)/);
15
+ if (!match)
16
+ continue;
17
+ const functionName = (_a = match[1]) !== null && _a !== void 0 ? _a : "anonymous";
18
+ if (skip.includes(functionName))
19
+ continue;
20
+ return {
21
+ functionName,
22
+ file: match[2],
23
+ line: Number(match[3]),
24
+ column: Number(match[4]),
25
+ };
26
+ }
27
+ return null;
28
+ }
@@ -1 +1 @@
1
- export * from './caller_utils';
1
+ export * from './caller_utils.js';
@@ -0,0 +1 @@
1
+ export * from './caller_utils';
@@ -0,0 +1,36 @@
1
+ // src/functions/typeUtils/numUtils.ts
2
+ import { getLogString } from '@putkoff/abstract-logger';
3
+ const FILE_LOCATION = 'src/functions/typeUtils/numUtils.ts';
4
+ /**
5
+ * Recursively traverse the object and convert BigInts to numbers or strings.
6
+ *
7
+ * @param {object|array} obj - The object to traverse
8
+ * @param {boolean} convertToNumber - Whether to convert BigInt to Number (default is true)
9
+ * @returns {object|array} - The transformed object
10
+ */
11
+ export function convertBigInts(obj, convertToNumber = true) {
12
+ if (obj === null || obj === undefined)
13
+ return obj;
14
+ try {
15
+ if (typeof obj === 'bigint') {
16
+ return convertToNumber ? Number(obj) : obj.toString();
17
+ }
18
+ if (typeof obj === 'object') {
19
+ if (Array.isArray(obj)) {
20
+ return obj.map((item) => convertBigInts(item, convertToNumber));
21
+ }
22
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, convertBigInts(value, convertToNumber)]));
23
+ }
24
+ }
25
+ catch (error) {
26
+ getLogString({
27
+ message: 'Error converting BigInt',
28
+ logType: 'warn',
29
+ details: error.message,
30
+ function_name: 'convertBigInts',
31
+ file_location: FILE_LOCATION
32
+ });
33
+ return obj;
34
+ }
35
+ return obj;
36
+ }
@@ -0,0 +1,37 @@
1
+ import { exponential } from './safe_math';
2
+ export const SECOND = 1;
3
+ export const ZEPTOSECOND = exponential(SECOND, -21);
4
+ export const ATTOSECOND = exponential(SECOND, -18);
5
+ export const FEMTOSECOND = exponential(SECOND, -15);
6
+ export const PICOSECOND = exponential(SECOND, -12);
7
+ export const NANOSECOND = exponential(SECOND, -9);
8
+ export const MICROSECOND = exponential(SECOND, -6);
9
+ export const MILISECOND = exponential(SECOND, -3);
10
+ export const CENTISECOND = exponential(SECOND, -2);
11
+ export const DECISECOND = exponential(SECOND, -1);
12
+ export const MINUTE = 60 * SECOND;
13
+ export const HOUR = 60 * MINUTE;
14
+ export const DAY = 24 * HOUR;
15
+ export const YEAR = 365 * DAY;
16
+ export const MONTH = YEAR / 12;
17
+ // Derived: explicit names
18
+ export const SECONDS_PER_MINUTE = MINUTE;
19
+ export const SECONDS_PER_HOUR = HOUR;
20
+ export const SECONDS_PER_DAY = DAY;
21
+ //math
22
+ export const PI = Math.PI;
23
+ export const PI2 = 2 * PI;
24
+ // Distance
25
+ export const METERS_PER_KM = 1000;
26
+ export const METERS_PER_MILE = 1609.34;
27
+ export const METERS_PER_FOOT = 0.3048;
28
+ export const KMS_PER_METER = 1 / METERS_PER_KM;
29
+ export const MILES_PER_METER = 1 / METERS_PER_MILE;
30
+ export const FEET_PER_METER = 1 / METERS_PER_FOOT;
31
+ export const MIN_IN_S = 1 / MINUTE;
32
+ export const HOUR_IN_S = 1 / HOUR;
33
+ export const DAY_IN_S = 1 / DAY;
34
+ export const YEAR_IN_S = 1 / YEAR;
35
+ export const MONTH_IN_S = 1 / MONTH;
36
+ export const MiPerH_TO_MPerS = METERS_PER_MILE * HOUR_IN_S;
37
+ export const MPerS_TO_MiPerH = 1 / MiPerH_TO_MPerS;
@@ -1,4 +1,4 @@
1
- import type { CanonTime, CanonDist, DistanceUnit, TimeUnit, ConvertDistance, ConvertTime, ConvertSpeed, OutDist, OutTimeType, OutSpeedType } from './scaleInterfaces';
1
+ import type { CanonTime, CanonDist, DistanceUnit, TimeUnit, ConvertDistance, ConvertTime, ConvertSpeed, OutDist, OutTimeType, OutSpeedType } from './scaleInterfaces.js';
2
2
  export declare const DIST_ALIASES: Record<string, CanonDist>;
3
3
  export declare const TIME_ALIASES: Record<string, CanonTime>;
4
4
  export declare const DIST_FACTORS: Record<CanonDist, number>;
@@ -0,0 +1,129 @@
1
+ // conversions.ts
2
+ import { METERS_PER_KM, METERS_PER_MILE, METERS_PER_FOOT, MINUTE, HOUR, DAY, } from "./constants";
3
+ import { safeMultiply, safeDivide } from "./safe_math";
4
+ /*───────────────────────────────────────────────────────────────
5
+ 🧭 CANONICAL MAPPINGS
6
+ ───────────────────────────────────────────────────────────────*/
7
+ export const DIST_ALIASES = {
8
+ m: "m", meter: "m", meters: "m",
9
+ km: "km", kms: "km", kilometer: "km", kilometers: "km",
10
+ mi: "mi", mile: "mi", miles: "mi",
11
+ ft: "ft", f: "ft", foot: "ft", feet: "ft",
12
+ };
13
+ export const TIME_ALIASES = {
14
+ s: "s", sec: "s", second: "s", seconds: "s",
15
+ min: "min", m: "min", minute: "min", minutes: "min",
16
+ h: "h", hr: "h", hour: "h", hours: "h",
17
+ day: "day", d: "day", days: "day",
18
+ };
19
+ export const DIST_FACTORS = {
20
+ m: 1,
21
+ km: METERS_PER_KM,
22
+ mi: METERS_PER_MILE,
23
+ ft: METERS_PER_FOOT,
24
+ };
25
+ export const TIME_FACTORS = {
26
+ s: 1,
27
+ min: MINUTE,
28
+ h: HOUR,
29
+ day: DAY,
30
+ };
31
+ /*───────────────────────────────────────────────────────────────
32
+ 🔍 CANONICALIZATION HELPERS
33
+ ───────────────────────────────────────────────────────────────*/
34
+ export function canonDist(u) {
35
+ const key = (u !== null && u !== void 0 ? u : "m").toString().toLowerCase();
36
+ const canon = DIST_ALIASES[key];
37
+ if (!canon)
38
+ throw new Error(`Unknown distance unit: ${u}`);
39
+ return canon;
40
+ }
41
+ export function canonTime(u) {
42
+ const key = (u !== null && u !== void 0 ? u : "s").toString().toLowerCase();
43
+ const canon = TIME_ALIASES[key];
44
+ if (!canon)
45
+ throw new Error(`Unknown time unit: ${u}`);
46
+ return canon;
47
+ }
48
+ /*───────────────────────────────────────────────────────────────
49
+ ⚖️ NORMALIZATION HELPERS
50
+ ───────────────────────────────────────────────────────────────*/
51
+ export function distanceToMeters(d, unit) {
52
+ const u = canonDist(unit);
53
+ return safeMultiply(d, DIST_FACTORS[u]);
54
+ }
55
+ export function metersToDistance(v, unit) {
56
+ const u = canonDist(unit);
57
+ return safeDivide(v, DIST_FACTORS[u]);
58
+ }
59
+ export function timeToSeconds(t, unit) {
60
+ const u = canonTime(unit);
61
+ return safeMultiply(t, TIME_FACTORS[u]);
62
+ }
63
+ export function secondsToTime(v, unit) {
64
+ const u = canonTime(unit);
65
+ return safeDivide(v, TIME_FACTORS[u]);
66
+ }
67
+ /*───────────────────────────────────────────────────────────────
68
+ 🚀 SPEED CONVERSIONS (normalize / unnormalize)
69
+ ───────────────────────────────────────────────────────────────*/
70
+ export function speedToMps(v, distUnit, timeUnit) {
71
+ const du = canonDist(distUnit);
72
+ const tu = canonTime(timeUnit);
73
+ return v * (DIST_FACTORS[du] / TIME_FACTORS[tu]);
74
+ }
75
+ export function mpsToSpeed(vMps, distUnit, timeUnit) {
76
+ const du = canonDist(distUnit);
77
+ const tu = canonTime(timeUnit);
78
+ return vMps * (TIME_FACTORS[tu] / DIST_FACTORS[du]);
79
+ }
80
+ /*───────────────────────────────────────────────────────────────
81
+ 🎯 UNIVERSAL CONVERTERS
82
+ ───────────────────────────────────────────────────────────────*/
83
+ export function convertDistance({ d, fromDist, toDist, vOnly = true, }) {
84
+ const m = distanceToMeters(d, fromDist);
85
+ const D = canonDist(toDist !== null && toDist !== void 0 ? toDist : "m");
86
+ const out = metersToDistance(m, D);
87
+ return vOnly ? out : { d: out, D };
88
+ }
89
+ export function convertTime({ t, fromTime, toTime, vOnly = true, }) {
90
+ const sec = timeToSeconds(t, fromTime);
91
+ const T = canonTime(toTime !== null && toTime !== void 0 ? toTime : "s");
92
+ const out = secondsToTime(sec, T);
93
+ return vOnly ? out : { t: out, T };
94
+ }
95
+ export function convertSpeed({ v, fromDist, fromTime, toDist, toTime, vOnly = true, }) {
96
+ const mps = speedToMps(v, fromDist, fromTime);
97
+ const d = canonDist(toDist !== null && toDist !== void 0 ? toDist : "m");
98
+ const t = canonTime(toTime !== null && toTime !== void 0 ? toTime : "s");
99
+ const out = mpsToSpeed(mps, d, t);
100
+ return vOnly ? out : { v: out, d, t };
101
+ }
102
+ export const DistanceConverter = {
103
+ normalize: distanceToMeters,
104
+ unnormalize: metersToDistance,
105
+ };
106
+ export const TimeConverter = {
107
+ normalize: timeToSeconds,
108
+ unnormalize: secondsToTime,
109
+ };
110
+ export const SpeedConverter = {
111
+ normalize: (v, [du, tu]) => speedToMps(v, du, tu),
112
+ unnormalize: (v, [du, tu]) => mpsToSpeed(v, du, tu),
113
+ };
114
+ /*───────────────────────────────────────────────────────────────
115
+ 🧩 COMPATIBILITY WRAPPERS (legacy aliases)
116
+ ───────────────────────────────────────────────────────────────*/
117
+ export const toMeters = distanceToMeters;
118
+ export const fromMeters = metersToDistance;
119
+ export const toSeconds = timeToSeconds;
120
+ export const fromSeconds = secondsToTime;
121
+ export const velocityToMs = (value, unit) => speedToMps(value, unit, "s");
122
+ export const velocityFromMs = (value, unit) => mpsToSpeed(value, unit, "s");
123
+ /** Non-canonical helper for arbitrary rate conversion, e.g. ft/day → m/s */
124
+ export const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit);
125
+ /*───────────────────────────────────────────────────────────────
126
+ 📊 UTILITIES
127
+ ───────────────────────────────────────────────────────────────*/
128
+ export const isFiniteNum = (x) => Number.isFinite(x);
129
+ export const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";