@putkoff/abstract-utilities 1.0.67 → 1.0.69
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/index.js +89 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +80 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +26 -1
- package/dist/types/functions/math_utils/index.d.ts +1 -0
- package/dist/types/functions/math_utils/safe_math.d.ts +1 -0
- package/dist/types/functions/math_utils/time_utils.d.ts +1 -0
- package/dist/types/functions/string_utils/src/index.d.ts +1 -0
- package/dist/types/functions/string_utils/src/quote_utils.d.ts +5 -0
- package/dist/types/functions/string_utils/src/string_utils.d.ts +4 -0
- package/dist/types/functions/type_utils/src/index.d.ts +1 -0
- package/dist/types/functions/type_utils/src/json_utils.d.ts +2 -0
- package/dist/types/functions/type_utils/src/null_utils.d.ts +9 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1061,6 +1061,26 @@ function get(obj, keys, defaultValue = null) {
|
|
|
1061
1061
|
}
|
|
1062
1062
|
return defaultValue;
|
|
1063
1063
|
}
|
|
1064
|
+
// Create the accountInfo table if it doesn't already exist
|
|
1065
|
+
function findKeyValue(obj, keyToFind) {
|
|
1066
|
+
if (keyToFind in obj)
|
|
1067
|
+
return obj[keyToFind];
|
|
1068
|
+
for (const key in obj) {
|
|
1069
|
+
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
1070
|
+
const result = findKeyValue(obj[key], keyToFind);
|
|
1071
|
+
if (result !== undefined)
|
|
1072
|
+
return result;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return undefined;
|
|
1076
|
+
}
|
|
1077
|
+
function omitKeys(obj, ...keys) {
|
|
1078
|
+
const newObj = Object.assign({}, obj);
|
|
1079
|
+
keys.forEach(key => {
|
|
1080
|
+
delete newObj[key];
|
|
1081
|
+
});
|
|
1082
|
+
return newObj;
|
|
1083
|
+
}
|
|
1064
1084
|
|
|
1065
1085
|
function isType(obj, type) {
|
|
1066
1086
|
if (typeof obj === type) {
|
|
@@ -1403,6 +1423,28 @@ const confirm_type = confirmType;
|
|
|
1403
1423
|
const is_media_type = isMediaType;
|
|
1404
1424
|
const get_mime_type = getMimeType;
|
|
1405
1425
|
|
|
1426
|
+
// Function to handle undefined or null values
|
|
1427
|
+
function getIfNone(obj, fallback) {
|
|
1428
|
+
return obj !== undefined && obj !== null && obj !== '' ? obj : fallback;
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Merges non-null values from multiple dictionaries.
|
|
1432
|
+
*/
|
|
1433
|
+
function mergeNotNullValues(dictA, dictB, dictC, dictD, dictE) {
|
|
1434
|
+
var _a, _b, _c, _d;
|
|
1435
|
+
const result = {};
|
|
1436
|
+
for (const key of Object.keys(dictA)) {
|
|
1437
|
+
result[key] = (_d = (_c = (_b = (_a = dictA[key]) !== null && _a !== void 0 ? _a : dictB === null || dictB === void 0 ? void 0 : dictB[key]) !== null && _b !== void 0 ? _b : dictC === null || dictC === void 0 ? void 0 : dictC[key]) !== null && _c !== void 0 ? _c : dictD === null || dictD === void 0 ? void 0 : dictD[key]) !== null && _d !== void 0 ? _d : dictE === null || dictE === void 0 ? void 0 : dictE[key];
|
|
1438
|
+
}
|
|
1439
|
+
return result;
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Converts an empty object to null.
|
|
1443
|
+
*/
|
|
1444
|
+
function emptyObjectToNull(value) {
|
|
1445
|
+
return value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0 ? null : value;
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1406
1448
|
function getSubstring(obj, maxLength = null, minLength = null) {
|
|
1407
1449
|
const objLength = obj.length;
|
|
1408
1450
|
const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
|
|
@@ -1416,6 +1458,14 @@ function getSubstring(obj, maxLength = null, minLength = null) {
|
|
|
1416
1458
|
}
|
|
1417
1459
|
return obj.substring(clampedMinLength, clampedMaxLength);
|
|
1418
1460
|
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Sanitize a string by removing null bytes and trimming whitespace.
|
|
1463
|
+
*/
|
|
1464
|
+
function sanitizeString(input) {
|
|
1465
|
+
if (!input)
|
|
1466
|
+
return input;
|
|
1467
|
+
return input.replace(/\u0000/g, "").trim(); // Remove null bytes and whitespace
|
|
1468
|
+
}
|
|
1419
1469
|
function truncateString(obj, maxLength = 20) {
|
|
1420
1470
|
const objLength = obj.length;
|
|
1421
1471
|
if (objLength > maxLength && maxLength) {
|
|
@@ -1574,6 +1624,24 @@ function eatouter(str, listObjects) {
|
|
|
1574
1624
|
return eatOuter(str, listObjects);
|
|
1575
1625
|
}
|
|
1576
1626
|
|
|
1627
|
+
/**
|
|
1628
|
+
* Checks if a value is enclosed in quotes.
|
|
1629
|
+
*/
|
|
1630
|
+
function ends_in_quotes(value) {
|
|
1631
|
+
if (typeof value === 'string') {
|
|
1632
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
1633
|
+
return true;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
return false;
|
|
1637
|
+
}
|
|
1638
|
+
function stripQuotes(value) {
|
|
1639
|
+
if (ends_in_quotes(value)) {
|
|
1640
|
+
return value.slice(1, -1); // Remove the first and last characters
|
|
1641
|
+
}
|
|
1642
|
+
return value; // Return the input unchanged for all other cases
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1577
1645
|
/**
|
|
1578
1646
|
* In the browser we already have a WHATWG URL constructor on window.
|
|
1579
1647
|
* Here we re-export it as “url” so other modules can import it.
|
|
@@ -1883,6 +1951,12 @@ function roundPercentage(x) {
|
|
|
1883
1951
|
function exponential(i, k) {
|
|
1884
1952
|
return i * (10 ** (k));
|
|
1885
1953
|
}
|
|
1954
|
+
function isZero(obj) {
|
|
1955
|
+
if (obj == 0) {
|
|
1956
|
+
return true;
|
|
1957
|
+
}
|
|
1958
|
+
return false;
|
|
1959
|
+
}
|
|
1886
1960
|
|
|
1887
1961
|
const SECOND = 1;
|
|
1888
1962
|
const ZEPTOSECOND = exponential(SECOND, -21);
|
|
@@ -2049,6 +2123,11 @@ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit)
|
|
|
2049
2123
|
const isFiniteNum = (x) => Number.isFinite(x);
|
|
2050
2124
|
const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
|
|
2051
2125
|
|
|
2126
|
+
// Function to check time interval
|
|
2127
|
+
function isTimeInterval(timeObj, interval) {
|
|
2128
|
+
return (Date.now() / 1000 - timeObj) < (interval - 1);
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2052
2131
|
function getSafeDocument() {
|
|
2053
2132
|
return typeof document !== 'undefined' ? document : undefined;
|
|
2054
2133
|
}
|
|
@@ -2458,6 +2537,8 @@ exports.eatOuter = eatOuter;
|
|
|
2458
2537
|
exports.eatall = eatall;
|
|
2459
2538
|
exports.eatinner = eatinner;
|
|
2460
2539
|
exports.eatouter = eatouter;
|
|
2540
|
+
exports.emptyObjectToNull = emptyObjectToNull;
|
|
2541
|
+
exports.ends_in_quotes = ends_in_quotes;
|
|
2461
2542
|
exports.ensureArray = ensureArray;
|
|
2462
2543
|
exports.ensureList = ensureList;
|
|
2463
2544
|
exports.ensureNumber = ensureNumber;
|
|
@@ -2474,6 +2555,7 @@ exports.exponential = exponential;
|
|
|
2474
2555
|
exports.fetchIndexHtml = fetchIndexHtml;
|
|
2475
2556
|
exports.fetchIndexHtmlContainer = fetchIndexHtmlContainer;
|
|
2476
2557
|
exports.fetchIt = fetchIt;
|
|
2558
|
+
exports.findKeyValue = findKeyValue;
|
|
2477
2559
|
exports.fmt = fmt;
|
|
2478
2560
|
exports.formatNumber = formatNumber;
|
|
2479
2561
|
exports.fromMeters = fromMeters;
|
|
@@ -2519,6 +2601,7 @@ exports.getFunctionsUtilsDirectory = getFunctionsUtilsDirectory;
|
|
|
2519
2601
|
exports.getHeaders = getHeaders;
|
|
2520
2602
|
exports.getHooksUtilsDirectory = getHooksUtilsDirectory;
|
|
2521
2603
|
exports.getHtmlDirectory = getHtmlDirectory;
|
|
2604
|
+
exports.getIfNone = getIfNone;
|
|
2522
2605
|
exports.getLibUtilsDirectory = getLibUtilsDirectory;
|
|
2523
2606
|
exports.getMediaExts = getMediaExts;
|
|
2524
2607
|
exports.getMediaMap = getMediaMap;
|
|
@@ -2564,17 +2647,21 @@ exports.isFiniteNum = isFiniteNum;
|
|
|
2564
2647
|
exports.isMediaType = isMediaType;
|
|
2565
2648
|
exports.isNum = isNum;
|
|
2566
2649
|
exports.isStrInString = isStrInString;
|
|
2650
|
+
exports.isTimeInterval = isTimeInterval;
|
|
2567
2651
|
exports.isTokenExpired = isTokenExpired;
|
|
2568
2652
|
exports.isType = isType;
|
|
2653
|
+
exports.isZero = isZero;
|
|
2569
2654
|
exports.is_media_type = is_media_type;
|
|
2570
2655
|
exports.loadConfig = loadConfig;
|
|
2571
2656
|
exports.makePath = makePath;
|
|
2572
2657
|
exports.make_path = make_path;
|
|
2573
2658
|
exports.make_sanitized_path = make_sanitized_path;
|
|
2574
2659
|
exports.makepath = makepath;
|
|
2660
|
+
exports.mergeNotNullValues = mergeNotNullValues;
|
|
2575
2661
|
exports.metersToDistance = metersToDistance;
|
|
2576
2662
|
exports.mpsToSpeed = mpsToSpeed;
|
|
2577
2663
|
exports.normalizeUrl = normalizeUrl;
|
|
2664
|
+
exports.omitKeys = omitKeys;
|
|
2578
2665
|
exports.parseResult = parseResult;
|
|
2579
2666
|
exports.pathJoin = pathJoin;
|
|
2580
2667
|
exports.path_join = path_join;
|
|
@@ -2589,9 +2676,11 @@ exports.safeMultiply = safeMultiply;
|
|
|
2589
2676
|
exports.safeNums = safeNums;
|
|
2590
2677
|
exports.safeStorage = safeStorage;
|
|
2591
2678
|
exports.sanitizeFilename = sanitizeFilename;
|
|
2679
|
+
exports.sanitizeString = sanitizeString;
|
|
2592
2680
|
exports.secondsToTime = secondsToTime;
|
|
2593
2681
|
exports.speedToMps = speedToMps;
|
|
2594
2682
|
exports.stripPrefixes = stripPrefixes;
|
|
2683
|
+
exports.stripQuotes = stripQuotes;
|
|
2595
2684
|
exports.timeToSeconds = timeToSeconds;
|
|
2596
2685
|
exports.toMeters = toMeters;
|
|
2597
2686
|
exports.toSeconds = toSeconds;
|