@putkoff/abstract-utilities 0.1.209 → 0.1.211

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
@@ -140,6 +140,17 @@ function isLoggedIn() {
140
140
  const tok = getToken();
141
141
  return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
142
142
  }
143
+ function removeToken() {
144
+ let is_logged = isLoggedIn();
145
+ if (is_logged) {
146
+ localStorage.removeItem("token");
147
+ }
148
+ is_logged = isLoggedIn();
149
+ if (is_logged) {
150
+ return false;
151
+ }
152
+ return true;
153
+ }
143
154
  /**
144
155
  * Add a Bearer Authorization header.
145
156
  * A shallow copy of headers is returned so callers can keep chaining.
@@ -405,9 +416,6 @@ function getResult(obj) {
405
416
  Object.prototype.hasOwnProperty.call(current, "result")) {
406
417
  current = current.result;
407
418
  }
408
- if (current === null || current === void 0 ? void 0 : current.result) {
409
- current = current.result;
410
- }
411
419
  return current;
412
420
  }
413
421
  // Determines HTTP method, defaults to GET or POST based on body
@@ -1061,6 +1069,62 @@ posix.posix = posix;
1061
1069
 
1062
1070
  var pathBrowserify = posix;
1063
1071
 
1072
+ function ensure_list(obj) {
1073
+ const objArray = Array.isArray(obj) ? obj : [obj];
1074
+ return objArray;
1075
+ }
1076
+ function assureString(obj) {
1077
+ return String(obj);
1078
+ }
1079
+ function cleanArray(obj) {
1080
+ obj = assureArray(obj);
1081
+ return Array.from(new Set(obj));
1082
+ }
1083
+ function assureArray(input) {
1084
+ if (typeof input === 'string') {
1085
+ return [input];
1086
+ }
1087
+ if (Array.isArray(input)) {
1088
+ return input.map(item => assureString(item));
1089
+ }
1090
+ return [];
1091
+ }
1092
+ // Constrain T so 'in obj' is allowed
1093
+ function get_key_value(obj, key) {
1094
+ // we cast to any for the indexing, since TS can’t infer arbitrary string keys
1095
+ if (key in obj && obj[key] != null) {
1096
+ return obj[key];
1097
+ }
1098
+ return null;
1099
+ }
1100
+ function get(obj, keys, defaultValue = null) {
1101
+ const keyArray = assureArray(keys);
1102
+ if (!obj || keyArray.length === 0) {
1103
+ return defaultValue;
1104
+ }
1105
+ for (const key of keyArray) {
1106
+ const val = get_key_value(obj, key);
1107
+ if (val != null) {
1108
+ return val;
1109
+ }
1110
+ }
1111
+ return defaultValue;
1112
+ }
1113
+ function cleanText(input) {
1114
+ // Replace delimiters with spaces and split
1115
+ const str = assureString(input);
1116
+ const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
1117
+ return words;
1118
+ }
1119
+ function getCleanArray(obj) {
1120
+ obj = obj.split(/\s+/) // Split on any whitespace
1121
+ .filter((item) => typeof item === 'string' && item !== '');
1122
+ // Get basename
1123
+ // Remove duplicates using Set
1124
+ const uniqueWords = cleanArray(obj);
1125
+ return uniqueWords;
1126
+ }
1127
+
1064
1128
  function getSubstring(obj, maxLength = null, minLength = null) {
1065
1129
  const objLength = obj.length;
1066
1130
  const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
@@ -1081,6 +1145,30 @@ function truncateString(obj, maxLength = 20) {
1081
1145
  }
1082
1146
  return obj;
1083
1147
  }
1148
+ function capitalize_str(string) {
1149
+ string = assureString(string);
1150
+ const string_len = string.length;
1151
+ let init_char = string.toUpperCase();
1152
+ if (string_len > 0) {
1153
+ init_char = string[0].toUpperCase();
1154
+ }
1155
+ let rest_chars = '';
1156
+ if (string_len > 1) {
1157
+ rest_chars = string.slice(1).toLowerCase();
1158
+ }
1159
+ const fin_chars = `${init_char}${rest_chars}`;
1160
+ return fin_chars;
1161
+ }
1162
+ function capitalize(string) {
1163
+ let nu_string = '';
1164
+ string = assureString(string);
1165
+ let objs = string.replace('-', '_').split('_');
1166
+ for (const obj of objs) {
1167
+ let str_obj = capitalize_str(obj);
1168
+ nu_string = `${nu_string} ${str_obj}`;
1169
+ }
1170
+ return eatAll(nu_string, [' ']);
1171
+ }
1084
1172
  // string_utils/src/string_utils.ts
1085
1173
  function stripPrefixes(str, bases = []) {
1086
1174
  /* NEW: coerce whatever arrives into a string */
@@ -1190,62 +1278,6 @@ function create_list_string(array_obj) {
1190
1278
  return string;
1191
1279
  }
1192
1280
 
1193
- function ensure_list(obj) {
1194
- const objArray = Array.isArray(obj) ? obj : [obj];
1195
- return objArray;
1196
- }
1197
- function assureString(obj) {
1198
- return String(obj);
1199
- }
1200
- function cleanArray(obj) {
1201
- obj = assureArray(obj);
1202
- return Array.from(new Set(obj));
1203
- }
1204
- function assureArray(input) {
1205
- if (typeof input === 'string') {
1206
- return [input];
1207
- }
1208
- if (Array.isArray(input)) {
1209
- return input.map(item => assureString(item));
1210
- }
1211
- return [];
1212
- }
1213
- // Constrain T so 'in obj' is allowed
1214
- function get_key_value(obj, key) {
1215
- // we cast to any for the indexing, since TS can’t infer arbitrary string keys
1216
- if (key in obj && obj[key] != null) {
1217
- return obj[key];
1218
- }
1219
- return null;
1220
- }
1221
- function get(obj, keys, defaultValue = null) {
1222
- const keyArray = assureArray(keys);
1223
- if (!obj || keyArray.length === 0) {
1224
- return defaultValue;
1225
- }
1226
- for (const key of keyArray) {
1227
- const val = get_key_value(obj, key);
1228
- if (val != null) {
1229
- return val;
1230
- }
1231
- }
1232
- return defaultValue;
1233
- }
1234
- function cleanText(input) {
1235
- // Replace delimiters with spaces and split
1236
- const str = assureString(input);
1237
- const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
1238
- return words;
1239
- }
1240
- function getCleanArray(obj) {
1241
- obj = obj.split(/\s+/) // Split on any whitespace
1242
- .filter((item) => typeof item === 'string' && item !== '');
1243
- // Get basename
1244
- // Remove duplicates using Set
1245
- const uniqueWords = cleanArray(obj);
1246
- return uniqueWords;
1247
- }
1248
-
1249
1281
  /**
1250
1282
  * In the browser we already have a WHATWG URL constructor on window.
1251
1283
  * Here we re-export it as “url” so other modules can import it.
@@ -1573,5 +1605,5 @@ function get_keyword_string(keywords) {
1573
1605
  return allString;
1574
1606
  }
1575
1607
 
1576
- export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, assureArray, assureString, callStorage, callWindowMethod, checkResponse, cleanArray, cleanText, create_list_string, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getBody, getCleanArray, getComponentsUtilsDirectory, getConfigContent, getConfigJson, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, 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, isTokenExpired, make_path, make_sanitized_path, normalizeUrl, parseResult, processKeywords, readJsonFile, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse };
1608
+ 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, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getBody, getCleanArray, getComponentsUtilsDirectory, getConfigContent, getConfigJson, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, 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, isTokenExpired, make_path, make_sanitized_path, normalizeUrl, parseResult, processKeywords, readJsonFile, removeToken, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse };
1577
1609
  //# sourceMappingURL=index.js.map