{"name":"iterable-ndjson","version":"1.0.0","description":"ndjson to async iterator","main":"index.js","scripts":{"test":"standard && nyc --reporter=lcov --reporter=text ava --verbose"},"repository":{"type":"git","url":"git+https://github.com/alanshaw/iterable-ndjson.git"},"keywords":["ndjson","json","async","iterator","iterable"],"author":{"name":"Alan Shaw"},"license":"MIT","bugs":{"url":"https://github.com/alanshaw/iterable-ndjson/issues"},"homepage":"https://github.com/alanshaw/iterable-ndjson#readme","devDependencies":{"ava":"^1.2.1","nyc":"^13.2.0","standard":"^12.0.1"},"dependencies":{"string_decoder":"^1.2.0"},"gitHead":"2a677775f33ba8a3d60cf5adddc7e38a404e2d53","_id":"iterable-ndjson@1.0.0","_npmVersion":"6.5.0","_nodeVersion":"11.9.0","_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"dist":{"integrity":"sha512-4AS0/OAKeEThKBpzbDK+LLJK0GtT6bAdJd7ANEAIIugKjG96/gZzuaYSNYofUOzfKpJe0k6CfomQJJpGfcb06g==","shasum":"0946ae5c506074abbe85d37ee1639c1ec46689c2","tarball":"http://registry-npm.ywwl.com/iterable-ndjson/download/iterable-ndjson-1.0.0.tgz","fileCount":5,"unpackedSize":5459,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcYsLOCRA9TVsSAnZWagAA1YQP/3RDD7rA9Nt0YGa7HZco\ny5pVZRH0ABsDICpgUZD13JgZwaZqSUziH2d6mct5YF2eyU5B9UcBoLk/2OKJ\nNrTuMF85PK2AKuWvZqav7I+0jViLCPqVUbdauWXZtOthVf4nSX6K1cleSEOo\nVSK9RE0xZ23KrWLeWj9zNEsI+yqmBtGh8aR6GDX4QMSlwz3V89cMZx7R9IsG\ncyGFtrh2tbe9iKkgOey8hSXzSkQEmrf9GiF7EqrDPsUAxIdZvNU5+lBXO3ye\nF/b66Ubj7sj2cu8EQTW0DttIfFKHoel53KtVZwx/8Yj86/9KJnpNtSPUAKFY\n7V2nzKE2zTzqw8UfpmB4WLJprSoe2h4kL1wefe/NwzQwjuVBBBiFGXJdH4O2\nDO7P1MF6hLoQoRuBsxZY/PJiv8uNyTeFr2ku3jlB2dBT+7pdotlFhMdNjoj5\n6MycRj+vmZVv2Khkldoj7miEG3kiSs4+rOLwzjRebowsMHRV2pKS6wm8Nd3r\nR/jkPu8IHOalzdNmQsOYePq4B69igc0dQsoaiKkia5FBoc70RgcxSRYWS/73\nz7Qc5+3AGanlbvNcpqoTRseWWjxdllDj9MrHijyUVfcyEbqONKnS9HlxwKvI\n6oihnrv0k+DhyxvyGml7rfkcKdpDm02a987DVmdKMqWs8dchZW5nh0GZuHXA\nwk7T\r\n=5mwu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCFFYH0ZS94O4oq2KB5tDqA2gwzVCZLNFL3i/Ossgxu5QIgLd/vC31cwj+xbHv+qD36FABmjQvqEfbb0uJAmCJxERk="}],"size":1787,"noattachment":false,"key":"/iterable-ndjson/-/iterable-ndjson-1.0.0.tgz"},"maintainers":[{"name":"alanshaw","email":"alan138@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/iterable-ndjson_1.0.0_1549976270276_0.9716075569007288"},"_hasShrinkwrap":false,"readme":"# iterable-ndjson\n\n[![Build Status](https://travis-ci.org/alanshaw/iterable-ndjson.svg?branch=master)](https://travis-ci.org/alanshaw/iterable-ndjson)\n[![dependencies Status](https://david-dm.org/alanshaw/iterable-ndjson/status.svg)](https://david-dm.org/alanshaw/iterable-ndjson)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n> Takes an (async) iterable that yields ndjson and returns an async iterable that yields JS objects\n\n## Install\n\n```sh\nnpm install iterable-ndjson\n```\n\n## Usage\n\n```js\nconst ndjson = require('iterable-ndjson')\nconst it = ndjson.parse(source) // where `source` is any iterable that yields ndjson\n\nfor await (const obj of it)\n  console.log(obj)\n```\n\n### Examples\n\nNode.js streams are async iterable:\n\n```js\nconst ndjson = require('iterable-ndjson')\nconst fs = require('fs')\nconst source = fs.createReadStream('/path/to/file.ndjson')\n\nfor await (const obj of ndjson.parse(source))\n  console.log(obj)\n```\n\nAsync iterable:\n\n```js\nconst ndjson = require('iterable-ndjson')\n\n// An ndjson async iterator\nconst source = (() => {\n  const array = ['{\"id\": 1}\\n', '{\"id\"', ': 2}', '\\n{\"id\": 3}\\n']\n  return {\n    [Symbol.asyncIterator] () {\n      return this\n    },\n    async next () {\n      await new Promise(resolve => setTimeout(resolve))\n      return array.length\n        ? { done: false, value: array.shift() }\n        : { done: true }\n    }\n  }\n})()\n\nasync function main () {\n  for await (const obj of ndjson.parse(source))\n    console.log(obj)\n    // Logs out:\n    // { id: 1 }\n    // { id: 2 }\n    // { id: 3 }\n}\n\nmain()\n```\n\nAsync iterable generator:\n\n```js\nconst ndjson = require('iterable-ndjson')\n\n// An ndjson async iterator\nconst source = (async function * () {\n  const array = ['{\"id\": 1}\\n', '{\"id\"', ': 2}', '\\n{\"id\": 3}\\n']\n  for (let i = 0; i < array.length; i++) {\n    yield new Promise(resolve => setTimeout(() => resolve(array[i])))\n  }\n})()\n\nasync function main () {\n  for await (const obj of ndjson.parse(source))\n    console.log(obj)\n    // Logs out:\n    // { id: 1 }\n    // { id: 2 }\n    // { id: 3 }\n}\n\nmain()\n```\n\nRegular iterable (like an array):\n\n```js\nconst ndjson = require('iterable-ndjson')\nconst source = ['{\"id\": 1}\\n', '{\"id\"', ': 2}', '\\n{\"id\": 3}\\n']\n\nasync function main () {\n  for await (const obj of ndjson.parse(source))\n    console.log(obj)\n    // Logs out:\n    // { id: 1 }\n    // { id: 2 }\n    // { id: 3 }\n}\n\nmain()\n```\n\nStringify JS objects to NDJSON:\n\n```js\nconst ndjson = require('iterable-ndjson')\nconst source = [{ id: 1 }, { id: 2 }, { id: 3 }]\n\nasync function main () {\n  for await (const obj of ndjson.stringify(source))\n    console.log(obj)\n    // Logs out:\n    // '{\"id\":1}\\n'\n    // '{\"id\":2}\\n'\n    // '{\"id\":3}\\n'\n}\n\nmain()\n```\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/alanshaw/iterable-ndjson/issues/new) or submit PRs.\n\n## License\n\n[MIT](LICENSE) © Alan Shaw\n","publish_time":1549976270423,"_cnpm_publish_time":1549976270423,"dist-tags":{"latest":"1.1.0"}}