@putkoff/abstract-utilities 0.1.208 → 0.1.210

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
@@ -408,9 +408,6 @@ function getResult(obj) {
408
408
  Object.prototype.hasOwnProperty.call(current, "result")) {
409
409
  current = current.result;
410
410
  }
411
- if (current === null || current === void 0 ? void 0 : current.result) {
412
- current = current.result;
413
- }
414
411
  return current;
415
412
  }
416
413
  // Determines HTTP method, defaults to GET or POST based on body
@@ -526,7 +523,7 @@ function fetchIt(endpoint_1) {
526
523
  if (blob)
527
524
  return res.blob();
528
525
  if (returnResult || returnJson) {
529
- let JsonRes = res.json();
526
+ let JsonRes = parseResult(res);
530
527
  if (returnResult) {
531
528
  JsonRes = getResult(JsonRes);
532
529
  }
@@ -1064,6 +1061,62 @@ posix.posix = posix;
1064
1061
 
1065
1062
  var pathBrowserify = posix;
1066
1063
 
1064
+ function ensure_list(obj) {
1065
+ const objArray = Array.isArray(obj) ? obj : [obj];
1066
+ return objArray;
1067
+ }
1068
+ function assureString(obj) {
1069
+ return String(obj);
1070
+ }
1071
+ function cleanArray(obj) {
1072
+ obj = assureArray(obj);
1073
+ return Array.from(new Set(obj));
1074
+ }
1075
+ function assureArray(input) {
1076
+ if (typeof input === 'string') {
1077
+ return [input];
1078
+ }
1079
+ if (Array.isArray(input)) {
1080
+ return input.map(item => assureString(item));
1081
+ }
1082
+ return [];
1083
+ }
1084
+ // Constrain T so 'in obj' is allowed
1085
+ function get_key_value(obj, key) {
1086
+ // we cast to any for the indexing, since TS can’t infer arbitrary string keys
1087
+ if (key in obj && obj[key] != null) {
1088
+ return obj[key];
1089
+ }
1090
+ return null;
1091
+ }
1092
+ function get(obj, keys, defaultValue = null) {
1093
+ const keyArray = assureArray(keys);
1094
+ if (!obj || keyArray.length === 0) {
1095
+ return defaultValue;
1096
+ }
1097
+ for (const key of keyArray) {
1098
+ const val = get_key_value(obj, key);
1099
+ if (val != null) {
1100
+ return val;
1101
+ }
1102
+ }
1103
+ return defaultValue;
1104
+ }
1105
+ function cleanText(input) {
1106
+ // Replace delimiters with spaces and split
1107
+ const str = assureString(input);
1108
+ const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
1109
+ return words;
1110
+ }
1111
+ function getCleanArray(obj) {
1112
+ obj = obj.split(/\s+/) // Split on any whitespace
1113
+ .filter((item) => typeof item === 'string' && item !== '');
1114
+ // Get basename
1115
+ // Remove duplicates using Set
1116
+ const uniqueWords = cleanArray(obj);
1117
+ return uniqueWords;
1118
+ }
1119
+
1067
1120
  function getSubstring(obj, maxLength = null, minLength = null) {
1068
1121
  const objLength = obj.length;
1069
1122
  const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
@@ -1084,6 +1137,30 @@ function truncateString(obj, maxLength = 20) {
1084
1137
  }
1085
1138
  return obj;
1086
1139
  }
1140
+ function capitalize_str(string) {
1141
+ string = assureString(string);
1142
+ const string_len = string.length;
1143
+ let init_char = string.toUpperCase();
1144
+ if (string_len > 0) {
1145
+ init_char = string[0].toUpperCase();
1146
+ }
1147
+ let rest_chars = '';
1148
+ if (string_len > 1) {
1149
+ rest_chars = string.slice(1).toLowerCase();
1150
+ }
1151
+ const fin_chars = `${init_char}${rest_chars}`;
1152
+ return fin_chars;
1153
+ }
1154
+ function capitalize(string) {
1155
+ let nu_string = '';
1156
+ string = assureString(string);
1157
+ let objs = string.replace('-', '_').split('_');
1158
+ for (const obj of objs) {
1159
+ let str_obj = capitalize_str(obj);
1160
+ nu_string = `${nu_string} ${str_obj}`;
1161
+ }
1162
+ return eatAll(nu_string, [' ']);
1163
+ }
1087
1164
  // string_utils/src/string_utils.ts
1088
1165
  function stripPrefixes(str, bases = []) {
1089
1166
  /* NEW: coerce whatever arrives into a string */
@@ -1193,62 +1270,6 @@ function create_list_string(array_obj) {
1193
1270
  return string;
1194
1271
  }
1195
1272
 
1196
- function ensure_list(obj) {
1197
- const objArray = Array.isArray(obj) ? obj : [obj];
1198
- return objArray;
1199
- }
1200
- function assureString(obj) {
1201
- return String(obj);
1202
- }
1203
- function cleanArray(obj) {
1204
- obj = assureArray(obj);
1205
- return Array.from(new Set(obj));
1206
- }
1207
- function assureArray(input) {
1208
- if (typeof input === 'string') {
1209
- return [input];
1210
- }
1211
- if (Array.isArray(input)) {
1212
- return input.map(item => assureString(item));
1213
- }
1214
- return [];
1215
- }
1216
- // Constrain T so 'in obj' is allowed
1217
- function get_key_value(obj, key) {
1218
- // we cast to any for the indexing, since TS can’t infer arbitrary string keys
1219
- if (key in obj && obj[key] != null) {
1220
- return obj[key];
1221
- }
1222
- return null;
1223
- }
1224
- function get(obj, keys, defaultValue = null) {
1225
- const keyArray = assureArray(keys);
1226
- if (!obj || keyArray.length === 0) {
1227
- return defaultValue;
1228
- }
1229
- for (const key of keyArray) {
1230
- const val = get_key_value(obj, key);
1231
- if (val != null) {
1232
- return val;
1233
- }
1234
- }
1235
- return defaultValue;
1236
- }
1237
- function cleanText(input) {
1238
- // Replace delimiters with spaces and split
1239
- const str = assureString(input);
1240
- const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
1241
- return words;
1242
- }
1243
- function getCleanArray(obj) {
1244
- obj = obj.split(/\s+/) // Split on any whitespace
1245
- .filter((item) => typeof item === 'string' && item !== '');
1246
- // Get basename
1247
- // Remove duplicates using Set
1248
- const uniqueWords = cleanArray(obj);
1249
- return uniqueWords;
1250
- }
1251
-
1252
1273
  /**
1253
1274
  * In the browser we already have a WHATWG URL constructor on window.
1254
1275
  * Here we re-export it as “url” so other modules can import it.
@@ -1608,6 +1629,8 @@ exports.assureArray = assureArray;
1608
1629
  exports.assureString = assureString;
1609
1630
  exports.callStorage = callStorage;
1610
1631
  exports.callWindowMethod = callWindowMethod;
1632
+ exports.capitalize = capitalize;
1633
+ exports.capitalize_str = capitalize_str;
1611
1634
  exports.checkResponse = checkResponse;
1612
1635
  exports.cleanArray = cleanArray;
1613
1636
  exports.cleanText = cleanText;