{"_id":"@async-util/fetch","_rev":"8-d8034c797c9f949d0c4179a02f41d7d8","name":"@async-util/fetch","dist-tags":{"latest":"0.7.4"},"versions":{"0.3.0":{"name":"@async-util/fetch","version":"0.3.0","keywords":["fetch","stream","parser"],"author":{"url":"talrasha007@gmail.com","name":"Tal"},"license":"Apache-2.0","_id":"@async-util/fetch@0.3.0","maintainers":[{"name":"talrasha007","email":"talrasha007@gmail.com"}],"homepage":"https://github.com/async-util/fetch#readme","bugs":{"url":"https://github.com/async-util/fetch/issues"},"dist":{"shasum":"3ef45d5a9d43813994c42e0ed035da58f4bd1a1c","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.3.0.tgz","fileCount":6,"integrity":"sha512-Li66iRBwX9VOvgmTf53irJDSpT72mJVn5xOIZDBWC+xuBskPmCbClAYOYalwmVgX3VOGwqB7j5tLuUQV0Yi5nA==","signatures":[{"sig":"MEQCIF+hO1YGmkKWQKYsafYyEYaeNfAD+GdxIlpgmkryArnGAiB+fBgPObzKLOOt2TzuLLJY+RBe5w1cd2h03RR3DgVoGw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19518},"main":"index.mjs","types":"index.d.mts","gitHead":"51aafcfedcbf27b77bdd2fae492a57fb0a2ca91c","_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"repository":{"url":"git+https://github.com/async-util/fetch.git","type":"git"},"_npmVersion":"9.6.7","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","directories":{"example":"example"},"_nodeVersion":"18.17.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/fetch_0.3.0_1692498446365_0.2471137925759186","host":"s3://npm-registry-packages"}},"0.3.1":{"name":"@async-util/fetch","version":"0.3.1","keywords":["fetch","stream","parser"],"author":{"url":"talrasha007@gmail.com","name":"Tal"},"license":"Apache-2.0","_id":"@async-util/fetch@0.3.1","maintainers":[{"name":"talrasha007","email":"talrasha007@gmail.com"}],"homepage":"https://github.com/async-util/fetch#readme","bugs":{"url":"https://github.com/async-util/fetch/issues"},"dist":{"shasum":"74109621a79f2dfeaeb758d140d2b578154a931a","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.3.1.tgz","fileCount":5,"integrity":"sha512-a5otOjh5wULAFva9NmjnWvLcr00J96/K1fx8Qw6vTv6gWRgQ+0WwQ8Nu60FmOUXcXp9gEPHFts2o5lB8aAr1vg==","signatures":[{"sig":"MEUCIQC8aeDaTTApgnoZBCjLeKwGG/sVwOUC53AdZuzAqNtG5QIgPMDKzXL3Up2O+0+a2niiRwahi+jNGRpZTD27WjvU4fA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19057},"main":"index.mjs","types":"index.d.mts","gitHead":"c80450483e75e9d2841be01eeb768d2c61d83944","_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"repository":{"url":"git+https://github.com/async-util/fetch.git","type":"git"},"_npmVersion":"9.6.7","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","directories":{"example":"example"},"_nodeVersion":"18.17.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/fetch_0.3.1_1692498615755_0.3172778845471804","host":"s3://npm-registry-packages"}},"0.3.2":{"name":"@async-util/fetch","version":"0.3.2","keywords":["fetch","stream","parser"],"author":{"url":"talrasha007@gmail.com","name":"Tal"},"license":"Apache-2.0","_id":"@async-util/fetch@0.3.2","homepage":"https://github.com/async-util/fetch#readme","bugs":{"url":"https://github.com/async-util/fetch/issues"},"dist":{"shasum":"7af0b732b4c62ebb05a4d35a066454b5d572c484","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.3.2.tgz","fileCount":5,"integrity":"sha512-udV20jzTNzy2DrYZiwzU+fafjF9cfzAuR9+n9UUgQw9YErXxL73dXvjNlL1Q1RQZar8TYfirx7KkIskQWs3G4g==","signatures":[{"sig":"MEUCIE0a0BTS9r8byYW2M+/XYhUODK+0Qt72zlruQfalGwcwAiEA4EYPiFUCFyGWume0eQErdYItuUKTD1QtL5vK+esde4E=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19061},"main":"index.mjs","types":"index.d.mts","gitHead":"0450c40c17b2b3891671f4c591603dcf2011e24e","_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"repository":{"url":"git+https://github.com/async-util/fetch.git","type":"git"},"_npmVersion":"10.7.0","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","directories":{"example":"example"},"_nodeVersion":"18.20.3","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/fetch_0.3.2_1719673673949_0.6523286402196737","host":"s3://npm-registry-packages"}},"0.3.3":{"name":"@async-util/fetch","version":"0.3.3","keywords":["fetch","stream","parser"],"author":{"url":"talrasha007@gmail.com","name":"Tal"},"license":"Apache-2.0","_id":"@async-util/fetch@0.3.3","homepage":"https://github.com/async-util/fetch#readme","bugs":{"url":"https://github.com/async-util/fetch/issues"},"dist":{"shasum":"9ffda10544197af31ae7285b0e464c1ecd3d425b","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.3.3.tgz","fileCount":5,"integrity":"sha512-p70FtHBqD8ft0dqQeiK8QOc0woC3Aoy2in+B5Q3wSWSpvZ1w/2+h+A04hHP66MSMjV5DCv6aZ77tY66PH5iuSQ==","signatures":[{"sig":"MEUCIQCu4g0GoJOM2GoNfnOaSUl20YtqAF7HHlQdb0ans9ry9wIgPNc0jbcLfXg0206e6rQO1nXSB3iYxMnBCspsMfqlhVE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19147},"main":"index.mjs","types":"index.d.mts","gitHead":"1c67774611cea39b010f7dc02de617326c74d9b2","_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"repository":{"url":"git+https://github.com/async-util/fetch.git","type":"git"},"_npmVersion":"10.7.0","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","directories":{"example":"example"},"_nodeVersion":"18.20.3","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/fetch_0.3.3_1719929066693_0.2117067036581628","host":"s3://npm-registry-packages"}},"0.4.0":{"name":"@async-util/fetch","version":"0.4.0","keywords":["fetch","stream","parser"],"author":{"url":"talrasha007@gmail.com","name":"Tal"},"license":"Apache-2.0","_id":"@async-util/fetch@0.4.0","maintainers":[{"name":"talrasha007","email":"talrasha007@gmail.com"}],"homepage":"https://github.com/async-util/fetch#readme","bugs":{"url":"https://github.com/async-util/fetch/issues"},"dist":{"shasum":"0e52f8748696072bca20f97d4bd90ea763a8e0c0","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.4.0.tgz","fileCount":5,"integrity":"sha512-VJJDigRFOX4eOG1ObThW9jFcXNfNDmQYJSSkz1PjgwofGlJz+Oebc/m7wxxKyNYswDVzZMXEVRyofdydiI2L/Q==","signatures":[{"sig":"MEQCICgbUV9e6jRka0ntf9yDuiKnhjIw6pkR6J2qzs7FmkOFAiADOqrTdj5r2u0y2H2ymmZP96zLvYrxZU4Y4O58Ca5r6w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19161},"main":"index.mjs","types":"index.d.mts","gitHead":"f01020e0b27340ca104dfcd4f63ce8ee4e872b59","_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"repository":{"url":"git+https://github.com/async-util/fetch.git","type":"git"},"_npmVersion":"10.7.0","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","directories":{"example":"example"},"_nodeVersion":"18.20.3","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/fetch_0.4.0_1720143959677_0.3441339607114504","host":"s3://npm-registry-packages"}},"0.5.0":{"name":"@async-util/fetch","version":"0.5.0","keywords":["fetch","stream","parser"],"author":{"url":"talrasha007@gmail.com","name":"Tal"},"license":"Apache-2.0","_id":"@async-util/fetch@0.5.0","maintainers":[{"name":"talrasha007","email":"talrasha007@gmail.com"}],"homepage":"https://github.com/async-util/fetch#readme","bugs":{"url":"https://github.com/async-util/fetch/issues"},"dist":{"shasum":"91b8433f1ed8e01a2bef22f8398689630aaaf4e0","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.5.0.tgz","fileCount":5,"integrity":"sha512-X0wRSrFV4I0TzU7UfP7P3y/JvbOUd8C/C1xrOybGcY9MxKUsz3fratcanKdTYMGz4sNyC3Tnp0ZhXiHCi423jQ==","signatures":[{"sig":"MEUCIQDYMb8l2J7ff26N2KpYmdnWTmKK5MZP4vu6HrD/yaCl8AIgHDmT/T/c0CtmX6rH64i6bnFQvIxxXYe0kcLFz/CGzDQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19350},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"d8bbf27ea65d88fd1e19071dff607ea6d922cc84","scripts":{"build":"tsc"},"_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"repository":{"url":"git+https://github.com/async-util/fetch.git","type":"git"},"_npmVersion":"10.7.0","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","directories":{"example":"example"},"_nodeVersion":"18.20.3","_hasShrinkwrap":false,"devDependencies":{"ts-node":"^10.9.2"},"_npmOperationalInternal":{"tmp":"tmp/fetch_0.5.0_1720686758918_0.39160796959296884","host":"s3://npm-registry-packages"}},"0.5.1":{"name":"@async-util/fetch","version":"0.5.1","keywords":["fetch","stream","parser"],"author":{"url":"talrasha007@gmail.com","name":"Tal"},"license":"Apache-2.0","_id":"@async-util/fetch@0.5.1","maintainers":[{"name":"talrasha007","email":"talrasha007@gmail.com"}],"homepage":"https://github.com/async-util/fetch#readme","bugs":{"url":"https://github.com/async-util/fetch/issues"},"dist":{"shasum":"215753ff7f590005e8b62966ae1a7ffb65f5e87e","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.5.1.tgz","fileCount":7,"integrity":"sha512-IGvjmNdu7udUAuJigIsm6LNpD+uzMsd5M9BFVwOOHlNDmE9EiUVWmVbS6VbUS5kdktIkTdDMpKn3h9LK/QQJSg==","signatures":[{"sig":"MEUCIADJgToRqExdza0HZuTR8AJAT8MlsgsbD6EtdH++lcVJAiEA5foE9W2K7MtR5+qqdjlSY2XF/nSAgi117OkUP2q5x3A=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22275},"main":"dist/index.mjs","types":"dist/index.d.ts","gitHead":"70274ba7cbbfc91096c340a9c8910d4850b765b8","scripts":{"build":"tsc && mv dist/index.js dist/index.mjs"},"_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"repository":{"url":"git+https://github.com/async-util/fetch.git","type":"git"},"_npmVersion":"10.7.0","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","directories":{"example":"example"},"_nodeVersion":"20.15.0","_hasShrinkwrap":false,"devDependencies":{"ts-node":"^10.9.2"},"_npmOperationalInternal":{"tmp":"tmp/fetch_0.5.1_1720692173587_0.3633480774421596","host":"s3://npm-registry-packages"}},"0.6.0":{"name":"@async-util/fetch","version":"0.6.0","keywords":["fetch","stream","parser"],"author":{"url":"talrasha007@gmail.com","name":"Tal"},"license":"Apache-2.0","_id":"@async-util/fetch@0.6.0","maintainers":[{"name":"talrasha007","email":"talrasha007@gmail.com"}],"homepage":"https://github.com/async-util/fetch#readme","bugs":{"url":"https://github.com/async-util/fetch/issues"},"dist":{"shasum":"abceeecde67fdf79c7e831f78d7401cc77d2ca30","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.6.0.tgz","fileCount":7,"integrity":"sha512-1IP67/6z697Be2S9UGOslVkzirPjrkRZ8eEUM0WkAw4J6aCYVtsE/aWGrzbD2+rioYLxMdobiD6SKAFte+VqWw==","signatures":[{"sig":"MEQCIGSoVgc/ESIn/AUhNpN7BNtdQuUasFLlLevmbSUhwxn4AiASaleC1BIy1pM9erEOklXkhKsLAQBXj84wHAgsfS5iQw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22361},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"47dfcae7ff81073546d60e6e2d381684454a52e5","scripts":{"build":"tsc"},"_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"repository":{"url":"git+https://github.com/async-util/fetch.git","type":"git"},"_npmVersion":"10.7.0","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","directories":{"example":"example"},"_nodeVersion":"20.15.1","_hasShrinkwrap":false,"devDependencies":{"ts-node":"^10.9.2"},"_npmOperationalInternal":{"tmp":"tmp/fetch_0.6.0_1722578530687_0.17618280758581295","host":"s3://npm-registry-packages"}},"0.7.4":{"name":"@async-util/fetch","version":"0.7.4","description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc"},"directories":{"example":"example"},"repository":{"type":"git","url":"git+https://github.com/async-util/fetch.git"},"keywords":["fetch","stream","parser"],"author":{"name":"Tal","url":"talrasha007@gmail.com"},"license":"Apache-2.0","bugs":{"url":"https://github.com/async-util/fetch/issues"},"homepage":"https://github.com/async-util/fetch#readme","devDependencies":{"@types/node":"^22.13.1","ts-node":"^10.9.2"},"_id":"@async-util/fetch@0.7.4","gitHead":"764a5357d13902b6da1e5d7a398661c50ccb143b","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-mBWQuPykTRnfv6G45jea5DdPUU535PCTDBh6S/Oqb5Ka42Tswyg1MZOirnIDseH/zRfZmvd+YawmcFOcmBbGFw==","shasum":"a156f4b0cf9b40661595720f5fec179d409b6c4b","tarball":"https://registry.npmjs.org/@async-util/fetch/-/fetch-0.7.4.tgz","fileCount":7,"unpackedSize":23687,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDUozJN2SCl3Jo7UdNKu6VmpNdCYoqjYhUBAsi0GKt2FwIhANK1wzms8712rvyj1YTrKJZc7ulZg2vfHODVITW5o2pl"}]},"_npmUser":{"name":"talrasha007","email":"talrasha007@gmail.com"},"maintainers":[{"name":"talrasha007","email":"talrasha007@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fetch_0.7.4_1739414862400_0.14446996123589684"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-20T02:27:26.247Z","modified":"2025-02-13T02:47:42.799Z","0.3.0":"2023-08-20T02:27:26.637Z","0.3.1":"2023-08-20T02:30:15.926Z","0.3.2":"2024-06-29T15:07:54.116Z","0.3.3":"2024-07-02T14:04:26.922Z","0.4.0":"2024-07-05T01:45:59.831Z","0.5.0":"2024-07-11T08:32:39.150Z","0.5.1":"2024-07-11T10:02:53.748Z","0.6.0":"2024-08-02T06:02:10.840Z","0.7.4":"2025-02-13T02:47:42.590Z"},"bugs":{"url":"https://github.com/async-util/fetch/issues"},"author":{"name":"Tal","url":"talrasha007@gmail.com"},"license":"Apache-2.0","homepage":"https://github.com/async-util/fetch#readme","keywords":["fetch","stream","parser"],"repository":{"type":"git","url":"git+https://github.com/async-util/fetch.git"},"description":"A super lightweight lib for parsing ReadableStream which is the type of Response.body of fetch api.","maintainers":[{"name":"talrasha007","email":"talrasha007@gmail.com"}],"readme":"# @async-util/fetch\nA super lightweight lib for parsing ReadableStream which is the type of Response.body of *fetch api*, implement by async generator fuction, so we can write code in AsyncIterableIterator style.\n\n## Parser & fetchParser\nThe parser ctor accepts a ReadableStream.\n```js\nimport { Parser } from '@async-util/fetch';\n\nasync function foo() {\n  const resp = await fetch('https://your/stream/url', opts);\n  const parser = new Parser(resp.body);\n}\n```\n\nIf you are parsing data from fetch response, use fetchParser, the arg is exactly the same as *fetch*.\n```js\nimoport fetchParser from '@async-util/fetch';\n// or\nimoport { fetchParser } from '@async-util/fetch';\n\nasync function foo() {\n  const parser = await fetchParser('https://your/stream/url', opts);\n}\n```\n\n## Read data from stream\nHere's a exmaple of read the data of *OPENAI* chat completions api with stream = true.\n```js\nimport fetchParser from '@async-util/fetch';\n\nconst openAiKey = process.env.OPENAI_KEY;\n\n(async function () {\n  const parser = await fetchParser('https://api.openai.com/v1/chat/completions', {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n      'Authorization': `Bearer ${openAiKey}`\n    },\n    body: JSON.stringify({\n      stream: true,\n      model: 'gpt-3.5-turbo',\n      messages: [\n        { role: 'system', content: 'You are a helpful assistant.' },\n        { role: 'user', content: 'Hello, how are you?' }\n      ]\n    })\n  });\n\n  for await (const { data } of parser.sse(true /* event.data is json, except the last one '[DONE]' */)) {\n    console.log(data.choices?.[0] || data);\n  }\n})().catch(console.error);\n```\nResults looks like:\n```\n{\n  index: 0,\n  delta: { role: 'assistant', content: '' },\n  finish_reason: null\n}\n{ index: 0, delta: { content: 'Hello' }, finish_reason: null }\n{ index: 0, delta: { content: '!' }, finish_reason: null }\n{ index: 0, delta: { content: ' I' }, finish_reason: null }\n{ index: 0, delta: { content: \"'m\" }, finish_reason: null }\n{ index: 0, delta: { content: ' an' }, finish_reason: null }\n{ index: 0, delta: { content: ' AI' }, finish_reason: null }\n{ index: 0, delta: { content: ' assistant' }, finish_reason: null }\n{ index: 0, delta: { content: ',' }, finish_reason: null }\n{ index: 0, delta: { content: ' so' }, finish_reason: null }\n{ index: 0, delta: { content: ' I' }, finish_reason: null }\n{ index: 0, delta: { content: ' don' }, finish_reason: null }\n{ index: 0, delta: { content: \"'t\" }, finish_reason: null }\n{ index: 0, delta: { content: ' have' }, finish_reason: null }\n{ index: 0, delta: { content: ' feelings' }, finish_reason: null }\n{ index: 0, delta: { content: ',' }, finish_reason: null }\n{ index: 0, delta: { content: ' but' }, finish_reason: null }\n{ index: 0, delta: { content: ' I' }, finish_reason: null }\n{ index: 0, delta: { content: \"'m\" }, finish_reason: null }\n{ index: 0, delta: { content: ' here' }, finish_reason: null }\n{ index: 0, delta: { content: ' to' }, finish_reason: null }\n{ index: 0, delta: { content: ' help' }, finish_reason: null }\n{ index: 0, delta: { content: ' you' }, finish_reason: null }\n{ index: 0, delta: { content: '.' }, finish_reason: null }\n{ index: 0, delta: { content: ' How' }, finish_reason: null }\n{ index: 0, delta: { content: ' can' }, finish_reason: null }\n{ index: 0, delta: { content: ' I' }, finish_reason: null }\n{ index: 0, delta: { content: ' assist' }, finish_reason: null }\n{ index: 0, delta: { content: ' you' }, finish_reason: null }\n{ index: 0, delta: { content: ' today' }, finish_reason: null }\n{ index: 0, delta: { content: '?' }, finish_reason: null }\n{ index: 0, delta: {}, finish_reason: 'stop' }\n[DONE]\n```\n\nOr write data to stdout, you will feel it is typing the response.\n```js\n  for await (const { data } of parser.sse(true)) {\n    const delta = data.choices?.[0].delta?.content;\n    if (delta) process.stdout.write(delta);\n  }\n```\n\n### sse\nIf the data source is [Server Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)\n```js\nasync function foo() {\n  const parser = await fetchParser('https://your/stream/url', opts);\n  for await (const evt of paser.sse(true /* if the data of event is json format. */)) {\n    console.log(evt.event, evt.id, evt.data);\n  }\n}\n```\n\n#### lines\n```js\nasync function foo() {\n  const parser = await fetchParser('https://your/stream/url', opts);\n  for await (const line of paser.lines()) {\n    console.log(line);\n  }\n}\n```\n\n#### json data\nIf every non-empty line is valid json:\n```js\nasync function foo() {\n  const parser = await fetchParser('https://your/stream/url', opts);\n  for await (const j of paser.json()) {\n    console.log(j);\n  }\n}\n```\n\n#### chunks\n```js\nasync function foo() {\n  const parser = await fetchParser('https://your/stream/url', opts);\n  for await (const chunk of paser.chunks()) {\n    console.log(chunk);\n  }\n}\n```","readmeFilename":"README.md"}