{"_id":"@amy1994/jsonp","_rev":"1-0b71cf6e86d2b19131d2b9bc24db4d6e","name":"@amy1994/jsonp","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@amy1994/jsonp","version":"1.0.0","description":"[![<CircleCI>](https://circleci.com/gh/Seven-Y-Q-Guo/jsonp.svg?style=svg)](https://app.circleci.com/pipelines/github/Seven-Y-Q-Guo/jsonp)","main":"jsonp.js","scripts":{"test":"jest","build":"esbuild jsonp.js --bundle --outfile=dist/out.js","build:example":"esbuild example/index.js --bundle --outfile=example/build.js","build:test":"esbuild test/main.js --bundle --outfile=test/out.js"},"keywords":["jsonp","build your own"],"author":{"name":"amy"},"license":"MIT","jest":{"testEnvironment":"jsdom"},"dependencies":{"esbuild":"^0.14.47","jest":"^28.1.1","jest-environment-jsdom":"^28.1.1","mocha":"^10.0.0"},"directories":{"example":"example","test":"test"},"gitHead":"5035a8416fdac35e0da3a1736c301ae27488b874","_id":"@amy1994/jsonp@1.0.0","_nodeVersion":"14.15.3","_npmVersion":"6.14.9","dist":{"integrity":"sha512-jzMdYzd9bcvchtlUfTEyQMmC1nXtBl0XnRo6OhoigfsV8JDeyugesjSZcyNum84ItGlpMeo1YrsWPWq7ArAD7A==","shasum":"f71fbdc7ee620b7fa70d36fa05972d58dd81634c","tarball":"https://registry.npmjs.org/@amy1994/jsonp/-/jsonp-1.0.0.tgz","fileCount":13,"unpackedSize":18748,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAy4Z2A5gRzRLTltBCBhmoz5HAZHPB4pp4nNTf5GtzUcAiBItGoXriK8Eyox4vBoHVqueT84lGzm+BcztJOMYQHRzQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiuF0eACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqySA//Xhui13D+zfpXF1J4jMbn88ikdZFtjJI3dCpk8KrrfN6U9Kpd\r\nLns8UVjPgRk87VTaTalJgsG3YY3YNtjBJo7wOXKJNPNAXf0ZLpdIzHc35XSp\r\nPbmzYy518kQ5m+gidPauLiR4iqNvPuRR+VaEdiCo3tBHwg8PxHhykJ18+9hu\r\nyDarGzJQWP84uNCyjsxUHYVaFUKbURY8A9XS6Ahv0si/UBTbj7bv0O8EyhIb\r\nZBEOePuDVx48d8v1OyWujPCqC7sUfhevJxbeY56ZMTc4E2rLcXSLo4NjawKU\r\nSvWF5GP9TLsskPTn9DCEelTSAK9H5Lo5+VqyPghNVtXsYM6I70VA4sakDgyP\r\nY7xXRx1Nn6E1SjeZhf059Iv2fFgqLDEb9Ux5Fjh3GYp+9lxYD1D2jKU4uZgJ\r\nIeq/cZ9GvIyvdTG+vS/PqsqqCPBVJxf39uJvk/mDR447f33AVvQz4Gfz0pg0\r\nqMbK7F53f9ZBECg9dNGCo9E8gzd1iAqUMzTXnN09gUqKWBiDOW4Bsj+pw5my\r\nzDWqhLGbHEKhex2Yl+JqzMbRsMK6aY6LXchqz4x8k5Qq4+CiJur/rW270OUm\r\nGH/MmvbLdwJi/lh8ffPBPJvWJrAlxJnn/WEjC4+JfBmR9sl8wFNk/IDDxLSk\r\nJZwlmKmHkaqG0831Mn43ou7puqb7poB0fJg=\r\n=ppIN\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"amy1994","email":"1259688240@qq.com"},"maintainers":[{"name":"amy1994","email":"1259688240@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jsonp_1.0.0_1656249630552_0.9880865653458009"},"_hasShrinkwrap":false},"1.0.1":{"name":"@amy1994/jsonp","version":"1.0.1","description":"[![<CircleCI>](https://circleci.com/gh/Xiaoqianerli/jsonp.svg?style=svg)](https://app.circleci.com/pipelines/github/Xiaoqianerli/jsonp)","main":"jsonp.js","scripts":{"test":"jest","build":"esbuild jsonp.js --bundle --outfile=dist/out.js","build:example":"esbuild example/index.js --bundle --outfile=example/build.js","build:test":"esbuild test/main.js --bundle --outfile=test/out.js"},"keywords":["jsonp","build your own"],"author":{"name":"amy"},"license":"MIT","jest":{"testEnvironment":"jsdom"},"dependencies":{"esbuild":"^0.14.47","jest":"^28.1.1","jest-environment-jsdom":"^28.1.1","mocha":"^10.0.0"},"directories":{"example":"example","test":"test"},"gitHead":"9c36c1944249b9ade2839a3cf3aa8ce86c656263","_id":"@amy1994/jsonp@1.0.1","_nodeVersion":"14.15.3","_npmVersion":"6.14.9","dist":{"integrity":"sha512-KR6NH6aZ+PbnExMRZdsMbn//ybn4o71Y6+0qcr9FpfghkNAhvqHWkwGG591hODQshrc4RQsukgZKe+Jttpkw2A==","shasum":"6e868cf8dddb6b7d38954f99e90dc3714e4215af","tarball":"https://registry.npmjs.org/@amy1994/jsonp/-/jsonp-1.0.1.tgz","fileCount":13,"unpackedSize":18746,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC3LtsdGu25rhcyJJOC08PEz1sivUwYHLCfWf4Nd2Qp6gIgXlAC2nGHKGS36Esxuy4n7KNp6T5f5cJaVj3wC1/O2NQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiuF3BACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq7hRAAoRn9B1Qji2eYRgqnrwng6JAlJHTVRp21F7lrcmcOlE31TbFQ\r\n1MYYQXGaiT2eLBp6j3E/6qXkmRsHWwYWWIZAZ4oKrEvohMamyV3UPCz6iY+G\r\nQyPev434g3itOmBxY78d6Mx8tk3Ur62hhrSwTevkSzm7RodP/b4YUgLDFoCQ\r\ntR4n285TPOSVmdwMxMrSz2dDXYf2fTizKuJFRSEorDHM+MgdC5dq4ycijgUM\r\nTdWFct/n1ptf+aXpMRovBTlubarJ14FgCqleK/Bnq4pplXosSNdmDnZD/kZ8\r\nHSEPk8dxqRcEtPFUipMKEMN4Kxy0bdXi81M4278DcEhoVz5JxNYwGITWh8GC\r\nOTjgXZa1ZgNMcNU3/FrM9w8QH5vuHE4NT/6G1KaSqJmCTnBTkpUaMmIxZ9GP\r\nDH5RVV09NPG1dxcuSWqC7Ay/dpNbrkP6KV/LQDg9mVe3UDO3e+ASENmjnIua\r\nO69vUbXQSJhGyGJ5q2zPfgwjeb5RsZ2VQliuQ+omNMIk6nxV3eQGNesWPAKy\r\nYJ/c7VI6WdN5x8E4fMtsP9ZIZYSYXuRnjC3l0KPGJEV7WL/VLU3xqhQdg7C8\r\nv9v36Xbs1m8LJGMJjaoiLomW5GWBeIf02GNpNbr0XswFUahV3Xok27P5buKm\r\nDElfU12MDS0KzJmeLzjts/4FSwtm+SzMRe0=\r\n=lYPL\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"amy1994","email":"1259688240@qq.com"},"maintainers":[{"name":"amy1994","email":"1259688240@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jsonp_1.0.1_1656249793404_0.9983981235170896"},"_hasShrinkwrap":false}},"time":{"created":"2022-06-26T13:20:30.482Z","1.0.0":"2022-06-26T13:20:30.710Z","modified":"2022-06-26T13:23:13.632Z","1.0.1":"2022-06-26T13:23:13.569Z"},"maintainers":[{"name":"amy1994","email":"1259688240@qq.com"}],"description":"[![<CircleCI>](https://circleci.com/gh/Xiaoqianerli/jsonp.svg?style=svg)](https://app.circleci.com/pipelines/github/Xiaoqianerli/jsonp)","keywords":["jsonp","build your own"],"author":{"name":"amy"},"license":"MIT","readme":"[![<CircleCI>](https://circleci.com/gh/Xiaoqianerli/jsonp.svg?style=svg)](https://app.circleci.com/pipelines/github/Xiaoqianerli/jsonp)\r\n\r\n# [build-your-own] JSONP\r\nInspired from https://github.com/webmodules/jsonp\r\n\r\n## Installation\r\nInstall via NPM:\r\n\r\n```bash\r\nnpm i @amy/jsonp\r\n```\r\n\r\n## Usage\r\n\r\n```javascript\r\nconst jsonp = require(\"@amy/jsonp\"); // or import jsonp from '@amy/jsonp';\r\njsonp('http://jsfiddle.net/echo/jsonp?name=amy', {\r\n  name: 'hello',\r\n  success: (info) => {\r\n    console.log(info); // {name: 'amy'}\r\n  },\r\n  error: (error) => {\r\n    console.log(error); // handle kinds of errors like timeout, 404, etc.\r\n  }\r\n});\r\n```\r\n\r\n## API\r\n\r\n### jsonp(url, opts)\r\n\r\n- `url` (`String`) url to fetch\r\n- `opts` (`Object`)\r\n  - `success` handle success\r\n  - `error` handle error\r\n  - `param` (`String`) name of the query string parameter to specify\r\n    the callback (defaults to `callback`)\r\n  - `timeout` (`Number`) how long after a timeout error is emitted. `0` or other falsy value to\r\n    disable (defaults to `30000`)\r\n  - `prefix` (`String`) prefix for the global callback functions that\r\n    handle jsonp responses (defaults to `__jp`)\r\n  - `name` (`String`) optional: name of the global callback functions that\r\n    handle jsonp responses, will generate `__jp + incremented` counter if not passing specific name\r\n\r\nReturns a function that, when called, will cancel the in-progress jsonp request\r\n(`success` & `error` won't be called any more).\r\n\r\n## Want Promise?\r\n\r\n### You can implement easily\r\n\r\n```javascript\r\nfunction fetchJson(url, opts = {}) {\r\n  return new Promise((resolve, reject) => {\r\n    jsonp(url, {\r\n      ...opts,\r\n      success: resolve,\r\n      error: reject\r\n    });\r\n  })\r\n}\r\nfetchJson('http://jsfiddle.net/echo/jsonp?name=amy').then(res => {\r\n  console.log(res);\r\n}).catch(err => {\r\n  console.log(err);\r\n});\r\n```\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}