@putkoff/abstract-utilities 0.1.216 → 0.1.218

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
@@ -339,13 +339,12 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
339
339
  function readJsonFile(relativeOrAbsolutePath) {
340
340
  return __awaiter(this, void 0, void 0, function* () {
341
341
  if (typeof window === 'undefined') {
342
- // Node environment
343
342
  try {
344
343
  const { readFile } = yield import('fs/promises');
345
344
  const { isAbsolute, resolve } = yield import('path');
346
345
  const filePath = isAbsolute(relativeOrAbsolutePath)
347
346
  ? relativeOrAbsolutePath
348
- : resolve(process.cwd(), relativeOrAbsolutePath);
347
+ : resolve((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) ? new URL('.', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))).pathname : '', relativeOrAbsolutePath);
349
348
  const text = yield readFile(filePath, 'utf8');
350
349
  return JSON.parse(text);
351
350
  }
@@ -353,32 +352,26 @@ function readJsonFile(relativeOrAbsolutePath) {
353
352
  return null;
354
353
  }
355
354
  }
356
- else {
357
- // 2) Try browser fetch
358
- const fetchFn = safeGlobalProp('fetch');
359
- if (typeof fetchFn !== 'function') {
360
- return null;
361
- }
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
- }
355
+ // Browser fallback
356
+ const fetchFn = safeGlobalProp('fetch');
357
+ if (typeof fetchFn !== 'function')
358
+ return null;
359
+ let url = relativeOrAbsolutePath;
360
+ const baseURI = safeGlobalProp('document', 'baseURI');
361
+ if (baseURI) {
373
362
  try {
374
- const res = yield fetch(relativeOrAbsolutePath);
375
- if (!res.ok)
376
- return null;
377
- return yield res.json();
363
+ url = new URL(relativeOrAbsolutePath, baseURI).href;
378
364
  }
379
- catch (_c) {
365
+ catch (_b) { }
366
+ }
367
+ try {
368
+ const res = yield fetchFn(url);
369
+ if (!res.ok)
380
370
  return null;
381
- }
371
+ return yield res.json();
372
+ }
373
+ catch (_c) {
374
+ return null;
382
375
  }
383
376
  });
384
377
  }
@@ -1340,9 +1333,12 @@ function fileURLToPath(fileUrl) {
1340
1333
  }
1341
1334
  }
1342
1335
  function getAbsolutePath() {
1336
+ if (typeof window !== 'undefined')
1337
+ return '';
1343
1338
  return fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
1344
1339
  }
1345
1340
 
1341
+ // path_utils.browser.ts
1346
1342
  function get_dirname(filePath) {
1347
1343
  if (!filePath)
1348
1344
  return '';