{"name":"fetch-jsonp","version":"1.2.2","description":"Fetch JSONP like a boss using Fetch API","main":"build/fetch-jsonp.js","scripts":{"prepublish":"npm run lint && npm run clean && npm run build","build":"babel src/ --modules umd --out-dir build","clean":"rm -rf build","lint":"eslint src/"},"keywords":["fetch","jsonp","github fetch","ajax"],"devDependencies":{"babel":"^5.8.21","babel-core":"^5.8.21","babel-eslint":"^4.0.5","eslint":"^1.1.0","eslint-config-airbnb":"^0.0.7","eslint-plugin-react":"^3.2.1"},"repository":{"type":"git","url":"git+https://github.com/camsong/fetch-jsonp.git"},"author":{"name":"Cam Song"},"license":"MIT","bugs":{"url":"https://github.com/camsong/fetch-jsonp/issues"},"homepage":"https://github.com/camsong/fetch-jsonp#readme","gitHead":"be1dd0f4883eea93219696fa4a138fca2ffa4592","_id":"fetch-jsonp@1.2.2","_nodeVersion":"16.15.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-8rQTSU3G2k9VwpsTLpuUQ8Ix7Yv1bZDGcOUGr4me0F7pxyKxMH9PSBXF6tPMx3fca9DICYwztDa1KgOTeAdTWg==","shasum":"c98923191390119a8eae401a9cbe75845230e000","tarball":"http://registry-npm.ywwl.com/fetch-jsonp/download/fetch-jsonp-1.2.2.tgz","fileCount":8,"unpackedSize":12028,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCf2pgwDqrkfEYMqxNaC6c21cgiyNwwf86iEFgUq1QM0QIgB3dEkmj3ALCf0yge8BnjM9/J6Pv8NFP3bBjS6nKm0Iw="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjBy67ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpLjw//QPm3C0Az44FDpgT/5/qGAHVx1iVtWTHE9xhtKIyIIHIpmMyk\r\neIcvFTMYusYcnHhRwjQhPe708vEx+N4PqRGKg/U2Cusm5ESwkO/ShMge5BJV\r\n0cz165ZQeofZIsm1jLlE+5Cw8Hke4q4pSDbep3hfg+nV3GZZYWFBd2ZoZykZ\r\nruvteHFViOGC7XQ/yj+FveM94G+5umWeSskwfjBL3ZJi6dSaE6ev8qg13Eeb\r\nXsdEC4gV6TUTxT1WXnt8brVIC8zD3W2829TAOou5ES3ZJNbfRerBXSMp6qiu\r\nbIXYMCM+kAsnuNUB7MsGqbkTiV0XrCWo1OBYFJGDMC58FZCRgZA/pAy/KcJt\r\nszYYNeGopsYwLN4xUjoKTXq6bJabmBG1r2OAeqwxGtA5nqP9BicA+0GiCMTX\r\nPuW5qYvTPQvg//XKNHoZ0opMc9kavZVWns0WJTbkHYnzA0kjN/1FrM+zE7h+\r\nhzapofayy5rlwHtl3B9xKLbC4sLg7I5EaGdbCM7oChjo7CJfdgnGh/edNDAt\r\njoZd2AfzOqqC1CWViUGmURHbxnB70TxkvzOFBtWHua/auxGWXEpJoknzB+Kl\r\neft0D2hAWB2cu5nQQmM2ICDMkN5oQs37Itn1fXJiSYosrryWDjurNktsRzkL\r\nI9/VWrUbEyNFtRH1ZBgM1dEEKQjgdERzryw=\r\n=B75r\r\n-----END PGP SIGNATURE-----\r\n","size":4411,"noattachment":false,"key":"/fetch-jsonp/-/fetch-jsonp-1.2.2.tgz"},"_npmUser":{"name":"camsong","email":"neosoyn@gmail.com"},"directories":{},"maintainers":[{"name":"camsong","email":"neosoyn@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fetch-jsonp_1.2.2_1661415099717_0.024064165320403674"},"_hasShrinkwrap":false,"readme":"# Fetch JSONP [![Build Status](https://travis-ci.org/camsong/fetch-jsonp.svg)](https://travis-ci.org/camsong/fetch-jsonp) [![npm version](https://badge.fury.io/js/fetch-jsonp.svg)](http://badge.fury.io/js/fetch-jsonp) [![npm downloads](https://img.shields.io/npm/dm/fetch-jsonp.svg?style=flat-square)](https://www.npmjs.com/package/fetch-jsonp)\n\nJSONP is NOT supported in standard Fetch API, https://fetch.spec.whatwg.org.\nfetch-jsonp provides you same API to fetch JSONP like native Fetch, also comes\nwith global `fetchJsonp` function.\n\nIf you need a `fetch` polyfill for old browsers, try [github/fetch](http://github.com/github/fetch).\n\n## Installation\n\nYou can install with `npm`.\n\n```\nnpm install fetch-jsonp\n```\n\n## Promise Polyfill for IE\n\nIE8/9/10/11 does not support [ES6 Promise](https://tc39.github.io/ecma262/#sec-promise-constructor), run this to polyfill the global environment at the beginning of your application.\n\n```js\nrequire('es6-promise').polyfill();\n```\n\n## Usage\n\nJSONP only supports GET method, same as `fetch-jsonp`.\n\n### Fetch JSONP in simple way\n\n```javascript\nfetchJsonp('/users.jsonp')\n  .then(function(response) {\n    return response.json()\n  }).then(function(json) {\n    console.log('parsed json', json)\n  }).catch(function(ex) {\n    console.log('parsing failed', ex)\n  })\n```\n\n### Set JSONP callback parameter name, default is 'callback'\n\n```javascript\nfetchJsonp('/users.jsonp', {\n    jsonpCallback: 'custom_callback',\n  })\n  .then(function(response) {\n    return response.json()\n  }).then(function(json) {\n    console.log('parsed json', json)\n  }).catch(function(ex) {\n    console.log('parsing failed', ex)\n  })\n```\n\n### Set JSONP callback function name, default is a random number with `json_` prefix\n\n```javascript\nfetchJsonp('/users.jsonp', {\n    jsonpCallbackFunction: 'function_name_of_jsonp_response'\n  })\n  .then(function(response) {\n    return response.json()\n  }).then(function(json) {\n    console.log('parsed json', json)\n  }).catch(function(ex) {\n    console.log('parsing failed', ex)\n  })\n```\n\n### Set JSONP request timeout, default is 5000ms\n\n```javascript\nfetchJsonp('/users.jsonp', {\n    timeout: 3000,\n  })\n  .then(function(response) {\n    return response.json()\n  }).then(function(json) {\n    console.log('parsed json', json)\n  }).catch(function(ex) {\n    console.log('parsing failed', ex)\n  })\n```\n\n### Difference between `jsonpCallback` and `jsonpCallbackFunction`\nThere two functions can easily be confused with each other, but there is a clear distinction.\n\nDefault values are\n* `jsonpCallback`, default value is `callback`. It's the name of the callback parameter\n* `jsonpCallbackFunction`, default value is `null`. It's the name of the callback function. In order to make it distinct, it's a random string with `jsonp_` prefix like `jsonp_1497658186785_39551`. Leave it blank if it's set by the server, set it explicitly if the callback function name is fixed.\n\n##### Case 1:\n```js\nfetchJsonp('/users.jsonp', {\n  jsonpCallback: 'cb'\n})\n```\nThe request url will be `/users.jsonp?cb=jsonp_1497658186785_39551`, and the server should respond with a function like:\n```js\njsonp_1497658186785_39551(\n  { ...data here... }\n)\n```\n\n##### Case 2:\n```js\nfetchJsonp('/users.jsonp', {\n  jsonpCallbackFunction: 'search_results'\n})\n```\nThe request url will be `/users.jsonp?callback=search_results`, and the server should always respond with a function named `search_results` like:\n```js\nsearch_results(\n  { ...data here... }\n)\n```\n\n### Caveats\n\n#### 1. You need to call `.then(function(response) { return response.json(); })` in order to keep consistent with Fetch API.\n\n#### 2. `Uncaught SyntaxError: Unexpected token :` error\n\nMore than likely, you are calling a JSON api, which does not support JSONP. The difference is that JSON api responds with an object like `{\"data\": 123}` and will throw the error above when being executed as a function. On the other hand, JSONP will respond with a function wrapped object like `jsonp_123132({data: 123})`.\n\n## Browser Support\n\n![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_7-8/internet-explorer_7-8_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png)\n--- | --- | --- | --- | --- |\nLatest ✔ | Latest ✔ | 8+ ✔ | Latest ✔ | 6.1+ ✔ |\n\n# License\n\nMIT\n\n# Acknowledgement\n\nThanks to [github/fetch](https://github.com/github/fetch) for bring Fetch to old browsers.\n","publish_time":1661415099932,"_cnpm_publish_time":1661415099932,"dist-tags":{"latest":"1.4.0"}}