@putkoff/abstract-utilities 1.0.66 → 1.0.68

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 CHANGED
@@ -238,7 +238,7 @@ function fetchIt(endpoint_1) {
238
238
  return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnReult = true) {
239
239
  method = (method || "GET").toUpperCase();
240
240
  // 2) choose the URL
241
- let url = endpoint;
241
+ const url = endpoint;
242
242
  // 3) prepare headers & body
243
243
  headers = Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), headers);
244
244
  const opts = {
@@ -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) {
@@ -1416,6 +1436,14 @@ function getSubstring(obj, maxLength = null, minLength = null) {
1416
1436
  }
1417
1437
  return obj.substring(clampedMinLength, clampedMaxLength);
1418
1438
  }
1439
+ /**
1440
+ * Sanitize a string by removing null bytes and trimming whitespace.
1441
+ */
1442
+ function sanitizeString(input) {
1443
+ if (!input)
1444
+ return input;
1445
+ return input.replace(/\u0000/g, "").trim(); // Remove null bytes and whitespace
1446
+ }
1419
1447
  function truncateString(obj, maxLength = 20) {
1420
1448
  const objLength = obj.length;
1421
1449
  if (objLength > maxLength && maxLength) {
@@ -1440,9 +1468,9 @@ function capitalize_str(string) {
1440
1468
  function capitalize(string) {
1441
1469
  let nu_string = '';
1442
1470
  string = assureString(string);
1443
- let objs = string.replace('-', '_').split('_');
1471
+ const objs = string.replace('-', '_').split('_');
1444
1472
  for (const obj of objs) {
1445
- let str_obj = capitalize_str(obj);
1473
+ const str_obj = capitalize_str(obj);
1446
1474
  nu_string = `${nu_string} ${str_obj}`;
1447
1475
  }
1448
1476
  return eatAll(nu_string, [' ']);
@@ -1525,7 +1553,7 @@ function get_alpha_ints(opts) {
1525
1553
  function eatElse(stringObj, chars, ints = true, alpha = true, lower = true, capitalize = true, string = true, listObj = true) {
1526
1554
  stringObj = String(stringObj);
1527
1555
  const alphaInts = get_alpha_ints();
1528
- let ls = ensure_list(chars || []).concat(alphaInts);
1556
+ const ls = ensure_list(chars || []).concat(alphaInts);
1529
1557
  while (true) {
1530
1558
  if (!stringObj)
1531
1559
  return stringObj;
@@ -1574,6 +1602,24 @@ function eatouter(str, listObjects) {
1574
1602
  return eatOuter(str, listObjects);
1575
1603
  }
1576
1604
 
1605
+ /**
1606
+ * Checks if a value is enclosed in quotes.
1607
+ */
1608
+ function ends_in_quotes(value) {
1609
+ if (typeof value === 'string') {
1610
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
1611
+ return true;
1612
+ }
1613
+ }
1614
+ return false;
1615
+ }
1616
+ function stripQuotes(value) {
1617
+ if (ends_in_quotes(value)) {
1618
+ return value.slice(1, -1); // Remove the first and last characters
1619
+ }
1620
+ return value; // Return the input unchanged for all other cases
1621
+ }
1622
+
1577
1623
  /**
1578
1624
  * In the browser we already have a WHATWG URL constructor on window.
1579
1625
  * Here we re-export it as “url” so other modules can import it.
@@ -1883,6 +1929,12 @@ function roundPercentage(x) {
1883
1929
  function exponential(i, k) {
1884
1930
  return i * (10 ** (k));
1885
1931
  }
1932
+ function isZero(obj) {
1933
+ if (obj == 0) {
1934
+ return true;
1935
+ }
1936
+ return false;
1937
+ }
1886
1938
 
1887
1939
  const SECOND = 1;
1888
1940
  const ZEPTOSECOND = exponential(SECOND, -21);
@@ -2049,6 +2101,11 @@ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit)
2049
2101
  const isFiniteNum = (x) => Number.isFinite(x);
2050
2102
  const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
2051
2103
 
2104
+ // Function to check time interval
2105
+ function isTimeInterval(timeObj, interval) {
2106
+ return (Date.now() / 1000 - timeObj) < (interval - 1);
2107
+ }
2108
+
2052
2109
  function getSafeDocument() {
2053
2110
  return typeof document !== 'undefined' ? document : undefined;
2054
2111
  }
@@ -2105,7 +2162,6 @@ function callStorage(method, ...args) {
2105
2162
  if (typeof fn !== 'function')
2106
2163
  return undefined;
2107
2164
  try {
2108
- // @ts-ignore – TS can’t infer that this is callable
2109
2165
  return fn.apply(storage, args);
2110
2166
  }
2111
2167
  catch (_a) {
@@ -2121,7 +2177,6 @@ function safeStorage(storageName, method, ...args) {
2121
2177
  const store = safeGlobalProp(storageName);
2122
2178
  if (!store || typeof store[method] !== "function")
2123
2179
  return undefined;
2124
- // @ts-ignore
2125
2180
  return store[method](...args);
2126
2181
  }
2127
2182
  catch (_a) {
@@ -2460,6 +2515,7 @@ exports.eatOuter = eatOuter;
2460
2515
  exports.eatall = eatall;
2461
2516
  exports.eatinner = eatinner;
2462
2517
  exports.eatouter = eatouter;
2518
+ exports.ends_in_quotes = ends_in_quotes;
2463
2519
  exports.ensureArray = ensureArray;
2464
2520
  exports.ensureList = ensureList;
2465
2521
  exports.ensureNumber = ensureNumber;
@@ -2476,6 +2532,7 @@ exports.exponential = exponential;
2476
2532
  exports.fetchIndexHtml = fetchIndexHtml;
2477
2533
  exports.fetchIndexHtmlContainer = fetchIndexHtmlContainer;
2478
2534
  exports.fetchIt = fetchIt;
2535
+ exports.findKeyValue = findKeyValue;
2479
2536
  exports.fmt = fmt;
2480
2537
  exports.formatNumber = formatNumber;
2481
2538
  exports.fromMeters = fromMeters;
@@ -2566,8 +2623,10 @@ exports.isFiniteNum = isFiniteNum;
2566
2623
  exports.isMediaType = isMediaType;
2567
2624
  exports.isNum = isNum;
2568
2625
  exports.isStrInString = isStrInString;
2626
+ exports.isTimeInterval = isTimeInterval;
2569
2627
  exports.isTokenExpired = isTokenExpired;
2570
2628
  exports.isType = isType;
2629
+ exports.isZero = isZero;
2571
2630
  exports.is_media_type = is_media_type;
2572
2631
  exports.loadConfig = loadConfig;
2573
2632
  exports.makePath = makePath;
@@ -2577,6 +2636,7 @@ exports.makepath = makepath;
2577
2636
  exports.metersToDistance = metersToDistance;
2578
2637
  exports.mpsToSpeed = mpsToSpeed;
2579
2638
  exports.normalizeUrl = normalizeUrl;
2639
+ exports.omitKeys = omitKeys;
2580
2640
  exports.parseResult = parseResult;
2581
2641
  exports.pathJoin = pathJoin;
2582
2642
  exports.path_join = path_join;
@@ -2591,9 +2651,11 @@ exports.safeMultiply = safeMultiply;
2591
2651
  exports.safeNums = safeNums;
2592
2652
  exports.safeStorage = safeStorage;
2593
2653
  exports.sanitizeFilename = sanitizeFilename;
2654
+ exports.sanitizeString = sanitizeString;
2594
2655
  exports.secondsToTime = secondsToTime;
2595
2656
  exports.speedToMps = speedToMps;
2596
2657
  exports.stripPrefixes = stripPrefixes;
2658
+ exports.stripQuotes = stripQuotes;
2597
2659
  exports.timeToSeconds = timeToSeconds;
2598
2660
  exports.toMeters = toMeters;
2599
2661
  exports.toSeconds = toSeconds;