@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,186 +0,0 @@
|
|
|
1
|
-
import { assureString, ensure_list } from './../../type_utils';
|
|
2
|
-
export function getSubstring(obj, maxLength = null, minLength = null) {
|
|
3
|
-
const objLength = obj.length;
|
|
4
|
-
const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
|
|
5
|
-
const effectiveMinLength = minLength !== null && minLength !== void 0 ? minLength : 0;
|
|
6
|
-
// Ensure bounds are valid
|
|
7
|
-
const clampedMaxLength = Math.min(Math.max(effectiveMaxLength, 0), objLength);
|
|
8
|
-
const clampedMinLength = Math.min(Math.max(effectiveMinLength, 0), objLength);
|
|
9
|
-
// If minLength exceeds maxLength, return empty string or adjust logic as needed
|
|
10
|
-
if (clampedMinLength >= clampedMaxLength) {
|
|
11
|
-
return '';
|
|
12
|
-
}
|
|
13
|
-
return obj.substring(clampedMinLength, clampedMaxLength);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Sanitize a string by removing null bytes and trimming whitespace.
|
|
17
|
-
*/
|
|
18
|
-
export function sanitizeString(input) {
|
|
19
|
-
if (!input)
|
|
20
|
-
return input;
|
|
21
|
-
return input.replace(/\u0000/g, "").trim(); // Remove null bytes and whitespace
|
|
22
|
-
}
|
|
23
|
-
export function truncateString(obj, maxLength = 20) {
|
|
24
|
-
const objLength = obj.length;
|
|
25
|
-
if (objLength > maxLength && maxLength) {
|
|
26
|
-
obj = getSubstring(obj, maxLength) + '...';
|
|
27
|
-
}
|
|
28
|
-
return obj;
|
|
29
|
-
}
|
|
30
|
-
export function capitalize_str(string) {
|
|
31
|
-
string = assureString(string);
|
|
32
|
-
const string_len = string.length;
|
|
33
|
-
let init_char = string.toUpperCase();
|
|
34
|
-
if (string_len > 0) {
|
|
35
|
-
init_char = string[0].toUpperCase();
|
|
36
|
-
}
|
|
37
|
-
let rest_chars = '';
|
|
38
|
-
if (string_len > 1) {
|
|
39
|
-
rest_chars = string.slice(1).toLowerCase();
|
|
40
|
-
}
|
|
41
|
-
const fin_chars = `${init_char}${rest_chars}`;
|
|
42
|
-
return fin_chars;
|
|
43
|
-
}
|
|
44
|
-
export function capitalize(string) {
|
|
45
|
-
let nu_string = '';
|
|
46
|
-
string = assureString(string);
|
|
47
|
-
const objs = string.replace('-', '_').split('_');
|
|
48
|
-
for (const obj of objs) {
|
|
49
|
-
const str_obj = capitalize_str(obj);
|
|
50
|
-
nu_string = `${nu_string} ${str_obj}`;
|
|
51
|
-
}
|
|
52
|
-
return eatAll(nu_string, [' ']);
|
|
53
|
-
}
|
|
54
|
-
// string_utils/src/string_utils.ts
|
|
55
|
-
export function stripPrefixes(str, bases = []) {
|
|
56
|
-
/* NEW: coerce whatever arrives into a string */
|
|
57
|
-
str = String(str);
|
|
58
|
-
const prefixes = (Array.isArray(bases) ? bases : [bases])
|
|
59
|
-
.filter(Boolean)
|
|
60
|
-
.sort((a, b) => b.length - a.length); // longest first
|
|
61
|
-
let changed = true;
|
|
62
|
-
while (changed) {
|
|
63
|
-
changed = false;
|
|
64
|
-
for (const prefix of prefixes) {
|
|
65
|
-
if (str.startsWith(prefix)) {
|
|
66
|
-
str = str.slice(prefix.length);
|
|
67
|
-
changed = true;
|
|
68
|
-
break; // restart from longest prefix
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return str;
|
|
73
|
-
}
|
|
74
|
-
export function tryEatPrefix(str, length, ...objs) {
|
|
75
|
-
str = String(str);
|
|
76
|
-
objs = ensure_list(objs);
|
|
77
|
-
const prefix = str.slice(0, length);
|
|
78
|
-
if (length < 0) {
|
|
79
|
-
const start = str.length + length;
|
|
80
|
-
const actualPrefix = str.slice(start);
|
|
81
|
-
return objs.includes(actualPrefix) ? [str.slice(0, start), true] : [str, false];
|
|
82
|
-
}
|
|
83
|
-
if (objs.includes(prefix)) {
|
|
84
|
-
return [str.slice(length), true];
|
|
85
|
-
}
|
|
86
|
-
return [str, false];
|
|
87
|
-
}
|
|
88
|
-
/** Python-equivalent eatInner */
|
|
89
|
-
export function eatInner(str, listObjects) {
|
|
90
|
-
str = String(str);
|
|
91
|
-
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
92
|
-
// Keep removing from left while leftmost char is in the set
|
|
93
|
-
while (str.length > 0 && chars.includes(str[0])) {
|
|
94
|
-
str = str.slice(1);
|
|
95
|
-
}
|
|
96
|
-
return str;
|
|
97
|
-
}
|
|
98
|
-
/** Python-equivalent eatOuter */
|
|
99
|
-
export function eatOuter(str, listObjects) {
|
|
100
|
-
str = String(str);
|
|
101
|
-
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
102
|
-
if (!str || chars.length === 0)
|
|
103
|
-
return str;
|
|
104
|
-
for (let i = 0; i < str.length; i++) {
|
|
105
|
-
if (!str)
|
|
106
|
-
return str;
|
|
107
|
-
const last = str[str.length - 1];
|
|
108
|
-
if (!chars.includes(last)) {
|
|
109
|
-
return str;
|
|
110
|
-
}
|
|
111
|
-
str = str.slice(0, -1);
|
|
112
|
-
}
|
|
113
|
-
return str;
|
|
114
|
-
}
|
|
115
|
-
/** Python-equivalent eatAll */
|
|
116
|
-
export function eatAll(str, listObjects) {
|
|
117
|
-
str = String(str);
|
|
118
|
-
const chars = Array.isArray(listObjects) ? listObjects : [listObjects];
|
|
119
|
-
str = eatInner(str, chars);
|
|
120
|
-
str = eatOuter(str, chars);
|
|
121
|
-
return str;
|
|
122
|
-
}
|
|
123
|
-
// Plug in the actual version from your project
|
|
124
|
-
function get_alpha_ints(opts) {
|
|
125
|
-
// REPLACE WITH YOUR REAL IMPLEMENTATION
|
|
126
|
-
return [];
|
|
127
|
-
}
|
|
128
|
-
/** Python-equivalent eatElse */
|
|
129
|
-
export function eatElse(stringObj, chars, ints = true, alpha = true, lower = true, capitalize = true, string = true, listObj = true) {
|
|
130
|
-
stringObj = String(stringObj);
|
|
131
|
-
const alphaInts = get_alpha_ints({
|
|
132
|
-
ints,
|
|
133
|
-
alpha,
|
|
134
|
-
lower,
|
|
135
|
-
capitalize,
|
|
136
|
-
string,
|
|
137
|
-
listObj,
|
|
138
|
-
});
|
|
139
|
-
const ls = ensure_list(chars || []).concat(alphaInts);
|
|
140
|
-
while (true) {
|
|
141
|
-
if (!stringObj)
|
|
142
|
-
return stringObj;
|
|
143
|
-
const startOk = !ls.includes(stringObj[0]);
|
|
144
|
-
const endOk = !ls.includes(stringObj[stringObj.length - 1]);
|
|
145
|
-
const shouldEat = startOk || endOk;
|
|
146
|
-
if (!shouldEat)
|
|
147
|
-
return stringObj;
|
|
148
|
-
if (stringObj && startOk) {
|
|
149
|
-
stringObj = stringObj.length === 1 ? "" : stringObj.slice(1);
|
|
150
|
-
}
|
|
151
|
-
if (stringObj && endOk) {
|
|
152
|
-
stringObj = stringObj.length === 1 ? "" : stringObj.slice(0, -1);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
export function tryParse(obj) {
|
|
157
|
-
try {
|
|
158
|
-
obj = JSON.stringify(obj);
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
try {
|
|
162
|
-
obj = JSON.parse(obj);
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return obj;
|
|
168
|
-
}
|
|
169
|
-
export function create_list_string(array_obj) {
|
|
170
|
-
let string = '';
|
|
171
|
-
for (const obj in array_obj) {
|
|
172
|
-
const array_value = array_obj[obj];
|
|
173
|
-
const parsed_value = tryParse(array_value);
|
|
174
|
-
string += `${obj} == ${parsed_value}\n`;
|
|
175
|
-
}
|
|
176
|
-
return string;
|
|
177
|
-
}
|
|
178
|
-
export function eatall(str, listObjects) {
|
|
179
|
-
return eatAll(str, listObjects);
|
|
180
|
-
}
|
|
181
|
-
export function eatinner(str, listObjects) {
|
|
182
|
-
return eatInner(str, listObjects);
|
|
183
|
-
}
|
|
184
|
-
export function eatouter(str, listObjects) {
|
|
185
|
-
return eatOuter(str, listObjects);
|
|
186
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ensure_string, ensure_array } from './ensure_utils';
|
|
2
|
-
export function cleanText(input) {
|
|
3
|
-
// Replace delimiters with spaces and split
|
|
4
|
-
const str = ensure_string(input);
|
|
5
|
-
const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
|
|
6
|
-
return words;
|
|
7
|
-
}
|
|
8
|
-
export function cleanArray(obj) {
|
|
9
|
-
obj = ensure_array(obj);
|
|
10
|
-
return Array.from(new Set(obj));
|
|
11
|
-
}
|
|
12
|
-
export function getCleanArray(obj) {
|
|
13
|
-
obj = obj.split(/\s+/) // Split on any whitespace
|
|
14
|
-
.filter((item) => typeof item === 'string' && item !== '');
|
|
15
|
-
// Get basename
|
|
16
|
-
// Remove duplicates using Set
|
|
17
|
-
const uniqueWords = cleanArray(obj);
|
|
18
|
-
return uniqueWords;
|
|
19
|
-
}
|
|
20
|
-
// Cache a formatter instance for slightly better performance
|
|
21
|
-
const US_DECIMAL_FORMATTER = new Intl.NumberFormat('en-US', {
|
|
22
|
-
minimumFractionDigits: 2,
|
|
23
|
-
maximumFractionDigits: 2,
|
|
24
|
-
});
|
|
25
|
-
export function formatNumber(value) {
|
|
26
|
-
try {
|
|
27
|
-
// coerce to number
|
|
28
|
-
const num = Number(value);
|
|
29
|
-
// if it's NaN or infinite, bail out
|
|
30
|
-
if (!isFinite(num))
|
|
31
|
-
return value;
|
|
32
|
-
return US_DECIMAL_FORMATTER.format(num);
|
|
33
|
-
}
|
|
34
|
-
catch (_a) {
|
|
35
|
-
// if anything goes wrong, return the original
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { parse_nested_list, split_outside_brackets } from './list_utils';
|
|
2
|
-
export function ensure_list(obj) {
|
|
3
|
-
if (obj == null)
|
|
4
|
-
return [];
|
|
5
|
-
if (Array.isArray(obj)) {
|
|
6
|
-
return obj.flatMap(item => ensure_list(item));
|
|
7
|
-
}
|
|
8
|
-
const s = String(obj).trim();
|
|
9
|
-
if (s.startsWith("[") && s.endsWith("]")) {
|
|
10
|
-
return parse_nested_list(s);
|
|
11
|
-
}
|
|
12
|
-
return split_outside_brackets(s).map(x => x.trim());
|
|
13
|
-
}
|
|
14
|
-
// coerce any single value into a number (0 if it can't)
|
|
15
|
-
export function ensure_number(x) {
|
|
16
|
-
const n = Number(x);
|
|
17
|
-
return isNaN(n) ? 0 : n;
|
|
18
|
-
}
|
|
19
|
-
export function ensure_string(obj) {
|
|
20
|
-
return String(obj);
|
|
21
|
-
}
|
|
22
|
-
export function ensurelist(obj) {
|
|
23
|
-
return ensure_list(obj);
|
|
24
|
-
}
|
|
25
|
-
export function assureList(obj) {
|
|
26
|
-
return ensure_list(obj);
|
|
27
|
-
}
|
|
28
|
-
export function assure_list(obj) {
|
|
29
|
-
return ensure_list(obj);
|
|
30
|
-
}
|
|
31
|
-
export function ensureList(obj) {
|
|
32
|
-
return ensure_list(obj);
|
|
33
|
-
}
|
|
34
|
-
export function assurelist(obj) {
|
|
35
|
-
return ensure_list(obj);
|
|
36
|
-
}
|
|
37
|
-
export function ensurenumber(x) {
|
|
38
|
-
return ensure_number(x);
|
|
39
|
-
}
|
|
40
|
-
export function assureNumber(x) {
|
|
41
|
-
return ensure_number(x);
|
|
42
|
-
}
|
|
43
|
-
export function ensureNumber(x) {
|
|
44
|
-
return ensure_number(x);
|
|
45
|
-
}
|
|
46
|
-
export function assurenumber(x) {
|
|
47
|
-
return ensure_number(x);
|
|
48
|
-
}
|
|
49
|
-
export function assure_number(x) {
|
|
50
|
-
return ensure_number(x);
|
|
51
|
-
}
|
|
52
|
-
export function ensurestring(obj) {
|
|
53
|
-
return ensure_string(obj);
|
|
54
|
-
}
|
|
55
|
-
export function ensureString(obj) {
|
|
56
|
-
return ensure_string(obj);
|
|
57
|
-
}
|
|
58
|
-
export function assureString(obj) {
|
|
59
|
-
return ensure_string(obj);
|
|
60
|
-
}
|
|
61
|
-
export function assurestring(obj) {
|
|
62
|
-
return ensure_string(obj);
|
|
63
|
-
}
|
|
64
|
-
export function assure_string(obj) {
|
|
65
|
-
return ensure_string(obj);
|
|
66
|
-
}
|
|
67
|
-
export function assurearray(obj) {
|
|
68
|
-
return ensure_list(obj);
|
|
69
|
-
}
|
|
70
|
-
export function ensurearray(obj) {
|
|
71
|
-
return ensure_list(obj);
|
|
72
|
-
}
|
|
73
|
-
export function ensure_array(obj) {
|
|
74
|
-
return ensure_list(obj);
|
|
75
|
-
}
|
|
76
|
-
export function ensureArray(obj) {
|
|
77
|
-
return ensure_list(obj);
|
|
78
|
-
}
|
|
79
|
-
export function assure_array(obj) {
|
|
80
|
-
return ensure_list(obj);
|
|
81
|
-
}
|
|
82
|
-
export function assureArray(obj) {
|
|
83
|
-
return ensure_list(obj);
|
|
84
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { ensure_array } from './ensure_utils';
|
|
13
|
-
// Constrain T so 'in obj' is allowed
|
|
14
|
-
export function get_key_value(obj, key) {
|
|
15
|
-
// we cast to any for the indexing, since TS can’t infer arbitrary string keys
|
|
16
|
-
if (key in obj && obj[key] != null) {
|
|
17
|
-
return obj[key];
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
export function get(obj, keys, defaultValue = null) {
|
|
22
|
-
const keyArray = ensure_array(keys);
|
|
23
|
-
if (!obj || keyArray.length === 0) {
|
|
24
|
-
return defaultValue;
|
|
25
|
-
}
|
|
26
|
-
for (const key of keyArray) {
|
|
27
|
-
const val = get_key_value(obj, key);
|
|
28
|
-
if (val != null) {
|
|
29
|
-
return val;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return defaultValue;
|
|
33
|
-
}
|
|
34
|
-
// Create the accountInfo table if it doesn't already exist
|
|
35
|
-
export function findKeyValue(obj, keyToFind) {
|
|
36
|
-
if (keyToFind in obj)
|
|
37
|
-
return obj[keyToFind];
|
|
38
|
-
for (const key in obj) {
|
|
39
|
-
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
40
|
-
const result = findKeyValue(obj[key], keyToFind);
|
|
41
|
-
if (result !== undefined)
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
export function omitKeys(obj, ...keys) {
|
|
48
|
-
const newObj = Object.assign({}, obj);
|
|
49
|
-
keys.forEach(key => {
|
|
50
|
-
delete newObj[key];
|
|
51
|
-
});
|
|
52
|
-
return newObj;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Extracts necessary properties from the insertValue to prevent circular references.
|
|
56
|
-
*
|
|
57
|
-
* @param insertValue - The original RPC result.
|
|
58
|
-
* @returns A new object with only the required properties.
|
|
59
|
-
*/
|
|
60
|
-
export function extractInsertData(insertValue) {
|
|
61
|
-
// Example: Suppose you only need certain fields from the transaction
|
|
62
|
-
// Modify this function based on your actual data structure
|
|
63
|
-
if (insertValue && typeof insertValue === 'object') {
|
|
64
|
-
const { transaction } = insertValue, rest = __rest(insertValue, ["transaction"]); // Exclude 'transaction' property
|
|
65
|
-
return rest;
|
|
66
|
-
}
|
|
67
|
-
return insertValue;
|
|
68
|
-
}
|
|
69
|
-
// Recursive function to load nested JSON
|
|
70
|
-
export function loadInnerJson(data) {
|
|
71
|
-
if (typeof data === 'string') {
|
|
72
|
-
try {
|
|
73
|
-
const parsed = JSON.parse(data);
|
|
74
|
-
return loadInnerJson(parsed);
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
return data;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else if (Array.isArray(data)) {
|
|
81
|
-
return data.map(item => loadInnerJson(item));
|
|
82
|
-
}
|
|
83
|
-
else if (typeof data === 'object' && data !== null) {
|
|
84
|
-
const result = {};
|
|
85
|
-
for (const key in data) {
|
|
86
|
-
if (data.hasOwnProperty(key)) {
|
|
87
|
-
result[key] = loadInnerJson(data[key]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
return data;
|
|
93
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
export function smart_split(s) {
|
|
2
|
-
const out = [];
|
|
3
|
-
let depth = 0;
|
|
4
|
-
let buf = "";
|
|
5
|
-
for (let i = 0; i < s.length; i++) {
|
|
6
|
-
const c = s[i];
|
|
7
|
-
if (c === "[") {
|
|
8
|
-
depth++;
|
|
9
|
-
buf += c;
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
if (c === "]") {
|
|
13
|
-
depth--;
|
|
14
|
-
buf += c;
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
// Split ONLY when depth === 0
|
|
18
|
-
if (c === "," && depth === 0) {
|
|
19
|
-
out.push(buf);
|
|
20
|
-
buf = "";
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
buf += c;
|
|
24
|
-
}
|
|
25
|
-
if (buf.length > 0)
|
|
26
|
-
out.push(buf);
|
|
27
|
-
return out;
|
|
28
|
-
}
|
|
29
|
-
export function split_outside_brackets(s) {
|
|
30
|
-
let depth = 0;
|
|
31
|
-
let start = 0;
|
|
32
|
-
const out = [];
|
|
33
|
-
for (let i = 0; i < s.length; i++) {
|
|
34
|
-
const c = s[i];
|
|
35
|
-
if (c === "[")
|
|
36
|
-
depth++;
|
|
37
|
-
else if (c === "]")
|
|
38
|
-
depth--;
|
|
39
|
-
// split only when NOT inside brackets
|
|
40
|
-
if (c === "," && depth === 0) {
|
|
41
|
-
out.push(s.slice(start, i));
|
|
42
|
-
start = i + 1;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
out.push(s.slice(start));
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
48
|
-
export function smart_split_preserving_lists(s) {
|
|
49
|
-
let depth = 0;
|
|
50
|
-
let start = 0;
|
|
51
|
-
const parts = [];
|
|
52
|
-
for (let i = 0; i < s.length; i++) {
|
|
53
|
-
const c = s[i];
|
|
54
|
-
if (c === "[")
|
|
55
|
-
depth++;
|
|
56
|
-
else if (c === "]")
|
|
57
|
-
depth--;
|
|
58
|
-
// Split ONLY when depth == 0 AND a comma appears
|
|
59
|
-
if (c === "," && depth === 0) {
|
|
60
|
-
parts.push(s.slice(start, i));
|
|
61
|
-
start = i + 1;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
parts.push(s.slice(start));
|
|
65
|
-
return parts;
|
|
66
|
-
}
|
|
67
|
-
export function parse_nested_list(s) {
|
|
68
|
-
// strip outer brackets
|
|
69
|
-
const inner = s.slice(1, -1).trim();
|
|
70
|
-
const parts = split_outside_brackets(inner);
|
|
71
|
-
const result = [];
|
|
72
|
-
for (let p of parts) {
|
|
73
|
-
p = p.trim();
|
|
74
|
-
if (p.startsWith("[") && p.endsWith("]")) {
|
|
75
|
-
// recursively parse nested list
|
|
76
|
-
result.push(parse_nested_list(p));
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
result.push(p);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
}
|