@putkoff/abstract-utilities 0.1.200 → 0.1.201

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
@@ -1484,74 +1484,52 @@ function Spinner() {
1484
1484
  }
1485
1485
 
1486
1486
  // src/functions/config_utils/src/config_utils.ts
1487
- let _cachedConfig = null;
1488
- function loadConfig() {
1489
- return __awaiter(this, arguments, void 0, function* (filePath = null) {
1490
- var _a;
1491
- if (_cachedConfig) {
1492
- return _cachedConfig;
1493
- }
1494
- // 1) figure out where config.json lives
1495
- let configUrl;
1496
- if (filePath) {
1497
- configUrl = filePath;
1498
- }
1499
- else if (typeof import.meta !== 'undefined' && typeof import.meta.url === 'string') {
1500
- // ES module: resolve relative to this file
1501
- try {
1502
- configUrl = new URL('./config.json', import.meta.url).href;
1503
- }
1504
- catch (_b) {
1505
- configUrl = 'config.json';
1506
- }
1507
- }
1508
- else {
1509
- // browser fallback
1510
- const baseURI = safeGlobalProp('document', 'baseURI');
1487
+ /**
1488
+ * Attempt to load config.json if present, otherwise return empty object.
1489
+ */
1490
+ function getConfigJson() {
1491
+ return __awaiter(this, void 0, void 0, function* () {
1492
+ // Node environment: check if file exists
1493
+ if (typeof process !== 'undefined' &&
1494
+ process.versions != null &&
1495
+ process.versions.node) {
1511
1496
  try {
1512
- configUrl =
1513
- typeof baseURI === 'string'
1514
- ? new URL('config.json', baseURI).href
1515
- : 'config.json';
1497
+ // dynamically require fs to check existence
1498
+ const fs = yield import('fs');
1499
+ const path = yield import('path');
1500
+ const configPath = path.resolve(__dirname, 'config.json');
1501
+ if (fs.existsSync(configPath)) {
1502
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
1503
+ return require(configPath);
1504
+ }
1516
1505
  }
1517
- catch (_c) {
1518
- configUrl = 'config.json';
1506
+ catch (_a) {
1507
+ // fall through
1519
1508
  }
1520
1509
  }
1521
- // 2) if we have a fetch, try HTTP(S)
1510
+ // Browser or fallback: try fetching via HTTP
1522
1511
  const fetchFn = safeGlobalProp('fetch');
1523
1512
  if (typeof fetchFn === 'function') {
1524
1513
  try {
1525
- const res = yield fetchFn(configUrl);
1514
+ const res = yield fetchFn('config.json');
1526
1515
  if (res.ok) {
1527
- const json = yield res.json();
1528
- // cache & return
1529
- _cachedConfig = (_a = json) !== null && _a !== void 0 ? _a : {};
1530
- return _cachedConfig;
1516
+ return (yield res.json());
1531
1517
  }
1532
1518
  }
1533
- catch (_d) {
1534
- /* swallow */
1519
+ catch (_b) {
1520
+ // ignore
1535
1521
  }
1536
1522
  }
1537
- // 3) Node fallback: try reading from disk (requires your readJsonFile util)
1523
+ // Node fallback: read from disk via readJsonFile
1538
1524
  try {
1539
- const disk = yield readJsonFile(configUrl);
1540
- _cachedConfig = disk !== null && disk !== void 0 ? disk : {};
1541
- return _cachedConfig;
1525
+ const disk = yield readJsonFile('config.json');
1526
+ return disk !== null && disk !== void 0 ? disk : {};
1542
1527
  }
1543
- catch (_e) {
1544
- /* swallow */
1528
+ catch (_c) {
1529
+ // ignore
1545
1530
  }
1546
- // 4) if all else fails, return an empty config
1547
- _cachedConfig = {};
1548
- return _cachedConfig;
1549
- });
1550
- }
1551
- function getConfig(key) {
1552
- return __awaiter(this, void 0, void 0, function* () {
1553
- const cfg = yield loadConfig();
1554
- return key != null ? cfg[key] : cfg;
1531
+ // final fallback
1532
+ return {};
1555
1533
  });
1556
1534
  }
1557
1535
 
@@ -1589,5 +1567,5 @@ function get_keyword_string(keywords) {
1589
1567
  return allString;
1590
1568
  }
1591
1569
 
1592
- 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, getConfig, getConfigContent, 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, loadConfig, make_path, make_sanitized_path, normalizeUrl, parseResult, processKeywords, readJsonFile, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse };
1570
+ 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 };
1593
1571
  //# sourceMappingURL=index.js.map