@putkoff/abstract-utilities 0.1.214 → 0.1.216
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
|
@@ -338,47 +338,47 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
338
338
|
*/
|
|
339
339
|
function readJsonFile(relativeOrAbsolutePath) {
|
|
340
340
|
return __awaiter(this, void 0, void 0, function* () {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
process.versions != null &&
|
|
344
|
-
process.versions.node) {
|
|
341
|
+
if (typeof window === 'undefined') {
|
|
342
|
+
// Node environment
|
|
345
343
|
try {
|
|
346
|
-
const
|
|
347
|
-
const
|
|
348
|
-
const filePath =
|
|
344
|
+
const { readFile } = yield import('fs/promises');
|
|
345
|
+
const { isAbsolute, resolve } = yield import('path');
|
|
346
|
+
const filePath = isAbsolute(relativeOrAbsolutePath)
|
|
349
347
|
? relativeOrAbsolutePath
|
|
350
|
-
:
|
|
351
|
-
const text = yield
|
|
348
|
+
: resolve(process.cwd(), relativeOrAbsolutePath);
|
|
349
|
+
const text = yield readFile(filePath, 'utf8');
|
|
352
350
|
return JSON.parse(text);
|
|
353
351
|
}
|
|
354
352
|
catch (_a) {
|
|
355
|
-
|
|
353
|
+
return null;
|
|
356
354
|
}
|
|
357
355
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
// Resolve URL against document.baseURI if possible
|
|
364
|
-
let url = relativeOrAbsolutePath;
|
|
365
|
-
const baseURI = safeGlobalProp('document', 'baseURI');
|
|
366
|
-
if (baseURI) {
|
|
367
|
-
try {
|
|
368
|
-
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
356
|
+
else {
|
|
357
|
+
// 2) Try browser fetch
|
|
358
|
+
const fetchFn = safeGlobalProp('fetch');
|
|
359
|
+
if (typeof fetchFn !== 'function') {
|
|
360
|
+
return null;
|
|
369
361
|
}
|
|
370
|
-
|
|
371
|
-
|
|
362
|
+
// Resolve URL against document.baseURI if possible
|
|
363
|
+
let url = relativeOrAbsolutePath;
|
|
364
|
+
const baseURI = safeGlobalProp('document', 'baseURI');
|
|
365
|
+
if (baseURI) {
|
|
366
|
+
try {
|
|
367
|
+
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
368
|
+
}
|
|
369
|
+
catch (_b) {
|
|
370
|
+
// keep url as-is
|
|
371
|
+
}
|
|
372
372
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
373
|
+
try {
|
|
374
|
+
const res = yield fetch(relativeOrAbsolutePath);
|
|
375
|
+
if (!res.ok)
|
|
376
|
+
return null;
|
|
377
|
+
return yield res.json();
|
|
378
|
+
}
|
|
379
|
+
catch (_c) {
|
|
377
380
|
return null;
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
catch (_c) {
|
|
381
|
-
return null;
|
|
381
|
+
}
|
|
382
382
|
}
|
|
383
383
|
});
|
|
384
384
|
}
|
|
@@ -1124,6 +1124,48 @@ function getCleanArray(obj) {
|
|
|
1124
1124
|
const uniqueWords = cleanArray(obj);
|
|
1125
1125
|
return uniqueWords;
|
|
1126
1126
|
}
|
|
1127
|
+
function isStrInString(obj, string) {
|
|
1128
|
+
const obj_str = assureString(obj).toLowerCase;
|
|
1129
|
+
string = assureString(string).toLowerCase;
|
|
1130
|
+
if (string.includes(obj_str)) {
|
|
1131
|
+
return true;
|
|
1132
|
+
}
|
|
1133
|
+
return false;
|
|
1134
|
+
}
|
|
1135
|
+
function getChar(i, string) {
|
|
1136
|
+
if (string.length >= i) {
|
|
1137
|
+
return assureString(string)[i];
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
function isType(obj, type) {
|
|
1141
|
+
if (typeof obj === type) {
|
|
1142
|
+
return true;
|
|
1143
|
+
}
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
function getNums() {
|
|
1147
|
+
return '0123456789';
|
|
1148
|
+
}
|
|
1149
|
+
function isNum(obj) {
|
|
1150
|
+
const is_num = isType(obj, 'number');
|
|
1151
|
+
if (is_num) {
|
|
1152
|
+
return is_num;
|
|
1153
|
+
}
|
|
1154
|
+
return isStrInString(obj, getNums());
|
|
1155
|
+
}
|
|
1156
|
+
function getAlphas() {
|
|
1157
|
+
return 'abcdefghijklmnopqrstuvwxyz';
|
|
1158
|
+
}
|
|
1159
|
+
function getAlphaNum(obj) {
|
|
1160
|
+
const is_num = isNum(obj);
|
|
1161
|
+
const alphas = getAlphas();
|
|
1162
|
+
if (is_num) {
|
|
1163
|
+
return getChar(obj, alphas);
|
|
1164
|
+
}
|
|
1165
|
+
if (isStrInString(obj, alphas)) {
|
|
1166
|
+
return getChar(obj, alphas);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1127
1169
|
|
|
1128
1170
|
function getSubstring(obj, maxLength = null, minLength = null) {
|
|
1129
1171
|
const objLength = obj.length;
|
|
@@ -1527,47 +1569,12 @@ function Spinner() {
|
|
|
1527
1569
|
*/
|
|
1528
1570
|
function getConfigJson() {
|
|
1529
1571
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1530
|
-
// Node environment: check if file exists
|
|
1531
|
-
if (typeof process !== 'undefined' &&
|
|
1532
|
-
process.versions != null &&
|
|
1533
|
-
process.versions.node) {
|
|
1534
|
-
try {
|
|
1535
|
-
// dynamically require fs to check existence
|
|
1536
|
-
const fs = yield import('fs');
|
|
1537
|
-
const path = yield import('path');
|
|
1538
|
-
const configPath = path.resolve(__dirname, 'config.json');
|
|
1539
|
-
if (fs.existsSync(configPath)) {
|
|
1540
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1541
|
-
return require(configPath);
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
catch (_a) {
|
|
1545
|
-
// fall through
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
// Browser or fallback: try fetching via HTTP
|
|
1549
|
-
const fetchFn = safeGlobalProp('fetch');
|
|
1550
|
-
if (typeof fetchFn === 'function') {
|
|
1551
|
-
try {
|
|
1552
|
-
const res = yield fetchFn('config.json');
|
|
1553
|
-
if (res.ok) {
|
|
1554
|
-
return (yield res.json());
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
catch (_b) {
|
|
1558
|
-
// ignore
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
// Node fallback: read from disk via readJsonFile
|
|
1562
1572
|
try {
|
|
1563
|
-
|
|
1564
|
-
return disk !== null && disk !== void 0 ? disk : {};
|
|
1573
|
+
return (yield readJsonFile('config.json')) || {};
|
|
1565
1574
|
}
|
|
1566
|
-
catch (
|
|
1567
|
-
|
|
1575
|
+
catch (_a) {
|
|
1576
|
+
return {};
|
|
1568
1577
|
}
|
|
1569
|
-
// final fallback
|
|
1570
|
-
return {};
|
|
1571
1578
|
});
|
|
1572
1579
|
}
|
|
1573
1580
|
|
|
@@ -1667,9 +1674,12 @@ exports.geTypeUtilsDirectory = geTypeUtilsDirectory;
|
|
|
1667
1674
|
exports.get = get;
|
|
1668
1675
|
exports.getAbsDir = getAbsDir;
|
|
1669
1676
|
exports.getAbsPath = getAbsPath;
|
|
1677
|
+
exports.getAlphaNum = getAlphaNum;
|
|
1678
|
+
exports.getAlphas = getAlphas;
|
|
1670
1679
|
exports.getAuthorizationHeader = getAuthorizationHeader;
|
|
1671
1680
|
exports.getBaseDir = getBaseDir;
|
|
1672
1681
|
exports.getBody = getBody;
|
|
1682
|
+
exports.getChar = getChar;
|
|
1673
1683
|
exports.getCleanArray = getCleanArray;
|
|
1674
1684
|
exports.getComponentsUtilsDirectory = getComponentsUtilsDirectory;
|
|
1675
1685
|
exports.getConfigContent = getConfigContent;
|
|
@@ -1688,6 +1698,7 @@ exports.getHooksUtilsDirectory = getHooksUtilsDirectory;
|
|
|
1688
1698
|
exports.getHtmlDirectory = getHtmlDirectory;
|
|
1689
1699
|
exports.getLibUtilsDirectory = getLibUtilsDirectory;
|
|
1690
1700
|
exports.getMethod = getMethod;
|
|
1701
|
+
exports.getNums = getNums;
|
|
1691
1702
|
exports.getPublicDir = getPublicDir;
|
|
1692
1703
|
exports.getResult = getResult;
|
|
1693
1704
|
exports.getSafeDocument = getSafeDocument;
|
|
@@ -1712,7 +1723,10 @@ exports.get_window_location = get_window_location;
|
|
|
1712
1723
|
exports.get_window_parts = get_window_parts;
|
|
1713
1724
|
exports.get_window_pathname = get_window_pathname;
|
|
1714
1725
|
exports.isLoggedIn = isLoggedIn;
|
|
1726
|
+
exports.isNum = isNum;
|
|
1727
|
+
exports.isStrInString = isStrInString;
|
|
1715
1728
|
exports.isTokenExpired = isTokenExpired;
|
|
1729
|
+
exports.isType = isType;
|
|
1716
1730
|
exports.make_path = make_path;
|
|
1717
1731
|
exports.make_sanitized_path = make_sanitized_path;
|
|
1718
1732
|
exports.normalizeUrl = normalizeUrl;
|