@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.
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/print_utils-DzyRoj6m.js.map +1 -1
- package/dist/cjs/safe_storage-CJgWghnh.js.map +1 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/print_utils-qqcMhSul.js.map +1 -1
- package/dist/esm/safe_storage-CMuv35Vo.js.map +1 -1
- package/dist/types/client/auth/index.d.ts +1 -1
- package/dist/types/client/auth/index.js +3 -0
- package/dist/types/client/auth/src/index.d.ts +1 -1
- package/dist/types/client/auth/src/index.js +3 -0
- package/dist/types/client/auth/src/token_client.js +73 -0
- package/dist/types/client/fetch/src/fetch_auth.d.ts +1 -1
- package/dist/types/client/fetch/src/fetch_auth.js +26 -0
- package/dist/types/client/fetch/src/index.d.ts +1 -1
- package/dist/types/client/fetch/src/index.js +2 -0
- package/dist/types/client/index.d.ts +2 -2
- package/dist/types/client/index.js +4 -0
- package/dist/types/client/ui_utils/index.d.ts +1 -1
- package/dist/types/client/ui_utils/index.js +2 -0
- package/dist/types/client/ui_utils/src/button.js +34 -0
- package/dist/types/client/ui_utils/src/checkbox.js +18 -0
- package/dist/types/client/ui_utils/src/index.d.ts +4 -4
- package/dist/types/client/ui_utils/src/index.js +4 -0
- package/dist/types/client/ui_utils/src/input.js +18 -0
- package/dist/types/client/ui_utils/src/spinner.js +5 -0
- package/dist/types/functions/auth_utils/imports.d.ts +2 -2
- package/dist/types/functions/auth_utils/imports.js +1 -0
- package/dist/types/functions/auth_utils/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/index.js +1 -0
- package/dist/types/functions/auth_utils/src/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/index.js +1 -0
- package/dist/types/functions/auth_utils/src/jwt_core.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/jwt_core.js +25 -0
- package/dist/types/functions/auth_utils/src/token_utils (Copy).d.ts +1 -1
- package/dist/types/functions/auth_utils/src/token_utils (Copy).js +25 -0
- package/dist/types/functions/auth_utils/src/token_utils.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/token_utils.js +105 -0
- package/dist/types/functions/config_utils/imports.d.ts +3 -3
- package/dist/types/functions/config_utils/imports.js +2 -0
- package/dist/types/functions/config_utils/index.d.ts +1 -1
- package/dist/types/functions/config_utils/index.js +1 -0
- package/dist/types/functions/config_utils/src/config_utils.d.ts +1 -1
- package/dist/types/functions/config_utils/src/config_utils.js +83 -0
- package/dist/types/functions/config_utils/src/index.d.ts +1 -1
- package/dist/types/functions/config_utils/src/index.js +1 -0
- package/dist/types/functions/constants_utils/index.d.ts +1 -1
- package/dist/types/functions/constants_utils/index.js +1 -0
- package/dist/types/functions/constants_utils/src/constants.js +7 -0
- package/dist/types/functions/constants_utils/src/index.d.ts +1 -1
- package/dist/types/functions/constants_utils/src/index.js +1 -0
- package/dist/types/functions/env_utils/imports.d.ts +1 -1
- package/dist/types/functions/env_utils/imports.js +1 -0
- package/dist/types/functions/env_utils/index.d.ts +1 -1
- package/dist/types/functions/env_utils/index.js +1 -0
- package/dist/types/functions/env_utils/src/index.d.ts +1 -1
- package/dist/types/functions/env_utils/src/index.js +1 -0
- package/dist/types/functions/env_utils/src/window_utils.js +47 -0
- package/dist/types/functions/fetch_utils/imports.d.ts +2 -2
- package/dist/types/functions/fetch_utils/imports.js +1 -0
- package/dist/types/functions/fetch_utils/index.d.ts +1 -1
- package/dist/types/functions/fetch_utils/index.js +1 -0
- package/dist/types/functions/fetch_utils/src/fetch_utils.js +70 -0
- package/dist/types/functions/fetch_utils/src/index.d.ts +3 -3
- package/dist/types/functions/fetch_utils/src/index.js +3 -0
- package/dist/types/functions/fetch_utils/src/url_utils.js +86 -0
- package/dist/types/functions/fetch_utils/src/utils.d.ts +1 -1
- package/dist/types/functions/fetch_utils/src/utils.js +102 -0
- package/dist/types/functions/index.d.ts +17 -17
- package/dist/types/functions/index.js +17 -0
- package/dist/types/functions/inspect_utils/imports.js +1 -0
- package/dist/types/functions/inspect_utils/index.d.ts +2 -2
- package/dist/types/functions/inspect_utils/index.js +2 -0
- package/dist/types/functions/inspect_utils/src/caller_utils.js +28 -0
- package/dist/types/functions/inspect_utils/src/index.d.ts +1 -1
- package/dist/types/functions/inspect_utils/src/index.js +1 -0
- package/dist/types/functions/math_utils/bigint_utils.js +36 -0
- package/dist/types/functions/math_utils/constants.js +37 -0
- package/dist/types/functions/math_utils/conversions.d.ts +1 -1
- package/dist/types/functions/math_utils/conversions.js +129 -0
- package/dist/types/functions/math_utils/index.d.ts +6 -6
- package/dist/types/functions/math_utils/index.js +6 -0
- package/dist/types/functions/math_utils/safe_math.js +35 -0
- package/dist/types/functions/math_utils/scaleInterfaces.js +3 -0
- package/dist/types/functions/math_utils/time_utils.js +4 -0
- package/dist/types/functions/path_utils/imports.d.ts +2 -2
- package/dist/types/functions/path_utils/imports.js +27 -0
- package/dist/types/functions/path_utils/index.d.ts +1 -1
- package/dist/types/functions/path_utils/index.js +1 -0
- package/dist/types/functions/path_utils/src/base_dirs.js +17 -0
- package/dist/types/functions/path_utils/src/function_dirs.js +42 -0
- package/dist/types/functions/path_utils/src/index.d.ts +6 -6
- package/dist/types/functions/path_utils/src/index.js +6 -0
- package/dist/types/functions/path_utils/src/misc_dirs.js +15 -0
- package/dist/types/functions/path_utils/src/path_utils.js +160 -0
- package/dist/types/functions/path_utils/src/paths.js +12 -0
- package/dist/types/functions/path_utils/src/src_dirs.js +25 -0
- package/dist/types/functions/print_utils/imports.d.ts +1 -1
- package/dist/types/functions/print_utils/imports.js +1 -0
- package/dist/types/functions/print_utils/index.d.ts +1 -1
- package/dist/types/functions/print_utils/index.js +1 -0
- package/dist/types/functions/print_utils/src/index.d.ts +1 -1
- package/dist/types/functions/print_utils/src/index.js +1 -0
- package/dist/types/functions/print_utils/src/print_utils.js +14 -0
- package/dist/types/functions/read_utils/imports.d.ts +1 -1
- package/dist/types/functions/read_utils/imports.js +1 -0
- package/dist/types/functions/read_utils/index.d.ts +1 -1
- package/dist/types/functions/read_utils/index.js +1 -0
- package/dist/types/functions/read_utils/src/index.d.ts +3 -3
- package/dist/types/functions/read_utils/src/index.js +3 -0
- package/dist/types/functions/read_utils/src/readJsonFile.browser.js +26 -0
- package/dist/types/functions/read_utils/src/readJsonFile.js +35 -0
- package/dist/types/functions/read_utils/src/readJsonFile.node.js +13 -0
- package/dist/types/functions/rndm_utils/imports.d.ts +1 -0
- package/dist/types/functions/rndm_utils/imports.js +1 -0
- package/dist/types/functions/rndm_utils/index.d.ts +1 -1
- package/dist/types/functions/rndm_utils/index.js +1 -0
- package/dist/types/functions/rndm_utils/src/index.d.ts +1 -1
- package/dist/types/functions/rndm_utils/src/index.js +1 -0
- package/dist/types/functions/rndm_utils/src/utils.js +12 -0
- package/dist/types/functions/safe_utils/imports.d.ts +1 -1
- package/dist/types/functions/safe_utils/imports.js +1 -0
- package/dist/types/functions/safe_utils/index.d.ts +1 -1
- package/dist/types/functions/safe_utils/index.js +1 -0
- package/dist/types/functions/safe_utils/src/index.d.ts +4 -4
- package/dist/types/functions/safe_utils/src/index.js +4 -0
- package/dist/types/functions/safe_utils/src/safe_document.js +12 -0
- package/dist/types/functions/safe_utils/src/safe_globals.js +14 -0
- package/dist/types/functions/safe_utils/src/safe_storage.js +50 -0
- package/dist/types/functions/safe_utils/src/safe_window.js +42 -0
- package/dist/types/functions/size_utils/index.d.ts +1 -1
- package/dist/types/functions/size_utils/index.js +1 -0
- package/dist/types/functions/size_utils/src/index.d.ts +1 -1
- package/dist/types/functions/size_utils/src/index.js +1 -0
- package/dist/types/functions/size_utils/src/sizeUtils.js +44 -0
- package/dist/types/functions/string_utils/index.d.ts +1 -1
- package/dist/types/functions/string_utils/index.js +1 -0
- package/dist/types/functions/string_utils/src/index.d.ts +2 -2
- package/dist/types/functions/string_utils/src/index.js +2 -0
- package/dist/types/functions/string_utils/src/quote_utils.js +17 -0
- package/dist/types/functions/string_utils/src/string_utils.js +186 -0
- package/dist/types/functions/type_utils/imports.d.ts +1 -0
- package/dist/types/functions/type_utils/imports.js +1 -0
- package/dist/types/functions/type_utils/index.d.ts +1 -1
- package/dist/types/functions/type_utils/index.js +1 -0
- package/dist/types/functions/type_utils/src/clean_utils.js +38 -0
- package/dist/types/functions/type_utils/src/ensure_utils.js +84 -0
- package/dist/types/functions/type_utils/src/imports.d.ts +1 -0
- package/dist/types/functions/type_utils/src/imports.js +1 -0
- package/dist/types/functions/type_utils/src/index.d.ts +6 -6
- package/dist/types/functions/type_utils/src/index.js +6 -0
- package/dist/types/functions/type_utils/src/json_utils.js +93 -0
- package/dist/types/functions/type_utils/src/list_utils.js +83 -0
- package/dist/types/functions/type_utils/src/mime_utils.js +314 -0
- package/dist/types/functions/type_utils/src/null_utils.js +21 -0
- package/dist/types/functions/type_utils/src/type_utils.js +39 -0
- package/dist/types/functions/variable_utils/imports.d.ts +1 -1
- package/dist/types/functions/variable_utils/imports.js +1 -0
- package/dist/types/functions/variable_utils/index.d.ts +1 -1
- package/dist/types/functions/variable_utils/index.js +1 -0
- package/dist/types/functions/variable_utils/src/index.d.ts +1 -1
- package/dist/types/functions/variable_utils/src/index.js +1 -0
- package/dist/types/functions/variable_utils/src/variable_utils.js +34 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +2 -0
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/server/index.js +2 -0
- package/dist/types/server/src/index.d.ts +1 -1
- package/dist/types/server/src/index.js +2 -0
- package/dist/types/server/src/mime_utils.js +314 -0
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.js +1 -0
- package/dist/types/types/path-browserify.d.ts +3 -2
- package/dist/types/types/path-browserify.js +1 -0
- package/dist/types/types/src/Files.js +1 -0
- package/dist/types/types/src/index.d.ts +4 -4
- package/dist/types/types/src/index.js +4 -0
- package/dist/types/types/src/login.js +1 -0
- package/dist/types/types/src/logout.js +1 -0
- package/dist/types/types/src/utils.js +1 -0
- package/dist/types/utils/imports.d.ts +1 -1
- package/dist/types/utils/imports.js +1 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.js +1 -0
- package/dist/types/utils/src/Input.js +2 -0
- package/dist/types/utils/src/config.js +27 -0
- package/dist/types/utils/src/index.d.ts +2 -2
- package/dist/types/utils/src/index.js +2 -0
- package/package.json +13 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
3
|
+
* Returns `undefined` if any step is missing.
|
|
4
|
+
*/
|
|
5
|
+
export function safeGlobalProp(...path) {
|
|
6
|
+
let obj = globalThis;
|
|
7
|
+
for (const key of path) {
|
|
8
|
+
if (obj == null || typeof obj !== "object" || !(key in obj)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
obj = obj[key];
|
|
12
|
+
}
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { safeGlobalProp } from './safe_globals';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `window` if running in a browser, otherwise `undefined`.
|
|
4
|
+
*/
|
|
5
|
+
export function getSafeLocalStorage() {
|
|
6
|
+
if (typeof window === 'undefined')
|
|
7
|
+
return undefined;
|
|
8
|
+
try {
|
|
9
|
+
return window.localStorage;
|
|
10
|
+
}
|
|
11
|
+
catch (_a) {
|
|
12
|
+
return undefined; // e.g. Safari private-mode block
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Call a Storage method by name, silencing any errors or missing storage.
|
|
17
|
+
*
|
|
18
|
+
* @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
|
|
19
|
+
* @param args The arguments you’d normally pass to that method.
|
|
20
|
+
* @returns The method’s return value, or undefined if storage/method isn’t available.
|
|
21
|
+
*/
|
|
22
|
+
export function callStorage(method, ...args) {
|
|
23
|
+
const storage = getSafeLocalStorage();
|
|
24
|
+
if (!storage)
|
|
25
|
+
return undefined;
|
|
26
|
+
const fn = storage[method];
|
|
27
|
+
if (typeof fn !== 'function')
|
|
28
|
+
return undefined;
|
|
29
|
+
try {
|
|
30
|
+
return fn.apply(storage, args);
|
|
31
|
+
}
|
|
32
|
+
catch (_a) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
|
|
38
|
+
* Returns `undefined` on any error.
|
|
39
|
+
*/
|
|
40
|
+
export function safeStorage(storageName, method, ...args) {
|
|
41
|
+
try {
|
|
42
|
+
const store = safeGlobalProp(storageName);
|
|
43
|
+
if (!store || typeof store[method] !== "function")
|
|
44
|
+
return undefined;
|
|
45
|
+
return store[method](...args);
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the global window object if it exists, otherwise undefined.
|
|
3
|
+
*/
|
|
4
|
+
export function getSafeWindow() {
|
|
5
|
+
return typeof window !== 'undefined' ? window : undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Safely call a method on window by name.
|
|
9
|
+
*
|
|
10
|
+
* @param method The Window method to call (e.g. "alert", "open", etc.).
|
|
11
|
+
* @param args Arguments to pass to that method.
|
|
12
|
+
* @returns The method’s return value, or undefined if
|
|
13
|
+
* window/method isn’t available or throws.
|
|
14
|
+
*/
|
|
15
|
+
export function callWindowMethod(method, ...args) {
|
|
16
|
+
const w = getSafeWindow();
|
|
17
|
+
if (!w)
|
|
18
|
+
return undefined;
|
|
19
|
+
const fn = w[method];
|
|
20
|
+
if (typeof fn !== 'function')
|
|
21
|
+
return undefined;
|
|
22
|
+
try {
|
|
23
|
+
// cast to any so TS doesn’t complain about apply/invoke
|
|
24
|
+
return fn(...args);
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** implementation */
|
|
31
|
+
export function getWindowProp(...keys) {
|
|
32
|
+
let obj = getSafeWindow();
|
|
33
|
+
for (const k of keys) {
|
|
34
|
+
if (obj == null || typeof obj !== 'object')
|
|
35
|
+
return undefined;
|
|
36
|
+
obj = obj[k];
|
|
37
|
+
}
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
export function getWindowHost() {
|
|
41
|
+
return getWindowProp('location', 'host');
|
|
42
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './sizeUtils';
|
|
1
|
+
export * from './sizeUtils.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sizeUtils';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Function to compare MB
|
|
2
|
+
export function exceedsMbLimit(limitMb, payloadMb) {
|
|
3
|
+
return payloadMb > limitMb;
|
|
4
|
+
}
|
|
5
|
+
export function safeJsonSizeInMb(value) {
|
|
6
|
+
const seen = new WeakSet();
|
|
7
|
+
const json = JSON.stringify(value, (_, v) => {
|
|
8
|
+
if (typeof v === "bigint")
|
|
9
|
+
return v.toString();
|
|
10
|
+
if (typeof v === "object" && v !== null) {
|
|
11
|
+
if (seen.has(v))
|
|
12
|
+
return "[Circular]";
|
|
13
|
+
seen.add(v);
|
|
14
|
+
}
|
|
15
|
+
return v;
|
|
16
|
+
});
|
|
17
|
+
return Buffer.byteLength(json, "utf8") / (1024 * 1024);
|
|
18
|
+
}
|
|
19
|
+
export function dataSizeInMb(data) {
|
|
20
|
+
const size = typeof data === "string"
|
|
21
|
+
? Buffer.byteLength(data, "utf8")
|
|
22
|
+
: Buffer.byteLength(JSON.stringify(data), "utf8");
|
|
23
|
+
return size / (1024 * 1024);
|
|
24
|
+
}
|
|
25
|
+
export function getJsonSizeInMb(json) {
|
|
26
|
+
return Buffer.byteLength(JSON.stringify(json), "utf8") / (1024 * 1024);
|
|
27
|
+
}
|
|
28
|
+
// Function to calculate data size in KB
|
|
29
|
+
export function dataSize(data) {
|
|
30
|
+
let size = 0;
|
|
31
|
+
if (typeof data === 'string') {
|
|
32
|
+
size = Buffer.byteLength(data, 'utf8');
|
|
33
|
+
}
|
|
34
|
+
else if (Buffer.isBuffer(data)) {
|
|
35
|
+
size = data.length;
|
|
36
|
+
}
|
|
37
|
+
else if (typeof data === 'object') {
|
|
38
|
+
size = Buffer.byteLength(JSON.stringify(data), 'utf8');
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
size = Buffer.byteLength(String(data), 'utf8');
|
|
42
|
+
}
|
|
43
|
+
return size / 1000; // Convert to kilobytes
|
|
44
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './string_utils';
|
|
2
|
-
export * from './quote_utils';
|
|
1
|
+
export * from './string_utils.js';
|
|
2
|
+
export * from './quote_utils.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a value is enclosed in quotes.
|
|
3
|
+
*/
|
|
4
|
+
export function ends_in_quotes(value) {
|
|
5
|
+
if (typeof value === 'string') {
|
|
6
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
export function stripQuotes(value) {
|
|
13
|
+
if (ends_in_quotes(value)) {
|
|
14
|
+
return value.slice(1, -1); // Remove the first and last characters
|
|
15
|
+
}
|
|
16
|
+
return value; // Return the input unchanged for all other cases
|
|
17
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './clean_utils';
|
|
2
|
-
export * from './ensure_utils';
|
|
3
|
-
export * from './json_utils';
|
|
4
|
-
export * from './type_utils';
|
|
5
|
-
export * from './mime_utils';
|
|
6
|
-
export * from './null_utils';
|
|
1
|
+
export * from './clean_utils.js';
|
|
2
|
+
export * from './ensure_utils.js';
|
|
3
|
+
export * from './json_utils.js';
|
|
4
|
+
export * from './type_utils.js';
|
|
5
|
+
export * from './mime_utils.js';
|
|
6
|
+
export * from './null_utils.js';
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
}
|