{"name":"iterable-ndjson","version":"1.0.1","description":"ndjson to async iterator","main":"index.js","browser":"browser.js","scripts":{"test":"npm run test:node && npm run test:browser","test:node":"tape test.js","test:browser":"webpack --config webpack.test.config.js && cat output/test.js | tape-puppet","coverage":"standard && nyc --reporter=lcov --reporter=text tape test.js"},"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":{"nyc":"^13.2.0","standard":"^12.0.1","tape":"^4.10.1","tape-puppet":"^0.1.7","webpack":"^4.29.6","webpack-cli":"^3.2.3"},"dependencies":{"string_decoder":"^1.2.0"},"gitHead":"828a995e415382278153b7584646f973be7f4d17","_id":"iterable-ndjson@1.0.1","_nodeVersion":"11.10.0","_npmVersion":"6.7.0","_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"dist":{"integrity":"sha512-722WM6FIo0Kb5N7+G49nZ5w2IcL7v1tTl1BFrVUvV+eAsSaUL/pZ8AK/kUOL6s0Dtglcoo/4FeHEjUThbYOjcA==","shasum":"e5797b120cfc41df61d555f4d6a92bfc5e78f441","tarball":"http://registry-npm.ywwl.com/iterable-ndjson/download/iterable-ndjson-1.0.1.tgz","fileCount":8,"unpackedSize":8574,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcgPJyCRA9TVsSAnZWagAAbkIP/jstjOZGISerb+j2V+gd\nDsq9XhR4ZoM8L54hVFBGNOzDO6qc6E+Z7XQNaXrLVrPIFremTmSleoSSB9MJ\n97A4rxmm27G0Y+Sv2QHOI7RyjOYezWtp/tHi7thjHd7jrB27OoUTF1oqscEL\n4elbG7WMqxUECNPLKvj577fzl7C74YH6m0M5yOhBZNeWd/oNLsLH0d3JeweO\nQN+uaIhVZNrtdDmvFtp74xkxxZnSE9EGswld+6S9YD4qBnVy5Ovd/kJhCxvj\nWyu0V23MCn0UIcavUTu2ekQFO6gnf6VNiJzX6TTKuUhAkDnTAKDae0vzh/tI\nA0nijKy/7DKwXvHPSSKAudnFl8RAZWXTYOib4FRtWGC8lJDcvA+p6lHww0Wb\niKg2OAccsT3e1js9uSYGWzTWNOMrSgehb1DnI0xkKZxbs+vvyeHIk9HTBhge\nc1GTA/v3Dk3Iu8CzjL4SYexAwy1lh5vJK+vqd/v5/LiwdUaT947os8ruGZGj\n0KbxGe75CXCj3McN2uhhLlhWh1hwk+CTashr1F6noPQlBEC09azAA5noGT3m\n18y42vX5fv0LVy4ux0n6JWCodi+FkIHTeo/gj85CHcGNUAqtv23nfBYoZS65\nfWZaC1DujYcJqVkG7SdcTddjJfvbWHjspPG2RO/+2DMGP8ZgH/VlilWenN9z\nRD9r\r\n=S79k\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDxPMkyKfMTAdky4+Yq3cEJr4ei5lBKYloEjEhRg1Cb1gIhAKQzfaK7c5PpSN7cseZLKxRzgwtOCokxUYMe7AUrqWFZ"}],"size":2951,"noattachment":false,"key":"/iterable-ndjson/-/iterable-ndjson-1.0.1.tgz"},"maintainers":[{"name":"alanshaw","email":"alan138@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/iterable-ndjson_1.0.1_1551954545413_0.3223599279035978"},"_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":1551954545510,"_cnpm_publish_time":1551954545510,"dist-tags":{"latest":"1.1.0"}}