@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 +13 -0
- package/package.json +27 -0
- package/src/browser.ts +8 -0
- package/src/mod.ts +4 -0
- package/src/node.ts +31 -0
- package/src/packageInfo.ts +6 -0
- package/src/react-native.ts +4 -0
- package/src/shim.ts +7 -0
- package/tsconfig.build.json +14 -0
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
package/src/mod.ts
ADDED
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);
|
package/src/shim.ts
ADDED