@pezkuwi/x-fetch 14.0.1

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @pezkuwi/x-fetch
2
+
3
+ A cross-environment fetch.
4
+
5
+ Install it via `yarn add @pezkuwi/x-fetch`
6
+
7
+ ```js
8
+ import { fetch } from '@pezkuwi/x-fetch';
9
+
10
+ ...
11
+ const response = await fetch('https://example.com/something.json');
12
+ const json = await response.json();
13
+ ```
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/pezkuwichain/pezkuwi-common/issues",
4
+ "description": "A cross-environment fetch replacement",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
8
+ "homepage": "https://github.com/pezkuwichain/pezkuwi-common/tree/master/packages/x-fetch#readme",
9
+ "license": "Apache-2.0",
10
+ "name": "@pezkuwi/x-fetch",
11
+ "repository": {
12
+ "directory": "packages/x-fetch",
13
+ "type": "git",
14
+ "url": "https://github.com/pezkuwichain/pezkuwi-common.git"
15
+ },
16
+ "sideEffects": false,
17
+ "type": "module",
18
+ "version": "14.0.1",
19
+ "browser": "browser.js",
20
+ "main": "node.js",
21
+ "react-native": "react-native.js",
22
+ "dependencies": {
23
+ "@pezkuwi/x-global": "14.0.1",
24
+ "node-fetch": "^3.3.2",
25
+ "tslib": "^2.8.0"
26
+ }
27
+ }
package/src/browser.ts ADDED
@@ -0,0 +1,8 @@
1
+ // Copyright 2017-2025 @polkadot/x-fetch authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { xglobal } from '@pezkuwi/x-global';
5
+
6
+ export { packageInfo } from './packageInfo.js';
7
+
8
+ export const fetch = xglobal.fetch;
package/src/mod.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Copyright 2017-2025 @polkadot/x-fetch authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './browser.js';
package/src/node.ts ADDED
@@ -0,0 +1,31 @@
1
+ // Copyright 2017-2025 @polkadot/x-fetch authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { extractGlobal } from '@pezkuwi/x-global';
5
+
6
+ export { packageInfo } from './packageInfo.js';
7
+
8
+ // This is an ESM module, use the async import(...) syntax to pull it
9
+ // in. Logically we would like it in nodeFetch(...) itself, however
10
+ // while it is all-ok on Node itself, it does create issues in Jest,
11
+ // possibly due to the Jest 28 need for --experimental-vm-modules
12
+ const importFetch = import('node-fetch').catch(() => null);
13
+
14
+ // keep track of the resolved import value
15
+ let modFn: typeof fetch | null = null;
16
+
17
+ async function nodeFetch (...args: Parameters<typeof fetch>): Promise<Response> {
18
+ if (!modFn) {
19
+ const mod = await importFetch;
20
+
21
+ if (!mod?.default) {
22
+ throw new Error('Unable to import node-fetch in this environment');
23
+ }
24
+
25
+ modFn = mod.default as unknown as typeof fetch;
26
+ }
27
+
28
+ return modFn(...args);
29
+ }
30
+
31
+ export const fetch = /*#__PURE__*/ extractGlobal('fetch', nodeFetch);
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2025 @polkadot/x-fetch authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @polkadot/dev
5
+
6
+ export const packageInfo = { name: '@polkadot/x-fetch', path: 'auto', type: 'auto', version: '14.0.1' };
@@ -0,0 +1,4 @@
1
+ // Copyright 2017-2025 @polkadot/x-fetch authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './browser.js';
package/src/shim.ts ADDED
@@ -0,0 +1,7 @@
1
+ // Copyright 2017-2025 @polkadot/x-fetch authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { fetch } from '@pezkuwi/x-fetch';
5
+ import { exposeGlobal } from '@pezkuwi/x-global';
6
+
7
+ exposeGlobal('fetch', fetch);
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "..",
5
+ "outDir": "./build",
6
+ "rootDir": "./src"
7
+ },
8
+ "exclude": [
9
+ "**/mod.ts"
10
+ ],
11
+ "references": [
12
+ { "path": "../x-global/tsconfig.build.json" }
13
+ ]
14
+ }