@putkoff/abstract-utilities 0.1.195 → 0.1.198
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 +113 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +105 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +32 -2
- package/dist/types/functions/index.d.ts +1 -0
- package/dist/types/functions/path_utils/src/path_utils.d.ts +8 -1
- package/dist/types/functions/type_utils/src/type_utils.d.ts +7 -0
- package/dist/types/functions/variable_utils/imports.d.ts +1 -0
- package/dist/types/functions/variable_utils/index.d.ts +1 -0
- package/dist/types/functions/variable_utils/src/index.d.ts +1 -0
- package/dist/types/functions/variable_utils/src/variable_utils.d.ts +15 -0
- package/package.json +74 -89
package/dist/cjs/index.js
CHANGED
|
@@ -1191,6 +1191,57 @@ function ensure_list(obj) {
|
|
|
1191
1191
|
const objArray = Array.isArray(obj) ? obj : [obj];
|
|
1192
1192
|
return objArray;
|
|
1193
1193
|
}
|
|
1194
|
+
function assureString(obj) {
|
|
1195
|
+
return String(obj);
|
|
1196
|
+
}
|
|
1197
|
+
function cleanArray(obj) {
|
|
1198
|
+
obj = assureArray(obj);
|
|
1199
|
+
return Array.from(new Set(obj));
|
|
1200
|
+
}
|
|
1201
|
+
function assureArray(input) {
|
|
1202
|
+
if (typeof input === 'string') {
|
|
1203
|
+
return [input];
|
|
1204
|
+
}
|
|
1205
|
+
if (Array.isArray(input)) {
|
|
1206
|
+
return input.map(item => assureString(item));
|
|
1207
|
+
}
|
|
1208
|
+
return [];
|
|
1209
|
+
}
|
|
1210
|
+
// Constrain T so 'in obj' is allowed
|
|
1211
|
+
function get_key_value(obj, key) {
|
|
1212
|
+
// we cast to any for the indexing, since TS can’t infer arbitrary string keys
|
|
1213
|
+
if (key in obj && obj[key] != null) {
|
|
1214
|
+
return obj[key];
|
|
1215
|
+
}
|
|
1216
|
+
return null;
|
|
1217
|
+
}
|
|
1218
|
+
function get(obj, keys, defaultValue = null) {
|
|
1219
|
+
const keyArray = assureArray(keys);
|
|
1220
|
+
if (!obj || keyArray.length === 0) {
|
|
1221
|
+
return defaultValue;
|
|
1222
|
+
}
|
|
1223
|
+
for (const key of keyArray) {
|
|
1224
|
+
const val = get_key_value(obj, key);
|
|
1225
|
+
if (val != null) {
|
|
1226
|
+
return val;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
return defaultValue;
|
|
1230
|
+
}
|
|
1231
|
+
function cleanText(input) {
|
|
1232
|
+
// Replace delimiters with spaces and split
|
|
1233
|
+
const str = assureString(input);
|
|
1234
|
+
const words = str.replace(/[_.-]/g, ' '); // Replace _, -, . with space
|
|
1235
|
+
return words;
|
|
1236
|
+
}
|
|
1237
|
+
function getCleanArray(obj) {
|
|
1238
|
+
obj = obj.split(/\s+/) // Split on any whitespace
|
|
1239
|
+
.filter((item) => typeof item === 'string' && item !== '');
|
|
1240
|
+
// Get basename
|
|
1241
|
+
// Remove duplicates using Set
|
|
1242
|
+
const uniqueWords = cleanArray(obj);
|
|
1243
|
+
return uniqueWords;
|
|
1244
|
+
}
|
|
1194
1245
|
|
|
1195
1246
|
/**
|
|
1196
1247
|
* In the browser we already have a WHATWG URL constructor on window.
|
|
@@ -1242,21 +1293,33 @@ function get_splitext(filePath) {
|
|
|
1242
1293
|
const filename = pathBrowserify.basename(filePath, ext);
|
|
1243
1294
|
return { filename, ext };
|
|
1244
1295
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1296
|
+
/**
|
|
1297
|
+
* Join multiple path segments, normalizing leading/trailing slashes.
|
|
1298
|
+
*
|
|
1299
|
+
* Usage:
|
|
1300
|
+
* make_path('/foo','bar','baz')
|
|
1301
|
+
* make_path(['/foo','bar','baz'])
|
|
1302
|
+
*/
|
|
1303
|
+
function make_path(...paths) {
|
|
1304
|
+
// If someone passed a single array, unwrap it:
|
|
1305
|
+
const pathArray = (paths.length === 1 && Array.isArray(paths[0])
|
|
1306
|
+
? paths[0]
|
|
1307
|
+
: paths);
|
|
1247
1308
|
let real_path = '';
|
|
1248
|
-
for (let i = 0; i <
|
|
1249
|
-
let segment =
|
|
1309
|
+
for (let i = 0; i < pathArray.length; i++) {
|
|
1310
|
+
let segment = pathArray[i];
|
|
1250
1311
|
if (i === 0) {
|
|
1251
1312
|
real_path = segment;
|
|
1252
1313
|
}
|
|
1253
1314
|
else {
|
|
1254
|
-
|
|
1255
|
-
|
|
1315
|
+
// remove any leading slash on this segment
|
|
1316
|
+
segment = segment.replace(/^\/+/, '');
|
|
1317
|
+
// remove any trailing slash on the accumulator
|
|
1318
|
+
real_path = real_path.replace(/\/+$/, '');
|
|
1256
1319
|
real_path = `${real_path}/${segment}`;
|
|
1257
1320
|
}
|
|
1258
1321
|
}
|
|
1259
|
-
return real_path
|
|
1322
|
+
return real_path;
|
|
1260
1323
|
}
|
|
1261
1324
|
function sanitizeFilename(filename) {
|
|
1262
1325
|
return filename
|
|
@@ -1495,6 +1558,40 @@ function getConfig(key) {
|
|
|
1495
1558
|
});
|
|
1496
1559
|
}
|
|
1497
1560
|
|
|
1561
|
+
/**
|
|
1562
|
+
* Processes keywords by checking if keywords is a string and splitting it.
|
|
1563
|
+
* Then cleans each keyword using `eatAll` with a set of characters to remove.
|
|
1564
|
+
*
|
|
1565
|
+
* @param keywords - The keywords as a comma-separated string or as an array.
|
|
1566
|
+
* @returns An array of cleaned keywords.
|
|
1567
|
+
*/
|
|
1568
|
+
function processKeywords(keywords) {
|
|
1569
|
+
let keywordArray;
|
|
1570
|
+
// If keywords is a string, split it on commas
|
|
1571
|
+
if (typeof keywords === "string") {
|
|
1572
|
+
keywordArray = keywords.split(",");
|
|
1573
|
+
}
|
|
1574
|
+
else {
|
|
1575
|
+
keywordArray = keywords;
|
|
1576
|
+
}
|
|
1577
|
+
// Clean each keyword by removing unwanted characters
|
|
1578
|
+
return keywordArray.map(keyword => eatAll(keyword, [",", "\n", "\t", " ", "#"]));
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Constructs a keyword string where each keyword is prefixed with a hash (#).
|
|
1582
|
+
*
|
|
1583
|
+
* @param keywords - An array of keywords.
|
|
1584
|
+
* @returns A string with each keyword prefixed by '#'.
|
|
1585
|
+
*/
|
|
1586
|
+
function get_keyword_string(keywords) {
|
|
1587
|
+
keywords = processKeywords(keywords);
|
|
1588
|
+
let allString = "";
|
|
1589
|
+
for (const keyword of keywords) {
|
|
1590
|
+
allString += ` #${keyword}`;
|
|
1591
|
+
}
|
|
1592
|
+
return allString;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1498
1595
|
Object.defineProperty(exports, "useCallback", {
|
|
1499
1596
|
enumerable: true,
|
|
1500
1597
|
get: function () { return react.useCallback; }
|
|
@@ -1523,9 +1620,13 @@ exports.PROTOCOL = PROTOCOL;
|
|
|
1523
1620
|
exports.SUB_DIR = SUB_DIR;
|
|
1524
1621
|
exports.Spinner = Spinner;
|
|
1525
1622
|
exports.alertit = alertit;
|
|
1623
|
+
exports.assureArray = assureArray;
|
|
1624
|
+
exports.assureString = assureString;
|
|
1526
1625
|
exports.callStorage = callStorage;
|
|
1527
1626
|
exports.callWindowMethod = callWindowMethod;
|
|
1528
1627
|
exports.checkResponse = checkResponse;
|
|
1628
|
+
exports.cleanArray = cleanArray;
|
|
1629
|
+
exports.cleanText = cleanText;
|
|
1529
1630
|
exports.create_list_string = create_list_string;
|
|
1530
1631
|
exports.currentUsername = currentUsername;
|
|
1531
1632
|
exports.currentUsernames = currentUsernames;
|
|
@@ -1548,11 +1649,13 @@ exports.gePathUtilsDirectory = gePathUtilsDirectory;
|
|
|
1548
1649
|
exports.geStaticDirectory = geStaticDirectory;
|
|
1549
1650
|
exports.geStringUtilsDirectory = geStringUtilsDirectory;
|
|
1550
1651
|
exports.geTypeUtilsDirectory = geTypeUtilsDirectory;
|
|
1652
|
+
exports.get = get;
|
|
1551
1653
|
exports.getAbsDir = getAbsDir;
|
|
1552
1654
|
exports.getAbsPath = getAbsPath;
|
|
1553
1655
|
exports.getAuthorizationHeader = getAuthorizationHeader;
|
|
1554
1656
|
exports.getBaseDir = getBaseDir;
|
|
1555
1657
|
exports.getBody = getBody;
|
|
1658
|
+
exports.getCleanArray = getCleanArray;
|
|
1556
1659
|
exports.getComponentsUtilsDirectory = getComponentsUtilsDirectory;
|
|
1557
1660
|
exports.getConfig = getConfig;
|
|
1558
1661
|
exports.getConfigContent = getConfigContent;
|
|
@@ -1586,6 +1689,8 @@ exports.get_basename = get_basename;
|
|
|
1586
1689
|
exports.get_dirname = get_dirname;
|
|
1587
1690
|
exports.get_extname = get_extname;
|
|
1588
1691
|
exports.get_filename = get_filename;
|
|
1692
|
+
exports.get_key_value = get_key_value;
|
|
1693
|
+
exports.get_keyword_string = get_keyword_string;
|
|
1589
1694
|
exports.get_splitext = get_splitext;
|
|
1590
1695
|
exports.get_window = get_window;
|
|
1591
1696
|
exports.get_window_location = get_window_location;
|
|
@@ -1598,6 +1703,7 @@ exports.make_path = make_path;
|
|
|
1598
1703
|
exports.make_sanitized_path = make_sanitized_path;
|
|
1599
1704
|
exports.normalizeUrl = normalizeUrl;
|
|
1600
1705
|
exports.parseResult = parseResult;
|
|
1706
|
+
exports.processKeywords = processKeywords;
|
|
1601
1707
|
exports.readJsonFile = readJsonFile;
|
|
1602
1708
|
exports.requireToken = requireToken;
|
|
1603
1709
|
exports.safeGlobalProp = safeGlobalProp;
|