@putkoff/abstract-utilities 1.0.113 → 1.0.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client.js +1 -11
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/functions.js +4 -14
- package/dist/cjs/functions.js.map +1 -1
- package/dist/cjs/index.js +4 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/{print_utils-DzyRoj6m.js → print_utils-DhPs0s0W.js} +6 -16
- package/dist/cjs/print_utils-DhPs0s0W.js.map +1 -0
- package/dist/cjs/safe_storage-B6MYZDKg.js +941 -0
- package/dist/cjs/safe_storage-B6MYZDKg.js.map +1 -0
- package/dist/esm/client.js +1 -11
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/functions.js +2 -12
- package/dist/esm/functions.js.map +1 -1
- package/dist/esm/index.js +2 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/{print_utils-qqcMhSul.js → print_utils-gTxtZBM7.js} +2 -12
- package/dist/esm/print_utils-gTxtZBM7.js.map +1 -0
- package/dist/esm/safe_storage-D4QfcTw0.js +897 -0
- package/dist/esm/safe_storage-D4QfcTw0.js.map +1 -0
- package/dist/types/client/auth/index.d.ts +1 -1
- package/dist/types/client/auth/src/index.d.ts +1 -1
- package/dist/types/client/fetch/src/fetch_auth.d.ts +1 -1
- package/dist/types/client/fetch/src/index.d.ts +1 -1
- package/dist/types/client/index.d.ts +2 -2
- package/dist/types/client/ui_utils/index.d.ts +1 -1
- package/dist/types/client/ui_utils/src/index.d.ts +4 -4
- package/dist/types/functions/auth_utils/imports.d.ts +2 -2
- package/dist/types/functions/auth_utils/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/jwt_core.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/token_utils (Copy).d.ts +1 -1
- package/dist/types/functions/auth_utils/src/token_utils.d.ts +1 -1
- package/dist/types/functions/config_utils/imports.d.ts +3 -3
- package/dist/types/functions/config_utils/index.d.ts +1 -1
- package/dist/types/functions/config_utils/src/config_utils.d.ts +1 -1
- package/dist/types/functions/config_utils/src/index.d.ts +1 -1
- package/dist/types/functions/constants_utils/index.d.ts +1 -1
- package/dist/types/functions/constants_utils/src/index.d.ts +1 -1
- package/dist/types/functions/env_utils/imports.d.ts +1 -1
- package/dist/types/functions/env_utils/index.d.ts +1 -1
- package/dist/types/functions/env_utils/src/index.d.ts +1 -1
- package/dist/types/functions/fetch_utils/imports.d.ts +2 -2
- package/dist/types/functions/fetch_utils/index.d.ts +1 -1
- package/dist/types/functions/fetch_utils/src/index.d.ts +3 -3
- package/dist/types/functions/fetch_utils/src/utils.d.ts +1 -1
- package/dist/types/functions/inspect_utils/index.d.ts +2 -2
- package/dist/types/functions/inspect_utils/src/index.d.ts +1 -1
- package/dist/types/functions/math_utils/conversions.d.ts +1 -1
- package/dist/types/functions/math_utils/index.d.ts +6 -6
- package/dist/types/functions/path_utils/imports.d.ts +2 -2
- package/dist/types/functions/path_utils/index.d.ts +1 -1
- package/dist/types/functions/path_utils/src/index.d.ts +6 -6
- package/dist/types/functions/print_utils/imports.d.ts +1 -1
- package/dist/types/functions/print_utils/index.d.ts +1 -1
- package/dist/types/functions/print_utils/src/index.d.ts +1 -1
- package/dist/types/functions/read_utils/imports.d.ts +1 -1
- package/dist/types/functions/read_utils/index.d.ts +1 -1
- package/dist/types/functions/read_utils/src/index.d.ts +3 -3
- package/dist/types/functions/rndm_utils/imports.d.ts +0 -1
- package/dist/types/functions/rndm_utils/index.d.ts +1 -1
- package/dist/types/functions/rndm_utils/src/index.d.ts +1 -1
- package/dist/types/functions/safe_utils/imports.d.ts +1 -1
- package/dist/types/functions/safe_utils/index.d.ts +1 -1
- package/dist/types/functions/safe_utils/src/index.d.ts +4 -4
- package/dist/types/functions/size_utils/index.d.ts +1 -1
- package/dist/types/functions/size_utils/src/index.d.ts +1 -1
- package/dist/types/functions/string_utils/index.d.ts +1 -1
- package/dist/types/functions/string_utils/src/index.d.ts +2 -2
- package/dist/types/functions/type_utils/imports.d.ts +0 -1
- package/dist/types/functions/type_utils/index.d.ts +1 -1
- package/dist/types/functions/type_utils/src/imports.d.ts +0 -1
- package/dist/types/functions/type_utils/src/index.d.ts +6 -6
- package/dist/types/functions/variable_utils/imports.d.ts +1 -1
- package/dist/types/functions/variable_utils/index.d.ts +1 -1
- package/dist/types/functions/variable_utils/src/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/server/src/index.d.ts +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/path-browserify.d.ts +2 -3
- package/dist/types/types/src/index.d.ts +4 -4
- package/dist/types/utils/imports.d.ts +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/src/index.d.ts +2 -2
- package/package.json +2 -2
- package/dist/cjs/print_utils-DzyRoj6m.js.map +0 -1
- package/dist/cjs/safe_storage-CJgWghnh.js +0 -15986
- package/dist/cjs/safe_storage-CJgWghnh.js.map +0 -1
- package/dist/esm/print_utils-qqcMhSul.js.map +0 -1
- package/dist/esm/safe_storage-CMuv35Vo.js +0 -15941
- package/dist/esm/safe_storage-CMuv35Vo.js.map +0 -1
- package/dist/types/client/auth/index.js +0 -3
- package/dist/types/client/auth/src/index.js +0 -3
- package/dist/types/client/auth/src/token_client.js +0 -73
- package/dist/types/client/fetch/src/fetch_auth.js +0 -26
- package/dist/types/client/fetch/src/index.js +0 -2
- package/dist/types/client/index.js +0 -4
- package/dist/types/client/ui_utils/index.js +0 -2
- package/dist/types/client/ui_utils/src/button.js +0 -34
- package/dist/types/client/ui_utils/src/checkbox.js +0 -18
- package/dist/types/client/ui_utils/src/index.js +0 -4
- package/dist/types/client/ui_utils/src/input.js +0 -18
- package/dist/types/client/ui_utils/src/spinner.js +0 -5
- package/dist/types/functions/auth_utils/imports.js +0 -1
- package/dist/types/functions/auth_utils/index.js +0 -1
- package/dist/types/functions/auth_utils/src/index.js +0 -1
- package/dist/types/functions/auth_utils/src/jwt_core.js +0 -25
- package/dist/types/functions/auth_utils/src/token_utils (Copy).js +0 -25
- package/dist/types/functions/auth_utils/src/token_utils.js +0 -105
- package/dist/types/functions/config_utils/imports.js +0 -2
- package/dist/types/functions/config_utils/index.js +0 -1
- package/dist/types/functions/config_utils/src/config_utils.js +0 -83
- package/dist/types/functions/config_utils/src/index.js +0 -1
- package/dist/types/functions/constants_utils/index.js +0 -1
- package/dist/types/functions/constants_utils/src/constants.js +0 -7
- package/dist/types/functions/constants_utils/src/index.js +0 -1
- package/dist/types/functions/env_utils/imports.js +0 -1
- package/dist/types/functions/env_utils/index.js +0 -1
- package/dist/types/functions/env_utils/src/index.js +0 -1
- package/dist/types/functions/env_utils/src/window_utils.js +0 -47
- package/dist/types/functions/fetch_utils/imports.js +0 -1
- package/dist/types/functions/fetch_utils/index.js +0 -1
- package/dist/types/functions/fetch_utils/src/fetch_utils.js +0 -70
- package/dist/types/functions/fetch_utils/src/index.js +0 -3
- package/dist/types/functions/fetch_utils/src/url_utils.js +0 -86
- package/dist/types/functions/fetch_utils/src/utils.js +0 -102
- package/dist/types/functions/index.js +0 -17
- package/dist/types/functions/inspect_utils/imports.js +0 -1
- package/dist/types/functions/inspect_utils/index.js +0 -2
- package/dist/types/functions/inspect_utils/src/caller_utils.js +0 -28
- package/dist/types/functions/inspect_utils/src/index.js +0 -1
- package/dist/types/functions/math_utils/bigint_utils.js +0 -36
- package/dist/types/functions/math_utils/constants.js +0 -37
- package/dist/types/functions/math_utils/conversions.js +0 -129
- package/dist/types/functions/math_utils/index.js +0 -6
- package/dist/types/functions/math_utils/safe_math.js +0 -35
- package/dist/types/functions/math_utils/scaleInterfaces.js +0 -3
- package/dist/types/functions/math_utils/time_utils.js +0 -4
- package/dist/types/functions/path_utils/imports.js +0 -27
- package/dist/types/functions/path_utils/index.js +0 -1
- package/dist/types/functions/path_utils/src/base_dirs.js +0 -17
- package/dist/types/functions/path_utils/src/function_dirs.js +0 -42
- package/dist/types/functions/path_utils/src/index.js +0 -6
- package/dist/types/functions/path_utils/src/misc_dirs.js +0 -15
- package/dist/types/functions/path_utils/src/path_utils.js +0 -160
- package/dist/types/functions/path_utils/src/paths.js +0 -12
- package/dist/types/functions/path_utils/src/src_dirs.js +0 -25
- package/dist/types/functions/print_utils/imports.js +0 -1
- package/dist/types/functions/print_utils/index.js +0 -1
- package/dist/types/functions/print_utils/src/index.js +0 -1
- package/dist/types/functions/print_utils/src/print_utils.js +0 -14
- package/dist/types/functions/read_utils/imports.js +0 -1
- package/dist/types/functions/read_utils/index.js +0 -1
- package/dist/types/functions/read_utils/src/index.js +0 -3
- package/dist/types/functions/read_utils/src/readJsonFile.browser.js +0 -26
- package/dist/types/functions/read_utils/src/readJsonFile.js +0 -35
- package/dist/types/functions/read_utils/src/readJsonFile.node.js +0 -13
- package/dist/types/functions/rndm_utils/imports.js +0 -1
- package/dist/types/functions/rndm_utils/index.js +0 -1
- package/dist/types/functions/rndm_utils/src/index.js +0 -1
- package/dist/types/functions/rndm_utils/src/utils.js +0 -12
- package/dist/types/functions/safe_utils/imports.js +0 -1
- package/dist/types/functions/safe_utils/index.js +0 -1
- package/dist/types/functions/safe_utils/src/index.js +0 -4
- package/dist/types/functions/safe_utils/src/safe_document.js +0 -12
- package/dist/types/functions/safe_utils/src/safe_globals.js +0 -14
- package/dist/types/functions/safe_utils/src/safe_storage.js +0 -50
- package/dist/types/functions/safe_utils/src/safe_window.js +0 -42
- package/dist/types/functions/size_utils/index.js +0 -1
- package/dist/types/functions/size_utils/src/index.js +0 -1
- package/dist/types/functions/size_utils/src/sizeUtils.js +0 -44
- package/dist/types/functions/string_utils/index.js +0 -1
- package/dist/types/functions/string_utils/src/index.js +0 -2
- package/dist/types/functions/string_utils/src/quote_utils.js +0 -17
- package/dist/types/functions/string_utils/src/string_utils.js +0 -186
- package/dist/types/functions/type_utils/imports.js +0 -1
- package/dist/types/functions/type_utils/index.js +0 -1
- package/dist/types/functions/type_utils/src/clean_utils.js +0 -38
- package/dist/types/functions/type_utils/src/ensure_utils.js +0 -84
- package/dist/types/functions/type_utils/src/imports.js +0 -1
- package/dist/types/functions/type_utils/src/index.js +0 -6
- package/dist/types/functions/type_utils/src/json_utils.js +0 -93
- package/dist/types/functions/type_utils/src/list_utils.js +0 -83
- package/dist/types/functions/type_utils/src/mime_utils.js +0 -314
- package/dist/types/functions/type_utils/src/null_utils.js +0 -21
- package/dist/types/functions/type_utils/src/type_utils.js +0 -39
- package/dist/types/functions/variable_utils/imports.js +0 -1
- package/dist/types/functions/variable_utils/index.js +0 -1
- package/dist/types/functions/variable_utils/src/index.js +0 -1
- package/dist/types/functions/variable_utils/src/variable_utils.js +0 -34
- package/dist/types/index.js +0 -2
- package/dist/types/server/index.js +0 -2
- package/dist/types/server/src/index.js +0 -2
- package/dist/types/server/src/mime_utils.js +0 -314
- package/dist/types/types/index.js +0 -1
- package/dist/types/types/path-browserify.js +0 -1
- package/dist/types/types/src/Files.js +0 -1
- package/dist/types/types/src/index.js +0 -4
- package/dist/types/types/src/login.js +0 -1
- package/dist/types/types/src/logout.js +0 -1
- package/dist/types/types/src/utils.js +0 -1
- package/dist/types/utils/imports.js +0 -1
- package/dist/types/utils/index.js +0 -1
- package/dist/types/utils/src/Input.js +0 -2
- package/dist/types/utils/src/config.js +0 -27
- package/dist/types/utils/src/index.js +0 -2
|
@@ -1,86 +0,0 @@
|
|
|
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,102 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
export { inspect } from "util";
|
|
@@ -1,28 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
export * from './caller_utils';
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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,129 +0,0 @@
|
|
|
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";
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ensure_number } from './../type_utils';
|
|
2
|
-
// take N args and coerce them all to numbers
|
|
3
|
-
export function safeNums(...args) {
|
|
4
|
-
return args.map(ensure_number);
|
|
5
|
-
}
|
|
6
|
-
// divide the first value by each of the following
|
|
7
|
-
export function safeDivide(...args) {
|
|
8
|
-
const [head, ...rest] = safeNums(...args);
|
|
9
|
-
// if we don’t have a head or any divisor is zero, bail
|
|
10
|
-
if (head === 0 || rest.some((d) => d === 0))
|
|
11
|
-
return 0;
|
|
12
|
-
return rest.reduce((acc, d) => acc / d, head);
|
|
13
|
-
}
|
|
14
|
-
// multiply all the values together
|
|
15
|
-
export function safeMultiply(...args) {
|
|
16
|
-
const nums = safeNums(...args);
|
|
17
|
-
// if any number is zero, result is zero
|
|
18
|
-
if (nums.includes(0))
|
|
19
|
-
return 0;
|
|
20
|
-
return nums.reduce((acc, n) => acc * n, 1);
|
|
21
|
-
}
|
|
22
|
-
// round a value to two decimals by percent
|
|
23
|
-
export function roundPercentage(x) {
|
|
24
|
-
const pct = safeMultiply(ensure_number(x), 100);
|
|
25
|
-
return safeDivide(Math.round(pct), 100);
|
|
26
|
-
}
|
|
27
|
-
export function exponential(i, k) {
|
|
28
|
-
return i * (10 ** (k));
|
|
29
|
-
}
|
|
30
|
-
export function isZero(obj) {
|
|
31
|
-
if (obj == 0) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In the browser we already have a WHATWG URL constructor on window.
|
|
3
|
-
* Here we re-export it as “url” so other modules can import it.
|
|
4
|
-
*/
|
|
5
|
-
const _url = typeof window !== 'undefined' ? window.URL : undefined;
|
|
6
|
-
export { _url as url };
|
|
7
|
-
/**
|
|
8
|
-
* Minimal fileURLToPath implementation for browser-side code.
|
|
9
|
-
* If you only ever need to strip off “file://” in development, this is enough.
|
|
10
|
-
*/
|
|
11
|
-
export function fileURLToPath(fileUrl) {
|
|
12
|
-
// e.g. fileUrl = "file:///Users/foo/bar.txt"
|
|
13
|
-
try {
|
|
14
|
-
const u = new URL(fileUrl);
|
|
15
|
-
return u.pathname;
|
|
16
|
-
}
|
|
17
|
-
catch (_a) {
|
|
18
|
-
// fallback: just strip file://
|
|
19
|
-
return fileUrl.replace(/^file:\/\//, '');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export { eatOuter, eatInner } from './../string_utils';
|
|
23
|
-
export { ensure_list } from './../type_utils';
|
|
24
|
-
export function getAbsolutePath() {
|
|
25
|
-
return fileURLToPath(import.meta.url);
|
|
26
|
-
}
|
|
27
|
-
;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { make_path, get_dirname } from './path_utils';
|
|
2
|
-
import { getSrcDir } from './src_dirs';
|
|
3
|
-
export function getBaseDir() {
|
|
4
|
-
return get_dirname(getSrcDir());
|
|
5
|
-
}
|
|
6
|
-
export function getPublicDir() {
|
|
7
|
-
return make_path(getBaseDir(), 'public');
|
|
8
|
-
}
|
|
9
|
-
;
|
|
10
|
-
export function getDistDir() {
|
|
11
|
-
return make_path(getBaseDir(), 'dist');
|
|
12
|
-
}
|
|
13
|
-
;
|
|
14
|
-
export function getEnvDir() {
|
|
15
|
-
return make_path(getBaseDir(), '.env');
|
|
16
|
-
}
|
|
17
|
-
;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { make_path, get_dirname } from './path_utils';
|
|
2
|
-
import { getAbsDir } from './paths';
|
|
3
|
-
export function getFunctionsDir() {
|
|
4
|
-
return get_dirname(getAbsDir());
|
|
5
|
-
}
|
|
6
|
-
;
|
|
7
|
-
export function geAuthsUtilsDirectory() {
|
|
8
|
-
return make_path(getFunctionsDir(), 'auths');
|
|
9
|
-
}
|
|
10
|
-
;
|
|
11
|
-
export function geBackupsUtilsDirectory() {
|
|
12
|
-
return make_path(getFunctionsDir(), 'backups');
|
|
13
|
-
}
|
|
14
|
-
;
|
|
15
|
-
export function geConstantsUtilsDirectory() {
|
|
16
|
-
return make_path(getFunctionsDir(), 'constants');
|
|
17
|
-
}
|
|
18
|
-
;
|
|
19
|
-
export function geEnvUtilsDirectory() {
|
|
20
|
-
return make_path(getFunctionsDir(), 'env_utils');
|
|
21
|
-
}
|
|
22
|
-
;
|
|
23
|
-
export function geFetchUtilsDirectory() {
|
|
24
|
-
return make_path(getFunctionsDir(), 'fetch_utils');
|
|
25
|
-
}
|
|
26
|
-
;
|
|
27
|
-
export function geFileUtilsDirectory() {
|
|
28
|
-
return make_path(getFunctionsDir(), 'file_utils');
|
|
29
|
-
}
|
|
30
|
-
;
|
|
31
|
-
export function gePathUtilsDirectory() {
|
|
32
|
-
return make_path(getFunctionsDir(), 'path_utils');
|
|
33
|
-
}
|
|
34
|
-
;
|
|
35
|
-
export function geStringUtilsDirectory() {
|
|
36
|
-
return make_path(getFunctionsDir(), 'string_utils');
|
|
37
|
-
}
|
|
38
|
-
;
|
|
39
|
-
export function geTypeUtilsDirectory() {
|
|
40
|
-
return make_path(getFunctionsDir(), 'type_utils');
|
|
41
|
-
}
|
|
42
|
-
;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getBaseDir, getEnvDir } from './base_dirs';
|
|
2
|
-
import { make_path } from './path_utils';
|
|
3
|
-
export function getEnvPath(string = '.env') {
|
|
4
|
-
return make_path(getEnvDir(), string);
|
|
5
|
-
}
|
|
6
|
-
;
|
|
7
|
-
export function getDbConfigsPath() {
|
|
8
|
-
return make_path(getBaseDir(), 'dbConfigs');
|
|
9
|
-
}
|
|
10
|
-
export function getSchemasPath() {
|
|
11
|
-
return make_path(getDbConfigsPath(), 'schemas');
|
|
12
|
-
}
|
|
13
|
-
export function getSchemasDirPath(subPath) {
|
|
14
|
-
return make_path(getSchemasPath(), subPath);
|
|
15
|
-
}
|