{"name":"cross-fetch","version":"3.2.0-alpha.2","description":"Universal WHATWG Fetch API for Node, Browsers and React Native","homepage":"https://github.com/lquixada/cross-fetch","main":"dist/node-ponyfill.js","browser":"dist/browser-ponyfill.js","react-native":"dist/react-native-ponyfill.js","types":"index.d.ts","scripts":{"prepare":"husky install","prepublishOnly":"rimraf dist && make dist"},"lint-staged":{"*.js":["make build","standard --fix"]},"standard":{"env":["mocha","browser"],"globals":["expect","assert","chai"],"ignore":["/dist/","bundle.js","test.js","test.*.js","api.spec.js","*.ts"]},"mocha":{"require":["chai/register-expect","chai/register-assert"],"check-leaks":true},"nyc":{"temp-dir":".reports/.coverage"},"commitlint":{"extends":["@commitlint/config-conventional"]},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"standard-version":{"skip":{"changelog":true}},"repository":{"type":"git","url":"git+https://github.com/lquixada/cross-fetch.git"},"author":{"name":"Leonardo Quixada","email":"lquixada@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/lquixada/cross-fetch/issues"},"dependencies":{"node-fetch":"2.6.5"},"devDependencies":{"@commitlint/cli":"12.0.1","@commitlint/config-conventional":"12.0.1","@types/chai":"4.2.22","@types/mocha":"8.2.2","@types/node":"14.14.37","body-parser":"1.19.0","chai":"4.3.4","codecov":"3.8.3","cz-conventional-changelog":"3.3.0","express":"4.17.1","husky":"6.0.0","lint-staged":"10.5.4","mocha":"8.3.2","mocha-headless-chrome":"3.1.0","nock":"13.1.3","nyc":"15.1.0","open-cli":"6.0.1","rimraf":"3.0.2","rollup":"2.58.0","rollup-plugin-copy":"3.4.0","rollup-plugin-terser":"7.0.2","semver":"7.3.5","serve-index":"1.9.1","standard":"16.0.4","standard-version":"9.3.1","typescript":"4.4.4","webpack":"5.58.2","webpack-cli":"4.9.0","whatwg-fetch":"3.6.2","yargs":"16.2.0"},"keywords":["fetch","http","url","promise","async","await","isomorphic","universal","node","react","native","browser","ponyfill","whatwg","xhr","ajax"],"readme":"cross-fetch<br>\n[![NPM Version](https://img.shields.io/npm/v/cross-fetch.svg?branch=main)](https://www.npmjs.com/package/cross-fetch)\n[![Downloads Per Week](https://img.shields.io/npm/dw/cross-fetch.svg?color=blue)](https://www.npmjs.com/package/cross-fetch)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n![CI](https://github.com/lquixada/cross-fetch/workflows/CI/badge.svg)\n[![codecov](https://codecov.io/gh/lquixada/cross-fetch/branch/main/graph/badge.svg)](https://codecov.io/gh/lquixada/cross-fetch)\n================\n\nUniversal WHATWG Fetch API for Node, Browsers and React Native. The scenario that cross-fetch really shines is when the same JavaScript codebase needs to run on different platforms.\n\n- **Platform agnostic**: browsers, Node or React Native\n- **Optional polyfill**: it's up to you if something is going to be added to the global object or not\n- **Simple interface**: no instantiation, no configuration and no extra dependency\n- **WHATWG compliant**: it works the same way wherever your code runs\n- **TypeScript support**: better development experience with types.\n\n\n* * *\n\n## Table of Contents\n\n-   [Install](#install)\n-   [Usage](#usage)\n-   [Demo & API](#demo--api)\n-   [FAQ](#faq)\n-   [Thanks](#thanks)\n-   [License](#license)\n-   [Author](#author)\n\n* * *\n\n## Install\n\n```sh\nnpm install --save cross-fetch\n```\n\nAs a [ponyfill](https://github.com/sindresorhus/ponyfill):\n\n```javascript\n// Using ES6 modules with Babel or TypeScript\nimport fetch from 'cross-fetch';\n\n// Using CommonJS modules\nconst fetch = require('cross-fetch');\n```\n\nAs a polyfill:\n\n```javascript\n// Using ES6 modules\nimport 'cross-fetch/polyfill';\n\n// Using CommonJS modules\nrequire('cross-fetch/polyfill');\n```\n\n\nThe CDN build is also available on unpkg:\n\n```html\n<script src=\"//unpkg.com/cross-fetch/dist/cross-fetch.js\"></script>\n```\n\nThis adds the fetch function to the window object. Note that this is not UMD compatible.\n\n\n* * *\n\n## Usage\n\nWith [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise):\n\n```javascript\nimport fetch from 'cross-fetch';\n// Or just: import 'cross-fetch/polyfill';\n\nfetch('//api.github.com/users/lquixada')\n  .then(res => {\n    if (res.status >= 400) {\n      throw new Error(\"Bad response from server\");\n    }\n    return res.json();\n  })\n  .then(user => {\n    console.log(user);\n  })\n  .catch(err => {\n    console.error(err);\n  });\n```\n\nWith [async/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function):\n\n```javascript\nimport fetch from 'cross-fetch';\n// Or just: import 'cross-fetch/polyfill';\n\n(async () => {\n  try {\n    const res = await fetch('//api.github.com/users/lquixada');\n    \n    if (res.status >= 400) {\n      throw new Error(\"Bad response from server\");\n    }\n    \n    const user = await res.json();\n  \n    console.log(user);\n  } catch (err) {\n    console.error(err);\n  }\n})();\n```\n\n> ⚠️ **Warning**: If you're in an environment that doesn't support Promises such as Internet Explorer, you must install an ES6 Promise compatible polyfill. [es6-promise](https://github.com/jakearchibald/es6-promise) is suggested.\n\n\n## Demo & API\n\nYou can find a comprehensive doc at [Github's fetch](https://github.github.io/fetch/) page. If you want to play with cross-fetch, check our [**JSFiddle playground**](https://jsfiddle.net/lquixada/3ypqgacp/).\n\n> **Tip**: Run the fiddle on various browsers and with different settings (for instance: cross-domain requests, wrong urls or text requests). Don't forget to open the console in the test suite page and play around.\n\n\n## FAQ\n\n#### Yet another fetch library?\n\nI did a lot of research in order to find a fetch library that could be simple, cross-platform and provide polyfill as an option. There's a plethora of libs out there but none could match those requirements.\n\n\n#### Why not isomorphic-fetch?\n\nMy preferred library used to be [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch) but it has this [bug](https://github.com/matthew-andrews/isomorphic-fetch/issues/125) that prevents it from running in a react native environment. It seems unlikely to be fixed since there haven't been any new commits to it since 2016. That means dependencies are outdated as well. \n\n\n#### Why polyfill might not be a good idea?\n\nIn a word? Risk. If the spec changes in the future, it might be problematic to debug. Read more about it on [sindresorhus's ponyfill](https://github.com/sindresorhus/ponyfill#how-are-ponyfills-better-than-polyfills) page. It's up to you if you're fine with it or not.\n\n\n#### How does cross-fetch work?\n\nJust like isomorphic-fetch, it is just a proxy. If you're in node, it delivers you the [node-fetch](https://github.com/bitinn/node-fetch/) library, if you're in a browser or React Native, it delivers you the github's [whatwg-fetch](https://github.com/github/fetch/). The same strategy applies whether you're using polyfill or ponyfill.\n\n\n## Who's Using It?\n\n|[![The New York Times](./docs/images/logo-nytimes.png)](https://www.nytimes.com/)|[![Apollo GraphQL](./docs/images/logo-apollo.png)](https://github.com/apollographql/apollo-client/)|[![Facebook](./docs/images/logo-facebook.png)](https://github.com/facebook/fbjs/)|[![Swagger](./docs/images/logo-swagger.png)](https://swagger.io/)|[![VulcanJS](./docs/images/logo-vulcanjs.png)](http://vulcanjs.org)|[![graphql-request](./docs/images/logo-graphql-request.png)](https://github.com/prisma/graphql-request)|\n|:---:|:---:|:---:|:---:|:---:|:---:|\n|The New York Times|Apollo GraphQL|Facebook|Swagger|VulcanJS|graphql-request|\n\n\n## Thanks\n\nHeavily inspired by the works of [matthew-andrews](https://github.com/matthew-andrews). Kudos to him!\n\n\n## License\n\ncross-fetch is licensed under the [MIT license](https://github.com/lquixada/cross-fetch/blob/main/LICENSE) © [Leonardo Quixadá](https://twitter.com/lquixada/)\n\n\n## Author\n\n|[![@lquixada](https://avatars0.githubusercontent.com/u/195494?v=4&s=96)](https://github.com/lquixada)|\n|:---:|\n|[@lquixada](http://www.github.com/lquixada)|\n","readmeFilename":"README.md","gitHead":"dfd48c7670720bcf918bc94b4cacf861215831db","_id":"cross-fetch@3.2.0-alpha.2","_nodeVersion":"10.19.0","_npmVersion":"7.21.0","dist":{"integrity":"sha512-drGPjxxGKIsZN52uPUX929wCGLxd6lXkfhUlB8Zso+wWw5LXiJy+3iQQ1iqCB0O0SittVCWk1ZPD07wYvM19pQ==","shasum":"51b70796f44b68cdc1e86fdc3220c1d17dbb86a8","tarball":"http://registry-npm.ywwl.com/cross-fetch/download/cross-fetch-3.2.0-alpha.2.tgz","fileCount":13,"unpackedSize":87679,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICWmejr7vQ1Q/xxewaUAoW2InwDG8OdF52ShWBs9Qdj4AiAN7Wh+HL3GiiMwKYX7SvqIA6zApMqrlKBCvLIlXo2efg=="}],"size":21592,"noattachment":false,"key":"/cross-fetch/-/cross-fetch-3.2.0-alpha.2.tgz"},"_npmUser":{"name":"lquixada","email":"lquixada@gmail.com"},"directories":{},"maintainers":[{"name":"lquixada","email":"lquixada@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cross-fetch_3.2.0-alpha.2_1634674698142_0.010281058076072824"},"_hasShrinkwrap":false,"publish_time":1634674698343,"_cnpm_publish_time":1634674698343,"dist-tags":{"latest":"4.1.0","latest-v2.x":"2.2.6","latest-v3.x":"3.2.0","latest-v4.x":"4.1.0"}}