@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/esm/index.js CHANGED
@@ -224,7 +224,7 @@ function fetchIt(endpoint_1) {
224
224
  return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnReult = true) {
225
225
  method = (method || "GET").toUpperCase();
226
226
  // 2) choose the URL
227
- let url = endpoint;
227
+ const url = endpoint;
228
228
  // 3) prepare headers & body
229
229
  headers = Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), headers);
230
230
  const opts = {
@@ -1058,6 +1058,26 @@ function get(obj, keys, defaultValue = null) {
1058
1058
  }
1059
1059
  return defaultValue;
1060
1060
  }
1061
+ // Create the accountInfo table if it doesn't already exist
1062
+ function findKeyValue(obj, keyToFind) {
1063
+ if (keyToFind in obj)
1064
+ return obj[keyToFind];
1065
+ for (const key in obj) {
1066
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
1067
+ const result = findKeyValue(obj[key], keyToFind);
1068
+ if (result !== undefined)
1069
+ return result;
1070
+ }
1071
+ }
1072
+ return undefined;
1073
+ }
1074
+ function omitKeys(obj, ...keys) {
1075
+ const newObj = Object.assign({}, obj);
1076
+ keys.forEach(key => {
1077
+ delete newObj[key];
1078
+ });
1079
+ return newObj;
1080
+ }
1061
1081
 
1062
1082
  function isType(obj, type) {
1063
1083
  if (typeof obj === type) {
@@ -1443,6 +1463,14 @@ function getSubstring(obj, maxLength = null, minLength = null) {
1443
1463
  }
1444
1464
  return obj.substring(clampedMinLength, clampedMaxLength);
1445
1465
  }
1466
+ /**
1467
+ * Sanitize a string by removing null bytes and trimming whitespace.
1468
+ */
1469
+ function sanitizeString(input) {
1470
+ if (!input)
1471
+ return input;
1472
+ return input.replace(/\u0000/g, "").trim(); // Remove null bytes and whitespace
1473
+ }
1446
1474
  function truncateString(obj, maxLength = 20) {
1447
1475
  const objLength = obj.length;
1448
1476
  if (objLength > maxLength && maxLength) {
@@ -1467,9 +1495,9 @@ function capitalize_str(string) {
1467
1495
  function capitalize(string) {
1468
1496
  let nu_string = '';
1469
1497
  string = assureString(string);
1470
- let objs = string.replace('-', '_').split('_');
1498
+ const objs = string.replace('-', '_').split('_');
1471
1499
  for (const obj of objs) {
1472
- let str_obj = capitalize_str(obj);
1500
+ const str_obj = capitalize_str(obj);
1473
1501
  nu_string = `${nu_string} ${str_obj}`;
1474
1502
  }
1475
1503
  return eatAll(nu_string, [' ']);
@@ -1552,7 +1580,7 @@ function get_alpha_ints(opts) {
1552
1580
  function eatElse(stringObj, chars, ints = true, alpha = true, lower = true, capitalize = true, string = true, listObj = true) {
1553
1581
  stringObj = String(stringObj);
1554
1582
  const alphaInts = get_alpha_ints();
1555
- let ls = ensure_list(chars || []).concat(alphaInts);
1583
+ const ls = ensure_list(chars || []).concat(alphaInts);
1556
1584
  while (true) {
1557
1585
  if (!stringObj)
1558
1586
  return stringObj;
@@ -1601,6 +1629,24 @@ function eatouter(str, listObjects) {
1601
1629
  return eatOuter(str, listObjects);
1602
1630
  }
1603
1631
 
1632
+ /**
1633
+ * Checks if a value is enclosed in quotes.
1634
+ */
1635
+ function ends_in_quotes(value) {
1636
+ if (typeof value === 'string') {
1637
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
1638
+ return true;
1639
+ }
1640
+ }
1641
+ return false;
1642
+ }
1643
+ function stripQuotes(value) {
1644
+ if (ends_in_quotes(value)) {
1645
+ return value.slice(1, -1); // Remove the first and last characters
1646
+ }
1647
+ return value; // Return the input unchanged for all other cases
1648
+ }
1649
+
1604
1650
  /**
1605
1651
  * In the browser we already have a WHATWG URL constructor on window.
1606
1652
  * Here we re-export it as “url” so other modules can import it.
@@ -1910,6 +1956,12 @@ function roundPercentage(x) {
1910
1956
  function exponential(i, k) {
1911
1957
  return i * (10 ** (k));
1912
1958
  }
1959
+ function isZero(obj) {
1960
+ if (obj == 0) {
1961
+ return true;
1962
+ }
1963
+ return false;
1964
+ }
1913
1965
 
1914
1966
  const SECOND = 1;
1915
1967
  const ZEPTOSECOND = exponential(SECOND, -21);
@@ -2076,6 +2128,11 @@ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit)
2076
2128
  const isFiniteNum = (x) => Number.isFinite(x);
2077
2129
  const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
2078
2130
 
2131
+ // Function to check time interval
2132
+ function isTimeInterval(timeObj, interval) {
2133
+ return (Date.now() / 1000 - timeObj) < (interval - 1);
2134
+ }
2135
+
2079
2136
  function getSafeDocument() {
2080
2137
  return typeof document !== 'undefined' ? document : undefined;
2081
2138
  }
@@ -2132,7 +2189,6 @@ function callStorage(method, ...args) {
2132
2189
  if (typeof fn !== 'function')
2133
2190
  return undefined;
2134
2191
  try {
2135
- // @ts-ignore – TS can’t infer that this is callable
2136
2192
  return fn.apply(storage, args);
2137
2193
  }
2138
2194
  catch (_a) {
@@ -2148,7 +2204,6 @@ function safeStorage(storageName, method, ...args) {
2148
2204
  const store = safeGlobalProp(storageName);
2149
2205
  if (!store || typeof store[method] !== "function")
2150
2206
  return undefined;
2151
- // @ts-ignore
2152
2207
  return store[method](...args);
2153
2208
  }
2154
2209
  catch (_a) {
@@ -2401,5 +2456,5 @@ function get_keyword_string(keywords) {
2401
2456
  return allString;
2402
2457
  }
2403
2458
 
2404
- export { API_PREFIX, ATTOSECOND, BASE_URL, CENTISECOND, DAY, DAY_IN_S, DECISECOND, DEV_PREFIX, DIST_ALIASES, DIST_FACTORS, DOMAIN_NAME, DistanceConverter, FEET_PER_METER, FEMTOSECOND, HOUR, HOUR_IN_S, KMS_PER_METER, MEDIA_TYPES, METERS_PER_FOOT, METERS_PER_KM, METERS_PER_MILE, MICROSECOND, MILES_PER_METER, MILISECOND, MIME_TYPES, MINUTE, MIN_IN_S, MONTH, MONTH_IN_S, MPerS_TO_MiPerH, MiPerH_TO_MPerS, NANOSECOND, PI, PI2, PICOSECOND, PROD_PREFIX, PROTOCOL, SECOND, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SUB_DIR, SpeedConverter, TIME_ALIASES, TIME_FACTORS, TimeConverter, YEAR, YEAR_IN_S, ZEPTOSECOND, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, assurearray, assurelist, assurenumber, assurestring, callStorage, callWindowMethod, canonDist, canonTime, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, confirmType, confirm_type, convertDistance, convertSpeed, convertTime, create_list_string, decodeJwt, distanceToMeters, eatAll, eatElse, eatInner, eatOuter, eatall, eatinner, eatouter, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, ensurearray, ensurelist, ensurenumber, ensurestring, exponential, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fmt, formatNumber, fromMeters, fromMps, fromSeconds, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAllFileTypes, getAllFileTypesSync, getAlphaNum, getAlphas, getBaseDir, getBasename, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDirname, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getExtname, getFetchVars, getFilename, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMediaExts, getMediaMap, getMethod, getMimeType, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSplitext, getSrcDir, getSubstring, getWindowHost, getWindowProp, get_all_file_types, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_media_exts, get_media_map, get_mime_type, get_relative_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, getbasename, getdirname, getextname, getfilename, getsplitext, isFiniteNum, isMediaType, isNum, isStrInString, isTokenExpired, isType, is_media_type, loadConfig, makePath, make_path, make_sanitized_path, makepath, metersToDistance, mpsToSpeed, normalizeUrl, parseResult, pathJoin, path_join, path_to_url, pathjoin, processKeywords, readJsonFile, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, secondsToTime, speedToMps, stripPrefixes, timeToSeconds, toMeters, toSeconds, truncateString, tryEatPrefix, tryParse, urlJoin, url_to_path, urljoin, velocityFromMs, velocityToMs };
2459
+ export { API_PREFIX, ATTOSECOND, BASE_URL, CENTISECOND, DAY, DAY_IN_S, DECISECOND, DEV_PREFIX, DIST_ALIASES, DIST_FACTORS, DOMAIN_NAME, DistanceConverter, FEET_PER_METER, FEMTOSECOND, HOUR, HOUR_IN_S, KMS_PER_METER, MEDIA_TYPES, METERS_PER_FOOT, METERS_PER_KM, METERS_PER_MILE, MICROSECOND, MILES_PER_METER, MILISECOND, MIME_TYPES, MINUTE, MIN_IN_S, MONTH, MONTH_IN_S, MPerS_TO_MiPerH, MiPerH_TO_MPerS, NANOSECOND, PI, PI2, PICOSECOND, PROD_PREFIX, PROTOCOL, SECOND, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SUB_DIR, SpeedConverter, TIME_ALIASES, TIME_FACTORS, TimeConverter, YEAR, YEAR_IN_S, ZEPTOSECOND, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, assurearray, assurelist, assurenumber, assurestring, callStorage, callWindowMethod, canonDist, canonTime, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, confirmType, confirm_type, convertDistance, convertSpeed, convertTime, create_list_string, decodeJwt, distanceToMeters, eatAll, eatElse, eatInner, eatOuter, eatall, eatinner, eatouter, ends_in_quotes, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, ensurearray, ensurelist, ensurenumber, ensurestring, exponential, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, findKeyValue, fmt, formatNumber, fromMeters, fromMps, fromSeconds, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAllFileTypes, getAllFileTypesSync, getAlphaNum, getAlphas, getBaseDir, getBasename, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDirname, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getExtname, getFetchVars, getFilename, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMediaExts, getMediaMap, getMethod, getMimeType, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSplitext, getSrcDir, getSubstring, getWindowHost, getWindowProp, get_all_file_types, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_media_exts, get_media_map, get_mime_type, get_relative_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, getbasename, getdirname, getextname, getfilename, getsplitext, isFiniteNum, isMediaType, isNum, isStrInString, isTimeInterval, isTokenExpired, isType, isZero, is_media_type, loadConfig, makePath, make_path, make_sanitized_path, makepath, metersToDistance, mpsToSpeed, normalizeUrl, omitKeys, parseResult, pathJoin, path_join, path_to_url, pathjoin, processKeywords, readJsonFile, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, sanitizeString, secondsToTime, speedToMps, stripPrefixes, stripQuotes, timeToSeconds, toMeters, toSeconds, truncateString, tryEatPrefix, tryParse, urlJoin, url_to_path, urljoin, velocityFromMs, velocityToMs };
2405
2460
  //# sourceMappingURL=index.js.map