{"name":"meros","version":"1.0.0-beta.8","description":"A fast utility for reading streamed multipart responses.","keywords":["multipart","multipart mixed","fetch","utility","reader"],"repository":{"type":"git","url":"git+https://github.com/maraisr/meros.git"},"license":"MIT","author":{"name":"Marais Rossouw","email":"me@marais.dev","url":"https://marais.io"},"exports":{".":{"import":"./node/index.mjs","browser":"./browser/index.mjs","require":"./node/index.js"},"./node":{"import":"./node/index.mjs","require":"./node/index.js"},"./browser":{"import":"./browser/index.mjs","require":"./browser/index.js"}},"unpkg":"browser/index.min.js","browser":"browser/index.mjs","module":"node/index.mjs","main":"node/index.js","types":"index.d.ts","scripts":{"bench":"node -r ts-node/register -r ./test/_polyfill.js bench/index.ts","typecheck":"tsc --noEmit","build":"rollup -c","format":"prettier  --write --list-different \"{*,.github/**/*}.+(json|yml|md)\"","prepublishOnly":"yarn build","test":"uvu -r ts-node/register -r ./test/_polyfill.js -i _polyfill -i mocks test"},"prettier":{"bracketSpacing":true,"printWidth":80,"proseWrap":"always","singleQuote":true,"tabWidth":4,"trailingComma":"all","useTabs":true,"overrides":[{"files":["*.md"],"options":{"useTabs":false,"tabWidth":2}}]},"devDependencies":{"@marais/tsconfig":"0.0.1","@rollup/plugin-node-resolve":"10.0.0","@types/benchmark":"2.1.0","@types/node":"14.14.7","benchmark":"2.1.4","fetch-multipart-graphql":"2.2.0","it-multipart":"1.0.5","prettier":"2.1.2","rollup":"2.33.1","rollup-plugin-dts":"^1.4.14","rollup-plugin-terser":"7.0.2","rollup-plugin-typescript2":"0.29.0","ts-node":"9.0.0","typescript":"4.0.5","uvu":"0.4.1"},"volta":{"node":"15.2.0","yarn":"1.22.5"},"readme":"# `meros` &middot; <small>From Ancient Greek μέρος (méros, \"part\").</small>\n\n[![CI](https://img.shields.io/github/workflow/status/maraisr/meros/CI/main)](https://github.com/maraisr/meros/actions?query=workflow:CI+branch:main)\n[![codecov](https://img.shields.io/codecov/c/gh/maraisr/meros/main?token=dAoRt2GoQn)](https://codecov.io/gh/maraisr/meros)\n\n> A fast (761B) utility for reading streamed multipart/mixed responses.\n\n## ⚡ Features\n\n- No dependencies\n- Super [performant](#-benchmark)\n- Supports _any_<sup>1</sup> `content-type`\n- Supports `content-length`<sup>2</sup>\n- _preamble_ and _epilogue_ don't yield\n- Browser-Compatible\n- Plugs into existing libraries like Relay and rxjs\n\n## ⚙️ Install\n\n```sh\nyarn add meros\n```\n\n## 🚀 Usage\n\n```ts\n// Rely on bundler/environment dection\nimport { meros } from 'meros';\n\nconst parts = await fetch('/fetch-multipart').then(meros);\n\n// As a simple Async Generator\nfor await (const part of parts) {\n  // Do something with this part\n}\n\n// Used with rxjs streams\nfrom(parts).pipe(\n  tap((part) => {\n    // Do something with it\n  }),\n);\n```\n\n## _Specific Environment_\n\n```ts\n// Browser\nimport { meros } from 'meros/browser';\n// import { meros } from 'https://cdn.skypack.dev/meros';\n\nconst parts = await fetch('/fetch-multipart').then(meros);\n\n// Node\nimport http from 'http';\nimport { meros } from 'meros/node';\n\nconst response = await new Promise((resolve) => {\n  const request = http.get(`http://my-domain/mock-ep`, (response) => {\n    resolve(response);\n  });\n  request.end();\n});\n\nconst parts = await meros(response);\n```\n\n## 🎒 Notes\n\nThis library aims to implement [RFC1341] in its entirety, however we aren't\nthere yet. That being said, you may very well use this library in other\nscenarios like streaming in file form uploads.\n\nPlease note; be sure to define a boundary that can be guaranteed to never\ncollide with things from the body:\n\n> _Because encapsulation boundaries must not appear in the body parts being\n> encapsulated, a user agent must exercise care to choose a unique boundary._\n>\n> <small>~ [RFC1341] 7.2.1</small>\n\n### _Caveats_\n\n- No support the `/alternative` , `/digest` _or_ `/parallel` subtype at this\n  time.\n- No support for\n  [nested multiparts](https://tools.ietf.org/html/rfc1341#appendix-C)\n\n## 🔎 API\n\n### _Browser_\n\n```ts\nfunction meros<T = object>(\n  response: Response,\n): Promise<\n  | Response\n  | AsyncGenerator<\n      | { json: true; headers: Record<string, string>; body: T }\n      | { json: false; headers: Record<string, string>; body: string }\n    >\n>;\n```\n\n### _Node_\n\n```ts\nfunction meros<T = object>(\n  response: IncomingMessage,\n): Promise<\n  | IncomingMessage\n  | AsyncGenerator<\n      | { json: true; headers: Record<string, string>; body: T }\n      | { json: false; headers: Record<string, string>; body: Buffer }\n    >\n>;\n```\n\nReturns an async generator that yields on every part. Worth noting that if\nmultiple parts are present in one chunk, each part will yield independently.\n\n> If the `content-type` is **NOT** a multipart, then it will resolve with the\n> response argument. Or really any unhandled cases, we'll resolve with the\n> response.\n>\n> <details>\n> <summary>Example on how to handle this case</summary>\n>\n> ```ts\n> import { meros } from 'meros';\n>\n> const response = await fetch('/fetch-multipart'); // Assume this returns json\n> const parts = await meros(response);\n>\n> if (parts[Symbol.asyncIterator] < 'u') {\n>   for await (const part of parts) {\n>     // Do something with this part\n>   }\n> } else {\n>   const data = await parts.json();\n> }\n> ```\n>\n> </details>\n\n## 💨 Benchmark\n\n```\nValidation :: node\n✔ meros\n✘ it-multipart (FAILED @ \"should match reference patch set\")\n\nBenchmark :: node\n  meros                     x 27,354 ops/sec ±0.83% (83 runs sampled)\n  it-multipart              x 14,956 ops/sec ±1.18% (78 runs sampled)\n\nValidation :: browser\n✔ meros\n✘ fetch-multipart-graphql (FAILED @ \"should match reference patch set\")\n\nBenchmark :: browser\n  meros                     x 30,077 ops/sec ±0.92% (80 runs sampled)\n  fetch-multipart-graphql   x 14,089 ops/sec ±0.65% (80 runs sampled)\n```\n\n> Ran with Node v15.1.0\n\n## ❤ Thanks\n\nSpecial thanks to [Luke Edwards](https://github.com/lukeed) for performance\nguidance and high level api design.\n\n## License\n\nMIT © [Marais Rossouw](https://marais.io)\n\n<details>\n<summary>Footnote</summary>\n\n> 1: By default, we'll look for JSON, and parse that for you. If not, we'll give\n> you the body as what was streamed.</small>\n>\n> 2: If not given, everything from the body through boundary will yield\n\n</details>\n\n[rfc1341]: https://tools.ietf.org/html/rfc1341 'The Multipart Content-Type'\n","readmeFilename":"readme.md","gitHead":"1c6391225256886988f3acb770baef56779e745a","bugs":{"url":"https://github.com/maraisr/meros/issues"},"homepage":"https://github.com/maraisr/meros#readme","_id":"meros@1.0.0-beta.8","_nodeVersion":"15.2.0","_npmVersion":"7.0.8","dist":{"integrity":"sha512-Q412DEQCCZDwGtud7/UbDRCbAcuDPZoIRgubZWdacJqSKv5N09Dff4nPp+Zp2+7kB0N3edXIfsCBx5eqXK3Xew==","shasum":"faea3f3be7c0a5220616ca62725be5b2c722af0b","tarball":"http://registry-npm.ywwl.com/meros/download/meros-1.0.0-beta.8.tgz","fileCount":11,"unpackedSize":25903,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJftGdACRA9TVsSAnZWagAAh3cQAIjwzLPaDWehtC5ruk3M\nIzKfc6b4WU3qeuMnRb9rJTbGEexNUukzMv0rsx/pEtGnLGvZtnPKMj7H6k2B\nqtl94S/fqzoRU18KpJ9JcY7tQdiz62/gcr1pXtVSQNTx51zp50m/qUyiN/iZ\nS+bxLGpx91WZbsTZ5BZc/+4oSNhQLj+CrUe3Qrgb7NxFFIW3UVhZtIkB0AYp\nAUiRZr4ishOr2UJe7gaMDSCVMMhhJWP+t/ZJaFitx5huXCU8Id9nDtYPTBs8\nxjlLocBZ4z1T0cTHjBG1pQgaZ+bYlfQ9wiQVc4Ga3MpIurF4gyqeqH2ol8H8\nq0AZVshsWHkxBAEhzgDDWrkVQ36R3/IjKkvX3Ri/y3P2I3rJ2MgmGEM1Gf0d\n9WhUPJO9V5zYwFNGL/SDBIkbvd7Db1qSIKsRACScYRp4PDx0MaF97298qmFY\nlt9FTG6/jf5ld5ha1NynGI9FY7ud7tV6/Hc+dsZRCfaj/g2e2gEzlS+lQmCZ\nnrke2Sp1Mswqv5qmM4Xv21LLb4ytijO5/Ux4Q4zNf06FqPoFEnpW7qZE3Ufx\nm9gPeZjIsetV9mU/AoIZgttDq81a06vvHg8tV65sFSbzHSylq5+dA2noQ8+H\niF29ONEBoKYW3QhwJFGIC+wfOaJNDZTbVv9LAWKC3Fpx8clYvvvJQlHPDjW+\nnCYe\r\n=SOnA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFaPCIK+xN98MaypjkGCzx79xHEOZ6wPL7Evtc4WCdwXAiEAjQGN4/QmhKdTKg3BG0vYqGVIISUKWR1pEPblqW6kjfk="}],"size":6211,"noattachment":false,"key":"/meros/-/meros-1.0.0-beta.8.tgz"},"_npmUser":{"name":"marais","email":"me@maraisr.com"},"directories":{},"maintainers":[{"name":"marais","email":"me@maraisr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/meros_1.0.0-beta.8_1605658432109_0.42835780205970697"},"_hasShrinkwrap":false,"publish_time":1605658432243,"_cnpm_publish_time":1605658432243,"dist-tags":{"beta":"1.1.0-beta.2","latest":"1.3.2","next":"1.2.0-next.4"}}