@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/cjs/index.js +94 -59
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +92 -60
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/types/functions/auth_utils/src/token_utils.d.ts +1 -0
- package/dist/types/functions/string_utils/src/string_utils.d.ts +2 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -143,6 +143,17 @@ function isLoggedIn() {
|
|
|
143
143
|
const tok = getToken();
|
|
144
144
|
return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
|
|
145
145
|
}
|
|
146
|
+
function removeToken() {
|
|
147
|
+
let is_logged = isLoggedIn();
|
|
148
|
+
if (is_logged) {
|
|
149
|
+
localStorage.removeItem("token");
|
|
150
|
+
}
|
|
151
|
+
is_logged = isLoggedIn();
|
|
152
|
+
if (is_logged) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
146
157
|
/**
|
|
147
158
|
* Add a Bearer Authorization header.
|
|
148
159
|
* A shallow copy of headers is returned so callers can keep chaining.
|
|
@@ -408,9 +419,6 @@ function getResult(obj) {
|
|
|
408
419
|
Object.prototype.hasOwnProperty.call(current, "result")) {
|
|
409
420
|
current = current.result;
|
|
410
421
|
}
|
|
411
|
-
if (current === null || current === void 0 ? void 0 : current.result) {
|
|
412
|
-
current = current.result;
|
|
413
|
-
}
|
|
414
422
|
return current;
|
|
415
423
|
}
|
|
416
424
|
// Determines HTTP method, defaults to GET or POST based on body
|
|
@@ -1064,6 +1072,62 @@ posix.posix = posix;
|
|
|
1064
1072
|
|
|
1065
1073
|
var pathBrowserify = posix;
|
|
1066
1074
|
|
|
1075
|
+
function ensure_list(obj) {
|
|
1076
|
+
const objArray = Array.isArray(obj) ? obj : [obj];
|
|
1077
|
+
return objArray;
|
|
1078
|
+
}
|
|
1079
|
+
function assureString(obj) {
|
|
1080
|
+
return String(obj);
|
|
1081
|
+
}
|
|
1082
|
+
function cleanArray(obj) {
|
|
1083
|
+
obj = assureArray(obj);
|
|
1084
|
+
return Array.from(new Set(obj));
|
|
1085
|
+
}
|
|
1086
|
+
function assureArray(input) {
|
|
1087
|
+
if (typeof input === 'string') {
|
|
1088
|
+
return [input];
|
|
1089
|
+
}
|
|
1090
|
+
if (Array.isArray(input)) {
|
|
1091
|
+
return input.map(item => assureString(item));
|
|
1092
|
+
}
|
|
1093
|
+
return [];
|
|
1094
|
+
}
|
|
1095
|
+
// Constrain T so 'in obj' is allowed
|
|
1096
|
+
function get_key_value(obj, key) {
|
|
1097
|
+
// we cast to any for the indexing, since TS can’t infer arbitrary string keys
|
|
1098
|
+
if (key in obj && obj[key] != null) {
|
|
1099
|
+
return obj[key];
|
|
1100
|
+
}
|
|
1101
|
+
return null;
|
|
1102
|
+
}
|
|
1103
|
+
function get(obj, keys, defaultValue = null) {
|
|
1104
|
+
const keyArray = assureArray(keys);
|
|
1105
|
+
if (!obj || keyArray.length === 0) {
|
|
1106
|
+
return defaultValue;
|
|
1107
|
+
}
|
|
1108
|
+
for (const key of keyArray) {
|
|
1109
|
+
const val = get_key_value(obj, key);
|
|
1110
|
+
if (val != null) {
|
|
1111
|
+
return val;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return defaultValue;
|
|
1115
|
+
}
|
|
1116
|
+
function cleanText(input) {
|
|
1117
|
+
// Replace delimiters with spaces and split
|
|
1118
|
+
const str = assureString(input);
|
|
1119
|
+
const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
|
|
1120
|
+
return words;
|
|
1121
|
+
}
|
|
1122
|
+
function getCleanArray(obj) {
|
|
1123
|
+
obj = obj.split(/\s+/) // Split on any whitespace
|
|
1124
|
+
.filter((item) => typeof item === 'string' && item !== '');
|
|
1125
|
+
// Get basename
|
|
1126
|
+
// Remove duplicates using Set
|
|
1127
|
+
const uniqueWords = cleanArray(obj);
|
|
1128
|
+
return uniqueWords;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1067
1131
|
function getSubstring(obj, maxLength = null, minLength = null) {
|
|
1068
1132
|
const objLength = obj.length;
|
|
1069
1133
|
const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
|
|
@@ -1084,6 +1148,30 @@ function truncateString(obj, maxLength = 20) {
|
|
|
1084
1148
|
}
|
|
1085
1149
|
return obj;
|
|
1086
1150
|
}
|
|
1151
|
+
function capitalize_str(string) {
|
|
1152
|
+
string = assureString(string);
|
|
1153
|
+
const string_len = string.length;
|
|
1154
|
+
let init_char = string.toUpperCase();
|
|
1155
|
+
if (string_len > 0) {
|
|
1156
|
+
init_char = string[0].toUpperCase();
|
|
1157
|
+
}
|
|
1158
|
+
let rest_chars = '';
|
|
1159
|
+
if (string_len > 1) {
|
|
1160
|
+
rest_chars = string.slice(1).toLowerCase();
|
|
1161
|
+
}
|
|
1162
|
+
const fin_chars = `${init_char}${rest_chars}`;
|
|
1163
|
+
return fin_chars;
|
|
1164
|
+
}
|
|
1165
|
+
function capitalize(string) {
|
|
1166
|
+
let nu_string = '';
|
|
1167
|
+
string = assureString(string);
|
|
1168
|
+
let objs = string.replace('-', '_').split('_');
|
|
1169
|
+
for (const obj of objs) {
|
|
1170
|
+
let str_obj = capitalize_str(obj);
|
|
1171
|
+
nu_string = `${nu_string} ${str_obj}`;
|
|
1172
|
+
}
|
|
1173
|
+
return eatAll(nu_string, [' ']);
|
|
1174
|
+
}
|
|
1087
1175
|
// string_utils/src/string_utils.ts
|
|
1088
1176
|
function stripPrefixes(str, bases = []) {
|
|
1089
1177
|
/* NEW: coerce whatever arrives into a string */
|
|
@@ -1193,62 +1281,6 @@ function create_list_string(array_obj) {
|
|
|
1193
1281
|
return string;
|
|
1194
1282
|
}
|
|
1195
1283
|
|
|
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
1284
|
/**
|
|
1253
1285
|
* In the browser we already have a WHATWG URL constructor on window.
|
|
1254
1286
|
* Here we re-export it as “url” so other modules can import it.
|
|
@@ -1608,6 +1640,8 @@ exports.assureArray = assureArray;
|
|
|
1608
1640
|
exports.assureString = assureString;
|
|
1609
1641
|
exports.callStorage = callStorage;
|
|
1610
1642
|
exports.callWindowMethod = callWindowMethod;
|
|
1643
|
+
exports.capitalize = capitalize;
|
|
1644
|
+
exports.capitalize_str = capitalize_str;
|
|
1611
1645
|
exports.checkResponse = checkResponse;
|
|
1612
1646
|
exports.cleanArray = cleanArray;
|
|
1613
1647
|
exports.cleanText = cleanText;
|
|
@@ -1688,6 +1722,7 @@ exports.normalizeUrl = normalizeUrl;
|
|
|
1688
1722
|
exports.parseResult = parseResult;
|
|
1689
1723
|
exports.processKeywords = processKeywords;
|
|
1690
1724
|
exports.readJsonFile = readJsonFile;
|
|
1725
|
+
exports.removeToken = removeToken;
|
|
1691
1726
|
exports.requireToken = requireToken;
|
|
1692
1727
|
exports.safeGlobalProp = safeGlobalProp;
|
|
1693
1728
|
exports.safeStorage = safeStorage;
|