@putkoff/abstract-utilities 0.1.224 → 0.1.226
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 +101 -56
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +86 -57
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +29 -9
- package/dist/types/functions/index.d.ts +1 -0
- package/dist/types/functions/math_utils/index.d.ts +1 -0
- package/dist/types/functions/math_utils/safe_math.d.ts +4 -0
- package/dist/types/functions/type_utils/src/clean_utils.d.ts +3 -0
- package/dist/types/functions/type_utils/src/ensure_utils.d.ts +16 -0
- package/dist/types/functions/type_utils/src/index.d.ts +3 -0
- package/dist/types/functions/type_utils/src/json_utils.d.ts +2 -0
- package/dist/types/functions/type_utils/src/type_utils.d.ts +2 -11
- package/package.json +1 -1
- package/dist/index.cjs +0 -5877
- package/dist/index.cjs.map +0 -1
- package/dist/index.js +0 -5762
- package/dist/index.js.map +0 -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
|
-
|
|
1067
|
-
|
|
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
|
|
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 =>
|
|
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 =
|
|
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
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
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 =
|
|
1119
|
-
string =
|
|
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
|
|
1153
|
+
return ensure_string(string)[i];
|
|
1128
1154
|
}
|
|
1129
1155
|
}
|
|
1130
|
-
function
|
|
1131
|
-
|
|
1132
|
-
|
|
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 0;
|
|
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
|
-
|
|
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
|