{"_id":"native-fetch","_rev":"4576669","name":"native-fetch","description":"Returns native fetch if available or the undici module if not","dist-tags":{"latest":"4.0.2"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"time":{"modified":"2026-04-10T15:44:56.000Z","created":"2018-11-13T02:44:59.872Z","4.0.2":"2021-12-13T11:15:37.848Z","4.0.1":"2021-12-13T11:09:51.820Z","4.0.0":"2021-11-17T18:14:38.830Z","3.0.0":"2021-02-03T13:40:57.535Z","2.0.1":"2020-10-06T14:49:24.525Z","2.0.0":"2020-09-03T06:46:48.557Z","1.0.0":"2018-11-13T03:18:15.770Z","0.0.0":"2018-11-13T02:44:59.872Z"},"users":{},"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"repository":{"type":"git","url":"git+https://github.com/achingbrain/native-fetch.git"},"versions":{"4.0.2":{"name":"native-fetch","version":"4.0.2","description":"Returns native fetch if available or the undici module if not","publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index-node.js","import":"./esm/src/index-node.js"}},"types":"./types/src/index.d.ts","typesVersions":{"*":{"src/*":["types/src/*","types/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"pretest":"npm run build","test":"npm run test:node && npm run test:browser && npm run test:electron-main && npm run test:electron-renderer","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:electron-main":"aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/**/*.spec.js","test:electron-renderer":"aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/**/*.spec.js","lint":"aegir ts -p check && aegir lint","release":"aegir release --docs --test false","release-minor":"aegir release --type minor --docs --test false","release-major":"aegir release --type major --docs --test false","build":"aegir build","dep-check":"aegir dep-check dist/src/**/*.js dist/test/**/*.js"},"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/achingbrain/native-fetch.git"},"peerDependencies":{"undici":"*"},"devDependencies":{"aegir":"^36.0.0","undici":"^4.10.0","native-fetch":"./dist"},"contributors":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"main":"./cjs/index.js","browser":{".":"./cjs/src/index.js","./esm/src/index-node.js":"./esm/src/index.js","./cjs/src/index-node.js":"./cjs/src/index.js"},"gitHead":"ee4766f1cca0faba4af60d1313d7f171bab64946","bugs":{"url":"https://github.com/achingbrain/native-fetch/issues"},"homepage":"https://github.com/achingbrain/native-fetch#readme","_id":"native-fetch@4.0.2","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"shasum":"75c8a44c5f3bb021713e5e24f2846750883e49af","size":3067,"noattachment":false,"key":"/native-fetch/-/native-fetch-4.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/native-fetch/download/native-fetch-4.0.2.tgz"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/native-fetch_4.0.2_1639394137723_0.11957646238593522"},"_hasShrinkwrap":false,"publish_time":1639394137848,"_cnpm_publish_time":1639394137848,"_cnpmcore_publish_time":"2021-12-16T13:35:36.899Z"},"4.0.1":{"name":"native-fetch","version":"4.0.1","description":"Returns native fetch if available or the undici module if not","publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index-node.js","import":"./esm/src/index-node.js"}},"types":"./types/index.d.ts","typesVersions":{"*":{"src/*":["types/src/*","types/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"pretest":"npm run build","test":"npm run test:node && npm run test:browser && npm run test:electron-main && npm run test:electron-renderer","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:electron-main":"aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/**/*.spec.js","test:electron-renderer":"aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/**/*.spec.js","lint":"aegir ts -p check && aegir lint","release":"aegir release --docs --test false","release-minor":"aegir release --type minor --docs --test false","release-major":"aegir release --type major --docs --test false","build":"aegir build","dep-check":"aegir dep-check dist/src/**/*.js dist/test/**/*.js"},"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/achingbrain/native-fetch.git"},"peerDependencies":{"undici":"*"},"devDependencies":{"aegir":"^36.0.0","undici":"^4.10.0","native-fetch":"./dist"},"contributors":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"main":"./cjs/index.js","browser":{".":"./cjs/src/index.js","./esm/src/index-node.js":"./esm/src/index.js","./cjs/src/index-node.js":"./cjs/src/index.js"},"gitHead":"d56681d7e54b270fb371dfda99b96e0959d4fba2","bugs":{"url":"https://github.com/achingbrain/native-fetch/issues"},"homepage":"https://github.com/achingbrain/native-fetch#readme","_id":"native-fetch@4.0.1","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"shasum":"98269ceb5724b3defc90699efdcd763485f3cf79","size":3066,"noattachment":false,"key":"/native-fetch/-/native-fetch-4.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/native-fetch/download/native-fetch-4.0.1.tgz"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/native-fetch_4.0.1_1639393791662_0.5489550041608962"},"_hasShrinkwrap":false,"publish_time":1639393791820,"_cnpm_publish_time":1639393791820,"_cnpmcore_publish_time":"2021-12-16T13:35:37.123Z"},"4.0.0":{"name":"native-fetch","version":"4.0.0","description":"Returns native fetch if available or the undici module if not","main":"src/index.js","types":"dist/src/index.d.ts","scripts":{"test":"aegir test -t node -t browser -t webworker -t electron-main -t electron-renderer","lint":"aegir lint && aegir ts -p check","build":"aegir build --no-bundle","release":"aegir release --docs false","release-minor":"aegir release --type minor --docs false","release-major":"aegir release --type major --docs false"},"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/achingbrain/native-fetch.git"},"peerDependencies":{"undici":"*"},"devDependencies":{"aegir":"^36.0.0","undici":"^4.10.0"},"contributors":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"gitHead":"141068da3c4cd3e837431209b67abbc20f4bb570","bugs":{"url":"https://github.com/achingbrain/native-fetch/issues"},"homepage":"https://github.com/achingbrain/native-fetch#readme","_id":"native-fetch@4.0.0","_nodeVersion":"16.11.1","_npmVersion":"8.0.0","dist":{"shasum":"f927ac02e97191be679ab3d1386a13bf7e8007a0","size":2151,"noattachment":false,"key":"/native-fetch/-/native-fetch-4.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/native-fetch/download/native-fetch-4.0.0.tgz"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/native-fetch_4.0.0_1637172878712_0.6474309811335079"},"_hasShrinkwrap":false,"publish_time":1637172878830,"_cnpm_publish_time":1637172878830,"_cnpmcore_publish_time":"2021-12-16T13:35:37.378Z"},"3.0.0":{"name":"native-fetch","version":"3.0.0","description":"Returns native fetch if available or the node-fetch module if not","main":"src/index.js","types":"dist/src/index.d.ts","scripts":{"test":"aegir test -t node -t browser -t webworker -t electron-main -t electron-renderer","lint":"aegir lint && aegir ts -p check","prepare":"aegir build --no-bundle","release":"aegir release --docs false","release-minor":"aegir release --type minor --docs false","release-major":"aegir release --type major --docs false"},"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/achingbrain/native-fetch.git"},"peerDependencies":{"node-fetch":"*"},"devDependencies":{"@types/node-fetch":"^2.5.8","aegir":"^30.3.0","node-fetch":"^2.6.0"},"contributors":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"gitHead":"2fc76e728222b6dded4c47862644701d1994c759","bugs":{"url":"https://github.com/achingbrain/native-fetch/issues"},"homepage":"https://github.com/achingbrain/native-fetch#readme","_id":"native-fetch@3.0.0","_nodeVersion":"14.15.4","_npmVersion":"6.14.10","dist":{"shasum":"06ccdd70e79e171c365c75117959cf4fe14a09bb","size":1872,"noattachment":false,"key":"/native-fetch/-/native-fetch-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/native-fetch/download/native-fetch-3.0.0.tgz"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/native-fetch_3.0.0_1612359657409_0.30413132505638996"},"_hasShrinkwrap":false,"publish_time":1612359657535,"_cnpm_publish_time":1612359657535,"_cnpmcore_publish_time":"2021-12-16T13:35:37.607Z"},"2.0.1":{"name":"native-fetch","version":"2.0.1","description":"Returns native fetch if available or the node-fetch module if not","main":"src/index.js","scripts":{"test":"aegir test -t node -t browser -t webworker -t electron-main -t electron-renderer","lint":"aegir lint","release":"aegir release --docs false","release-minor":"aegir release --type minor --docs false","release-major":"aegir release --type major --docs false"},"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/achingbrain/native-fetch.git"},"dependencies":{"globalthis":"^1.0.1"},"peerDependencies":{"node-fetch":"*"},"devDependencies":{"node-fetch":"^2.6.0","aegir":"^26.0.0"},"contributors":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"gitHead":"ce4ac1d1360e4c786fd6186bff35626da649ac7a","bugs":{"url":"https://github.com/achingbrain/native-fetch/issues"},"homepage":"https://github.com/achingbrain/native-fetch#readme","_id":"native-fetch@2.0.1","_nodeVersion":"12.16.1","_npmVersion":"6.14.1","dist":{"shasum":"319d53741a7040def92d5dc8ea5fe9416b1fad89","size":1657,"noattachment":false,"key":"/native-fetch/-/native-fetch-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/native-fetch/download/native-fetch-2.0.1.tgz"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/native-fetch_2.0.1_1601995764420_0.7925323883569839"},"_hasShrinkwrap":false,"publish_time":1601995764525,"_cnpm_publish_time":1601995764525,"_cnpmcore_publish_time":"2021-12-16T13:35:37.813Z"},"2.0.0":{"name":"native-fetch","version":"2.0.0","description":"Returns native fetch if available or the node-fetch module if not","main":"src/index.js","scripts":{"test":"aegir test -t node -t browser -t webworker -t electron-main -t electron-renderer","lint":"aegir lint","release":"aegir release --docs false","release-minor":"aegir release --type minor --docs false","release-major":"aegir release --type major --docs false"},"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/achingbrain/native-fetch.git"},"dependencies":{},"peerDependencies":{"node-fetch":"*"},"devDependencies":{"node-fetch":"^2.6.0","aegir":"^26.0.0","globalthis":"^1.0.1"},"contributors":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"gitHead":"8b78091e01c8449d7027fcd4caa08ff52b81403b","bugs":{"url":"https://github.com/achingbrain/native-fetch/issues"},"homepage":"https://github.com/achingbrain/native-fetch#readme","_id":"native-fetch@2.0.0","_nodeVersion":"12.16.1","_npmVersion":"6.14.1","dist":{"shasum":"3da4399676ec22546ea272684805c52ff95f97fa","size":1628,"noattachment":false,"key":"/native-fetch/-/native-fetch-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/native-fetch/download/native-fetch-2.0.0.tgz"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/native-fetch_2.0.0_1599115608455_0.15209587673244163"},"_hasShrinkwrap":false,"publish_time":1599115608557,"_cnpm_publish_time":1599115608557,"_cnpmcore_publish_time":"2021-12-16T13:35:38.056Z"},"1.0.0":{"name":"native-fetch","version":"1.0.0","keywords":["native-http","react-native","http","http-source","source","fetch"],"description":"","license":"MIT","author":{"name":"Patrik Šimunič","email":"patriksimunic@hotmail.com"},"repository":{"type":"git","url":"git+https://github.com/7h3w4rd0c70r/native-fetch.git"},"bug":"https://github.com/7h3w4rd0c70r/native-fetch/issues","main":"dist/index.js","jsnext:main":"dist/index.js","browser":"dist/index.js","module":"dist/index.js","types":"./index.d.ts","scripts":{"build":"tsc"},"devDependencies":{"@types/lodash":"^4.14.118","@types/react-native":"^0.57.7","typescript":"^3.1.6"},"dependencies":{"lodash":"^4.17.11"},"bugs":{"url":"https://github.com/7h3w4rd0c70r/native-fetch/issues"},"homepage":"https://github.com/7h3w4rd0c70r/native-fetch#readme","_id":"native-fetch@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.10.0","_npmUser":{"name":"7h3w4rd0c70r","email":"patriksimunic@hotmail.com"},"dist":{"shasum":"58a10c32f2713a679d669d0c849524c7aceaed83","size":4069,"noattachment":false,"key":"/native-fetch/-/native-fetch-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/native-fetch/download/native-fetch-1.0.0.tgz"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/native-fetch_1.0.0_1542079095589_0.6637987470214062"},"_hasShrinkwrap":false,"publish_time":1542079095770,"_cnpm_publish_time":1542079095770,"_cnpmcore_publish_time":"2021-12-16T13:35:38.265Z"},"0.0.0":{"name":"native-fetch","version":"0.0.0","keywords":["native-http","react-native","http","http-source","source","fetch"],"description":"","license":"MIT","author":{"name":"Patrik Šimunič","email":"patriksimunic@hotmail.com"},"repository":{"type":"git","url":"git+https://github.com/7h3w4rd0c70r/native-fetch.git"},"bug":"https://github.com/7h3w4rd0c70r/native-fetch/issues","main":"dist/index.js","jsnext:main":"dist/index.js","browser":"dist/index.js","module":"dist/index.js","types":"./index.d.ts","scripts":{"build":"tsc"},"devDependencies":{"@types/react-native":"^0.57.7","typescript":"^3.1.6"},"bugs":{"url":"https://github.com/7h3w4rd0c70r/native-fetch/issues"},"homepage":"https://github.com/7h3w4rd0c70r/native-fetch#readme","_id":"native-fetch@0.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.10.0","_npmUser":{"name":"7h3w4rd0c70r","email":"patriksimunic@hotmail.com"},"dist":{"shasum":"0d6c663fec054d97129dd61d0ae24df1f639047f","size":1724,"noattachment":false,"key":"/native-fetch/-/native-fetch-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/native-fetch/download/native-fetch-0.0.0.tgz"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/native-fetch_0.0.0_1542077099738_0.02491164552516767"},"_hasShrinkwrap":false,"publish_time":1542077099872,"_cnpm_publish_time":1542077099872,"_cnpmcore_publish_time":"2021-12-16T13:35:38.497Z"}},"readme":"# native-fetch\n\n> Returns native fetch/Request/Headers if available or the `undici` module if not\n\nAn (almost) drop-in replacement for the `undici` module that returns the native fetch if available or the polyfill if not.\n\n### Why?\n\nSome environments such as the Electron Renderer process straddle the node/browser divide with features from both APIs available.  In these cases the webpack approach of always using the `browser` field in your `package.json` to override requires is too heavy-handed as sometimes you want to use the node version of an API.\n\nInstead we can check for the availability of a given API and return it, rather than the node-polyfill for that API.\n\n### Why Undici and not node-fetch?\n\n[node-fetch](https://www.npmjs.com/package/node-fetch) is the OG fetch implementation for node, but it uses [Node.js streams](https://nodejs.org/api/stream.html) instead of [WHATWG streams](https://streams.spec.whatwg.org/). This means the APIs are not the same which leads to all sorts of weird shenanigans with types.\n\n[undici](https://www.npmjs.com/package/undici) is the new kid on the block and uses WHATWG streams so all of the APIs now live in glorious harmony.\n\nIf you are trying to write polymorphic code with strong typing this is a big deal.\n\n## Install\n\nYou must install a version of `undici` [alongside this module](https://docs.npmjs.com/files/package.json#peerdependencies) to be used if a native implementation is not available.\n\n```console\n$ npm install --save native-fetch undici\n```\n\n## Usage\n\n```javascript\nconst { fetch } = require('native-fetch')\n\nfetch('https://github.com/')\n    .then(res => res.text())\n    .then(body => console.log(body))\n```\n","_attachments":{},"homepage":"https://github.com/achingbrain/native-fetch#readme","bugs":{"url":"https://github.com/achingbrain/native-fetch/issues"},"license":"MIT"}