@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 +21 -25
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +21 -25
- package/dist/esm/index.js.map +1 -1
- package/dist/types/functions/path_utils/src/path_utils.browser.d.ts +2 -0
- package/dist/types/functions/path_utils/src/path_utils.node.d.ts +2 -0
- package/dist/types/functions/read_utils/src/utils.browser.d.ts +3 -0
- package/package.json +15 -6
package/dist/esm/index.js
CHANGED
|
@@ -336,13 +336,12 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
336
336
|
function readJsonFile(relativeOrAbsolutePath) {
|
|
337
337
|
return __awaiter(this, void 0, void 0, function* () {
|
|
338
338
|
if (typeof window === 'undefined') {
|
|
339
|
-
// Node environment
|
|
340
339
|
try {
|
|
341
340
|
const { readFile } = yield import('fs/promises');
|
|
342
341
|
const { isAbsolute, resolve } = yield import('path');
|
|
343
342
|
const filePath = isAbsolute(relativeOrAbsolutePath)
|
|
344
343
|
? relativeOrAbsolutePath
|
|
345
|
-
: resolve(
|
|
344
|
+
: resolve(import.meta.url ? new URL('.', import.meta.url).pathname : '', relativeOrAbsolutePath);
|
|
346
345
|
const text = yield readFile(filePath, 'utf8');
|
|
347
346
|
return JSON.parse(text);
|
|
348
347
|
}
|
|
@@ -350,32 +349,26 @@ function readJsonFile(relativeOrAbsolutePath) {
|
|
|
350
349
|
return null;
|
|
351
350
|
}
|
|
352
351
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
}
|
|
352
|
+
// Browser fallback
|
|
353
|
+
const fetchFn = safeGlobalProp('fetch');
|
|
354
|
+
if (typeof fetchFn !== 'function')
|
|
355
|
+
return null;
|
|
356
|
+
let url = relativeOrAbsolutePath;
|
|
357
|
+
const baseURI = safeGlobalProp('document', 'baseURI');
|
|
358
|
+
if (baseURI) {
|
|
370
359
|
try {
|
|
371
|
-
|
|
372
|
-
if (!res.ok)
|
|
373
|
-
return null;
|
|
374
|
-
return yield res.json();
|
|
360
|
+
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
375
361
|
}
|
|
376
|
-
catch (
|
|
362
|
+
catch (_b) { }
|
|
363
|
+
}
|
|
364
|
+
try {
|
|
365
|
+
const res = yield fetchFn(url);
|
|
366
|
+
if (!res.ok)
|
|
377
367
|
return null;
|
|
378
|
-
|
|
368
|
+
return yield res.json();
|
|
369
|
+
}
|
|
370
|
+
catch (_c) {
|
|
371
|
+
return null;
|
|
379
372
|
}
|
|
380
373
|
});
|
|
381
374
|
}
|
|
@@ -1337,9 +1330,12 @@ function fileURLToPath(fileUrl) {
|
|
|
1337
1330
|
}
|
|
1338
1331
|
}
|
|
1339
1332
|
function getAbsolutePath() {
|
|
1333
|
+
if (typeof window !== 'undefined')
|
|
1334
|
+
return '';
|
|
1340
1335
|
return fileURLToPath(import.meta.url);
|
|
1341
1336
|
}
|
|
1342
1337
|
|
|
1338
|
+
// path_utils.browser.ts
|
|
1343
1339
|
function get_dirname(filePath) {
|
|
1344
1340
|
if (!filePath)
|
|
1345
1341
|
return '';
|