@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/esm/index.js CHANGED
@@ -335,47 +335,47 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
335
335
  */
336
336
  function readJsonFile(relativeOrAbsolutePath) {
337
337
  return __awaiter(this, void 0, void 0, function* () {
338
- // 1) Try Node.js fs
339
- if (typeof process !== 'undefined' &&
340
- process.versions != null &&
341
- process.versions.node) {
338
+ if (typeof window === 'undefined') {
339
+ // Node environment
342
340
  try {
343
- const fs = yield import('fs');
344
- const path = yield import('path');
345
- const filePath = path.isAbsolute(relativeOrAbsolutePath)
341
+ const { readFile } = yield import('fs/promises');
342
+ const { isAbsolute, resolve } = yield import('path');
343
+ const filePath = isAbsolute(relativeOrAbsolutePath)
346
344
  ? relativeOrAbsolutePath
347
- : path.resolve(process.cwd(), relativeOrAbsolutePath);
348
- const text = yield fs.promises.readFile(filePath, 'utf8');
345
+ : resolve(process.cwd(), relativeOrAbsolutePath);
346
+ const text = yield readFile(filePath, 'utf8');
349
347
  return JSON.parse(text);
350
348
  }
351
349
  catch (_a) {
352
- // swallow and fall back to browser
350
+ return null;
353
351
  }
354
352
  }
355
- // 2) Try browser fetch
356
- const fetchFn = safeGlobalProp('fetch');
357
- if (typeof fetchFn !== 'function') {
358
- return null;
359
- }
360
- // Resolve URL against document.baseURI if possible
361
- let url = relativeOrAbsolutePath;
362
- const baseURI = safeGlobalProp('document', 'baseURI');
363
- if (baseURI) {
364
- try {
365
- url = new URL(relativeOrAbsolutePath, baseURI).href;
353
+ else {
354
+ // 2) Try browser fetch
355
+ const fetchFn = safeGlobalProp('fetch');
356
+ if (typeof fetchFn !== 'function') {
357
+ return null;
366
358
  }
367
- catch (_b) {
368
- // keep url as-is
359
+ // Resolve URL against document.baseURI if possible
360
+ let url = relativeOrAbsolutePath;
361
+ const baseURI = safeGlobalProp('document', 'baseURI');
362
+ if (baseURI) {
363
+ try {
364
+ url = new URL(relativeOrAbsolutePath, baseURI).href;
365
+ }
366
+ catch (_b) {
367
+ // keep url as-is
368
+ }
369
369
  }
370
- }
371
- try {
372
- const res = yield fetchFn(url);
373
- if (!res.ok)
370
+ try {
371
+ const res = yield fetch(relativeOrAbsolutePath);
372
+ if (!res.ok)
373
+ return null;
374
+ return yield res.json();
375
+ }
376
+ catch (_c) {
374
377
  return null;
375
- return (yield res.json());
376
- }
377
- catch (_c) {
378
- return null;
378
+ }
379
379
  }
380
380
  });
381
381
  }
@@ -1121,6 +1121,48 @@ function getCleanArray(obj) {
1121
1121
  const uniqueWords = cleanArray(obj);
1122
1122
  return uniqueWords;
1123
1123
  }
1124
+ function isStrInString(obj, string) {
1125
+ const obj_str = assureString(obj).toLowerCase;
1126
+ string = assureString(string).toLowerCase;
1127
+ if (string.includes(obj_str)) {
1128
+ return true;
1129
+ }
1130
+ return false;
1131
+ }
1132
+ function getChar(i, string) {
1133
+ if (string.length >= i) {
1134
+ return assureString(string)[i];
1135
+ }
1136
+ }
1137
+ function isType(obj, type) {
1138
+ if (typeof obj === type) {
1139
+ return true;
1140
+ }
1141
+ return false;
1142
+ }
1143
+ function getNums() {
1144
+ return '0123456789';
1145
+ }
1146
+ function isNum(obj) {
1147
+ const is_num = isType(obj, 'number');
1148
+ if (is_num) {
1149
+ return is_num;
1150
+ }
1151
+ return isStrInString(obj, getNums());
1152
+ }
1153
+ function getAlphas() {
1154
+ return 'abcdefghijklmnopqrstuvwxyz';
1155
+ }
1156
+ function getAlphaNum(obj) {
1157
+ const is_num = isNum(obj);
1158
+ const alphas = getAlphas();
1159
+ if (is_num) {
1160
+ return getChar(obj, alphas);
1161
+ }
1162
+ if (isStrInString(obj, alphas)) {
1163
+ return getChar(obj, alphas);
1164
+ }
1165
+ }
1124
1166
 
1125
1167
  function getSubstring(obj, maxLength = null, minLength = null) {
1126
1168
  const objLength = obj.length;
@@ -1524,47 +1566,12 @@ function Spinner() {
1524
1566
  */
1525
1567
  function getConfigJson() {
1526
1568
  return __awaiter(this, void 0, void 0, function* () {
1527
- // Node environment: check if file exists
1528
- if (typeof process !== 'undefined' &&
1529
- process.versions != null &&
1530
- process.versions.node) {
1531
- try {
1532
- // dynamically require fs to check existence
1533
- const fs = yield import('fs');
1534
- const path = yield import('path');
1535
- const configPath = path.resolve(__dirname, 'config.json');
1536
- if (fs.existsSync(configPath)) {
1537
- // eslint-disable-next-line @typescript-eslint/no-var-requires
1538
- return require(configPath);
1539
- }
1540
- }
1541
- catch (_a) {
1542
- // fall through
1543
- }
1544
- }
1545
- // Browser or fallback: try fetching via HTTP
1546
- const fetchFn = safeGlobalProp('fetch');
1547
- if (typeof fetchFn === 'function') {
1548
- try {
1549
- const res = yield fetchFn('config.json');
1550
- if (res.ok) {
1551
- return (yield res.json());
1552
- }
1553
- }
1554
- catch (_b) {
1555
- // ignore
1556
- }
1557
- }
1558
- // Node fallback: read from disk via readJsonFile
1559
1569
  try {
1560
- const disk = yield readJsonFile('config.json');
1561
- return disk !== null && disk !== void 0 ? disk : {};
1570
+ return (yield readJsonFile('config.json')) || {};
1562
1571
  }
1563
- catch (_c) {
1564
- // ignore
1572
+ catch (_a) {
1573
+ return {};
1565
1574
  }
1566
- // final fallback
1567
- return {};
1568
1575
  });
1569
1576
  }
1570
1577
 
@@ -1602,5 +1609,5 @@ function get_keyword_string(keywords) {
1602
1609
  return allString;
1603
1610
  }
1604
1611
 
1605
- 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 };
1612
+ 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, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfigContent, getConfigJson, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getNums, 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, isNum, isStrInString, isTokenExpired, isType, make_path, make_sanitized_path, normalizeUrl, parseResult, processKeywords, readJsonFile, removeToken, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse };
1606
1613
  //# sourceMappingURL=index.js.map