{"name":"cross-fetch","version":"2.2.5","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","typings":"index.d.ts","scripts":{"pretest:node:bundle":"webpack-cli --progress --config test/node-bundle/webpack.config.js","build":"rollup -c","codecov":"nyc report --reporter=text-lcov > coverage.lcov && codecov","deploy:major":"npm version major && git push --follow-tags","deploy:minor":"npm version minor && git push --follow-tags","deploy:patch":"npm version patch && git push --follow-tags","lint":"standard","sauce":"./tasks/sauce","security":"snyk test","test":"npm run -s test:browser:headless && npm run -s test:node:plain && npm run -s test:node:bundle && npm run -s lint","test:browser:headless":"mocha-headless-chrome -f test/browser-headless/index.html -a no-sandbox -a disable-setuid-sandbox","test:browser:plain":"opn test/browser/index.html","test:node:bundle":"nyc mocha test/node-bundle/index.js","test:node:plain":"nyc mocha test/node-plain/index.js"},"lint-staged":{"*.js":["standard --fix","git add"]},"husky":{"hooks":{"pre-commit":"npm run -s build && lint-staged"}},"standard":{"env":["mocha","browser"],"globals":["expect","chai","sinon"],"ignore":["/dist/","test/node-bundle/index.js"]},"nyc":{"temp-dir":".reports/.coverage"},"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.1","whatwg-fetch":"2.0.4"},"devDependencies":{"chai":"4.2.0","codecov":"3.1.0","husky":"1.1.2","lint-staged":"7.3.0","mocha":"5.2.0","mocha-headless-chrome":"2.0.1","nock":"10.0.1","nyc":"13.1.0","opn-cli":"3.1.0","ora":"3.0.0","rollup":"0.66.6","rollup-plugin-copy":"0.2.3","rollup-plugin-uglify":"6.0.0","sinon":"7.0.0","snyk":"1.105.0","standard":"12.0.1","webpack":"4.23.0","webpack-cli":"3.1.2"},"keywords":["fetch","isomorphic","universal","node","react","native","browser","ponyfill","whatwg","xhr","ajax"],"readme":"cross-fetch<br>\n[![Build Status](https://travis-ci.org/lquixada/cross-fetch.svg?branch=master)](https://travis-ci.org/lquixada/cross-fetch)\n[![Build Status](https://saucelabs.com/buildstatus/cross-fetch)](https://saucelabs.com/u/cross-fetch)\n[![codecov](https://codecov.io/gh/lquixada/cross-fetch/branch/master/graph/badge.svg)](https://codecov.io/gh/lquixada/cross-fetch)\n[![dependencies Status](https://david-dm.org/lquixada/cross-fetch/status.svg)](https://david-dm.org/lquixada/cross-fetch)\n[![NPM Version](https://img.shields.io/npm/v/cross-fetch.svg?branch=master)](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================\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- **Updated**: latest version of whatwg-fetch and node-fetch used\n\n\n* * *\n\n## Table of Contents\n\n-   [Install](#install)\n-   [Usage](#usage)\n-   [Demo & API](#demo--api)\n-   [FAQ](#faq)\n-   [Supported environments](#supported-environments)\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, these resources can be useful:\n\n* [**JSFiddle playground**](https://jsfiddle.net/lquixada/3ypqgacp/) ➡️\n* [**Public test suite**](https://lquixada.github.io/cross-fetch/test/saucelabs/) ➡️\n\n> **Tip**: Run theses resources 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 it will never be fixed since the author hasn't been committing for more than a year. 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://www.npmjs.com/package/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* [VulcanJS](http://vulcanjs.org)\n* [graphql-request](https://github.com/graphcool/graphql-request)\n* [Swagger](https://swagger.io/)\n\n\n## Supported environments\n\n* Node 6+\n* React-Native\n\n[![Build Status](https://saucelabs.com/browser-matrix/cross-fetch.svg)](https://saucelabs.com/u/cross-fetch)\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/master/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":"3abdc676d0b198e54d87c0df17b59668243826c4","_id":"cross-fetch@2.2.5","_nodeVersion":"13.11.0","_npmVersion":"6.9.0","_npmUser":{"name":"lquixada","email":"lquixada@gmail.com"},"dist":{"integrity":"sha512-xqYAhQb4NhCJSRym03dwxpP1bYXpK3y7UN83Bo2WFi3x1Zmzn0SL/6xGoPr+gpt4WmNrgCCX3HPysvOwFOW36w==","shasum":"afaf5729f3b6c78d89c9296115c9f142541a5705","tarball":"http://registry-npm.ywwl.com/cross-fetch/download/cross-fetch-2.2.5.tgz","fileCount":11,"unpackedSize":68085,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg/dOBCRA9TVsSAnZWagAAEBEQAJue0o5vis5DEMD1tWZ6\nCJPH+svEFUdSHIk0lC+nLF0fkXdp948gBP1OzqNliWRRs1b2fou2eYvrMClv\nsg8wUw1TfEb/GmTLnXyInFioSRL/vNjOhmMP/LjNBy2/jspplbR8vcw1Mc9M\ngxAL7BTID8RrdoHWKEOaMv81FGUdd0GyV5pNCpgYZRN22xOs1oc6zWhPlig7\n0BFFw37aC2c9tLSxqemIEghp2JnLIUHK203Gbf0hIiTxtQicDNGqQqYbZvZ8\niRnhH90k6/wY1OfQq+0n/Z/qcXBEG2+60XjEoOvSVzZJBOVSeYSs1WanILh8\ntEaoZUufY7wJyomdlYlDBb8RMMPktZM9SQsvk6kxpGi9b9XvvrEOjMtuwODA\nVGP2ZII9vbR/ZKVaAGNwsh0IguMIgukJvLwz514XZAxWF9gocuxVyuGa8rqi\nHD0kM/XlaDj6jmJRFUuT2o2UMzthm5dLXuRqfDgx6VQK104lBbiMMwNeiNjS\na7ncLHpHJh6A6H5T+F66DDXFn74OZEzki9yv0aydMWYDZ3aaQjhZsMxlIh64\nBEaAOpDzoAiJLk7S2x5wKjAv6TS10p4pDktEAmdX7seZaw0tM58ZlVijCF8O\nHZ7R1NUYwyCZZ7CJaXlsGlsT+Q18KMhd+ZevThcCqD9n/2nLF4Ikcaw2cL1j\nQclA\r\n=GDYO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCUhjzofUN539/Fpn2y5Iyt+r3zNzr6nTCsK8VcBLtbpAIhAJqlEA3cVrWUKrnYTlSV9+dvTZLcAG201brjz4n0AoVb"}],"size":15937,"noattachment":false,"key":"/cross-fetch/-/cross-fetch-2.2.5.tgz"},"directories":{},"maintainers":[{"name":"lquixada","email":"lquixada@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cross-fetch_2.2.5_1627247489404_0.1789342107282943"},"_hasShrinkwrap":false,"publish_time":1627247489560,"_cnpm_publish_time":1627247489560,"dist-tags":{"latest":"4.1.0","latest-v2.x":"2.2.6","latest-v3.x":"3.2.0","latest-v4.x":"4.1.0"}}