@putkoff/abstract-utilities 0.1.223 → 0.1.225

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.
Files changed (95) hide show
  1. package/dist/cjs/index.js +101 -56
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.js +86 -57
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/index.cjs +0 -0
  6. package/dist/index.cjs.map +0 -0
  7. package/dist/index.d.ts +29 -9
  8. package/dist/index.js +0 -0
  9. package/dist/index.js.map +0 -0
  10. package/dist/types/functions/auth_utils/imports.d.ts +0 -0
  11. package/dist/types/functions/auth_utils/index.d.ts +0 -0
  12. package/dist/types/functions/auth_utils/src/index.d.ts +0 -0
  13. package/dist/types/functions/auth_utils/src/token_utils.d.ts +0 -0
  14. package/dist/types/functions/config_utils/imports.d.ts +0 -0
  15. package/dist/types/functions/config_utils/index.d.ts +0 -0
  16. package/dist/types/functions/config_utils/src/config_utils.d.ts +0 -0
  17. package/dist/types/functions/config_utils/src/index.d.ts +0 -0
  18. package/dist/types/functions/constants_utils/index.d.ts +0 -0
  19. package/dist/types/functions/constants_utils/src/constants.d.ts +0 -0
  20. package/dist/types/functions/constants_utils/src/index.d.ts +0 -0
  21. package/dist/types/functions/env_utils/imports.d.ts +0 -0
  22. package/dist/types/functions/env_utils/index.d.ts +0 -0
  23. package/dist/types/functions/env_utils/src/index.d.ts +0 -0
  24. package/dist/types/functions/env_utils/src/window_utils.d.ts +0 -0
  25. package/dist/types/functions/fetch_utils/imports.d.ts +0 -0
  26. package/dist/types/functions/fetch_utils/index.d.ts +0 -0
  27. package/dist/types/functions/fetch_utils/src/fetch_utils.d.ts +0 -0
  28. package/dist/types/functions/fetch_utils/src/index.d.ts +0 -0
  29. package/dist/types/functions/fetch_utils/src/utils.d.ts +0 -0
  30. package/dist/types/functions/index.d.ts +1 -0
  31. package/dist/types/functions/math_utils/index.d.ts +1 -0
  32. package/dist/types/functions/math_utils/safe_math.d.ts +4 -0
  33. package/dist/types/functions/path_utils/imports.d.ts +0 -0
  34. package/dist/types/functions/path_utils/index.d.ts +0 -0
  35. package/dist/types/functions/path_utils/src/base_dirs.d.ts +0 -0
  36. package/dist/types/functions/path_utils/src/function_dirs.d.ts +0 -0
  37. package/dist/types/functions/path_utils/src/index.d.ts +0 -0
  38. package/dist/types/functions/path_utils/src/misc_dirs.d.ts +0 -0
  39. package/dist/types/functions/path_utils/src/path_utils.browser.d.ts +0 -0
  40. package/dist/types/functions/path_utils/src/path_utils.d.ts +0 -0
  41. package/dist/types/functions/path_utils/src/path_utils.node.d.ts +0 -0
  42. package/dist/types/functions/path_utils/src/paths.d.ts +0 -0
  43. package/dist/types/functions/path_utils/src/src_dirs.d.ts +0 -0
  44. package/dist/types/functions/read_utils/imports.d.ts +0 -0
  45. package/dist/types/functions/read_utils/index.d.ts +0 -0
  46. package/dist/types/functions/read_utils/src/index.d.ts +0 -0
  47. package/dist/types/functions/read_utils/src/read_utils.browser.d.ts +0 -0
  48. package/dist/types/functions/read_utils/src/utils.browser.d.ts +0 -0
  49. package/dist/types/functions/read_utils/src/utils.d.ts +0 -0
  50. package/dist/types/functions/rndm_utils/imports.d.ts +0 -0
  51. package/dist/types/functions/rndm_utils/index.d.ts +0 -0
  52. package/dist/types/functions/rndm_utils/src/index.d.ts +0 -0
  53. package/dist/types/functions/rndm_utils/src/utils.d.ts +0 -0
  54. package/dist/types/functions/safe_utils/imports.d.ts +0 -0
  55. package/dist/types/functions/safe_utils/index.d.ts +0 -0
  56. package/dist/types/functions/safe_utils/src/index.d.ts +0 -0
  57. package/dist/types/functions/safe_utils/src/safe_document.d.ts +0 -0
  58. package/dist/types/functions/safe_utils/src/safe_globals.d.ts +0 -0
  59. package/dist/types/functions/safe_utils/src/safe_storage.d.ts +0 -0
  60. package/dist/types/functions/safe_utils/src/safe_window.d.ts +0 -0
  61. package/dist/types/functions/string_utils/index.d.ts +0 -0
  62. package/dist/types/functions/string_utils/src/index.d.ts +0 -0
  63. package/dist/types/functions/string_utils/src/string_utils.d.ts +0 -0
  64. package/dist/types/functions/type_utils/imports.d.ts +0 -0
  65. package/dist/types/functions/type_utils/index.d.ts +0 -0
  66. package/dist/types/functions/type_utils/src/clean_utils.d.ts +3 -0
  67. package/dist/types/functions/type_utils/src/ensure_utils.d.ts +16 -0
  68. package/dist/types/functions/type_utils/src/index.d.ts +3 -0
  69. package/dist/types/functions/type_utils/src/json_utils.d.ts +2 -0
  70. package/dist/types/functions/type_utils/src/type_utils.d.ts +2 -11
  71. package/dist/types/functions/ui_utils/imports.d.ts +0 -0
  72. package/dist/types/functions/ui_utils/index.d.ts +0 -0
  73. package/dist/types/functions/ui_utils/src/button.d.ts +0 -0
  74. package/dist/types/functions/ui_utils/src/checkbox.d.ts +0 -0
  75. package/dist/types/functions/ui_utils/src/index.d.ts +0 -0
  76. package/dist/types/functions/ui_utils/src/input.d.ts +0 -0
  77. package/dist/types/functions/ui_utils/src/spinner.d.ts +0 -0
  78. package/dist/types/functions/variable_utils/imports.d.ts +0 -0
  79. package/dist/types/functions/variable_utils/index.d.ts +0 -0
  80. package/dist/types/functions/variable_utils/src/index.d.ts +0 -0
  81. package/dist/types/functions/variable_utils/src/variable_utils.d.ts +0 -0
  82. package/dist/types/index.d.ts +0 -0
  83. package/dist/types/types/index.d.ts +0 -0
  84. package/dist/types/types/src/ChangePassword.d.ts +0 -0
  85. package/dist/types/types/src/Files.d.ts +0 -0
  86. package/dist/types/types/src/index.d.ts +0 -0
  87. package/dist/types/types/src/login.d.ts +0 -0
  88. package/dist/types/types/src/logout.d.ts +0 -0
  89. package/dist/types/types/src/utils.d.ts +0 -0
  90. package/dist/types/utils/imports.d.ts +0 -0
  91. package/dist/types/utils/index.d.ts +0 -0
  92. package/dist/types/utils/src/Input.d.ts +0 -0
  93. package/dist/types/utils/src/config.d.ts +0 -0
  94. package/dist/types/utils/src/index.d.ts +0 -0
  95. package/package.json +1 -1
package/dist/esm/index.js CHANGED
@@ -1063,22 +1063,55 @@ function ensure_list(obj) {
1063
1063
  const objArray = Array.isArray(obj) ? obj : [obj];
1064
1064
  return objArray;
1065
1065
  }
1066
- function assureString(obj) {
1067
- return String(obj);
1066
+ // coerce any single value into a number (0 if it can't)
1067
+ function ensure_number(x) {
1068
+ const n = Number(x);
1069
+ return isNaN(n) ? 0 : n;
1068
1070
  }
1069
- function cleanArray(obj) {
1070
- obj = assureArray(obj);
1071
- return Array.from(new Set(obj));
1072
- }
1073
- function assureArray(input) {
1071
+ function ensure_array(input) {
1074
1072
  if (typeof input === 'string') {
1075
1073
  return [input];
1076
1074
  }
1077
1075
  if (Array.isArray(input)) {
1078
- return input.map(item => assureString(item));
1076
+ return input.map(item => ensure_string(item));
1079
1077
  }
1080
1078
  return [];
1081
1079
  }
1080
+ function ensure_string(obj) {
1081
+ return String(obj);
1082
+ }
1083
+ const assureList = ensure_list;
1084
+ const assureString = ensure_string;
1085
+ const assureNumber = ensure_number;
1086
+ const assureArray = ensure_array;
1087
+ const assure_list = ensure_list;
1088
+ const assure_string = ensure_string;
1089
+ const assure_number = ensure_number;
1090
+ const assure_array = ensure_array;
1091
+ const ensureList = ensure_list;
1092
+ const ensureString = ensure_string;
1093
+ const ensureNumber = ensure_number;
1094
+ const ensureArray = ensure_array;
1095
+
1096
+ function cleanText(input) {
1097
+ // Replace delimiters with spaces and split
1098
+ const str = ensure_string(input);
1099
+ const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
1100
+ return words;
1101
+ }
1102
+ function cleanArray(obj) {
1103
+ obj = ensure_array(obj);
1104
+ return Array.from(new Set(obj));
1105
+ }
1106
+ function getCleanArray(obj) {
1107
+ obj = obj.split(/\s+/) // Split on any whitespace
1108
+ .filter((item) => typeof item === 'string' && item !== '');
1109
+ // Get basename
1110
+ // Remove duplicates using Set
1111
+ const uniqueWords = cleanArray(obj);
1112
+ return uniqueWords;
1113
+ }
1114
+
1082
1115
  // Constrain T so 'in obj' is allowed
1083
1116
  function get_key_value(obj, key) {
1084
1117
  // we cast to any for the indexing, since TS can’t infer arbitrary string keys
@@ -1088,7 +1121,7 @@ function get_key_value(obj, key) {
1088
1121
  return null;
1089
1122
  }
1090
1123
  function get(obj, keys, defaultValue = null) {
1091
- const keyArray = assureArray(keys);
1124
+ const keyArray = ensure_array(keys);
1092
1125
  if (!obj || keyArray.length === 0) {
1093
1126
  return defaultValue;
1094
1127
  }
@@ -1100,23 +1133,16 @@ function get(obj, keys, defaultValue = null) {
1100
1133
  }
1101
1134
  return defaultValue;
1102
1135
  }
1103
- function cleanText(input) {
1104
- // Replace delimiters with spaces and split
1105
- const str = assureString(input);
1106
- const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
1107
- return words;
1108
- }
1109
- function getCleanArray(obj) {
1110
- obj = obj.split(/\s+/) // Split on any whitespace
1111
- .filter((item) => typeof item === 'string' && item !== '');
1112
- // Get basename
1113
- // Remove duplicates using Set
1114
- const uniqueWords = cleanArray(obj);
1115
- return uniqueWords;
1136
+
1137
+ function isType(obj, type) {
1138
+ if (typeof obj === type) {
1139
+ return true;
1140
+ }
1141
+ return false;
1116
1142
  }
1117
1143
  function isStrInString(obj, string) {
1118
- const obj_str = assureString(obj).toLowerCase;
1119
- string = assureString(string).toLowerCase;
1144
+ const obj_str = ensure_string(obj).toLowerCase;
1145
+ string = ensure_string(string).toLowerCase;
1120
1146
  if (string.includes(obj_str)) {
1121
1147
  return true;
1122
1148
  }
@@ -1124,14 +1150,18 @@ function isStrInString(obj, string) {
1124
1150
  }
1125
1151
  function getChar(i, string) {
1126
1152
  if (string.length >= i) {
1127
- return assureString(string)[i];
1153
+ return ensure_string(string)[i];
1128
1154
  }
1129
1155
  }
1130
- function isType(obj, type) {
1131
- if (typeof obj === type) {
1132
- return true;
1156
+ function getAlphaNum(obj) {
1157
+ const is_num = isNum(obj);
1158
+ const alphas = getAlphas();
1159
+ if (is_num) {
1160
+ return getChar(obj, alphas);
1161
+ }
1162
+ if (isStrInString(obj, alphas)) {
1163
+ return getChar(obj, alphas);
1133
1164
  }
1134
- return false;
1135
1165
  }
1136
1166
  function getNums() {
1137
1167
  return '0123456789';
@@ -1143,36 +1173,9 @@ function isNum(obj) {
1143
1173
  }
1144
1174
  return isStrInString(obj, getNums());
1145
1175
  }
1146
- function ensure_number(object) {
1147
- if (isNum(object)) {
1148
- return Number(object);
1149
- }
1150
- let nuString = '';
1151
- const object_str = assureString(object);
1152
- const str_spl = object_str.split('');
1153
- for (const obj in str_spl) {
1154
- if (isNum(obj)) {
1155
- nuString += obj;
1156
- }
1157
- }
1158
- if (nuString != '') {
1159
- return Number(nuString);
1160
- }
1161
- return null;
1162
- }
1163
1176
  function getAlphas() {
1164
1177
  return 'abcdefghijklmnopqrstuvwxyz';
1165
1178
  }
1166
- function getAlphaNum(obj) {
1167
- const is_num = isNum(obj);
1168
- const alphas = getAlphas();
1169
- if (is_num) {
1170
- return getChar(obj, alphas);
1171
- }
1172
- if (isStrInString(obj, alphas)) {
1173
- return getChar(obj, alphas);
1174
- }
1175
- }
1176
1179
 
1177
1180
  function getSubstring(obj, maxLength = null, minLength = null) {
1178
1181
  const objLength = obj.length;
@@ -1622,5 +1625,31 @@ function get_keyword_string(keywords) {
1622
1625
  return allString;
1623
1626
  }
1624
1627
 
1625
- export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, assureArray, assureString, callStorage, callWindowMethod, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, create_list_string, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensure_list, ensure_number, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfigContent, getConfigJson, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_basename, get_dirname, get_extname, get_filename, get_key_value, get_keyword_string, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isNum, isStrInString, isTokenExpired, isType, make_path, make_sanitized_path, normalizeUrl, parseResult, processKeywords, readJsonFile, removeToken, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse };
1628
+ // take N args and coerce them all to numbers
1629
+ function safeNums(...args) {
1630
+ return args.map(ensure_number);
1631
+ }
1632
+ // divide the first value by each of the following
1633
+ function safeDivide(...args) {
1634
+ const [head, ...rest] = safeNums(...args);
1635
+ // if we don’t have a head or any divisor is zero, bail
1636
+ if (head === 0 || rest.some((d) => d === 0))
1637
+ return 0;
1638
+ return rest.reduce((acc, d) => acc / d, head);
1639
+ }
1640
+ // multiply all the values together
1641
+ function safeMultiply(...args) {
1642
+ const nums = safeNums(...args);
1643
+ // if any number is zero, result is zero
1644
+ if (nums.includes(0))
1645
+ return 0;
1646
+ return nums.reduce((acc, n) => acc * n, 1);
1647
+ }
1648
+ // round a value to two decimals by percent
1649
+ function roundPercentage(x) {
1650
+ const pct = safeMultiply(ensure_number(x), 100);
1651
+ return safeDivide(Math.round(pct), 100);
1652
+ }
1653
+
1654
+ export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, callStorage, callWindowMethod, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, create_list_string, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfigContent, getConfigJson, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_basename, get_dirname, get_extname, get_filename, get_key_value, get_keyword_string, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isNum, isStrInString, isTokenExpired, isType, make_path, make_sanitized_path, normalizeUrl, parseResult, processKeywords, readJsonFile, removeToken, requireToken, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse };
1626
1655
  //# sourceMappingURL=index.js.map