{"_id":"peek-stream","_rev":"148974","name":"peek-stream","description":"Transform stream that lets you peek the first line before deciding how to parse it","dist-tags":{"latest":"1.1.3"},"maintainers":[{"name":"mafintosh","email":""}],"time":{"modified":"2021-06-03T11:31:16.000Z","created":"2014-07-23T15:19:14.308Z","1.1.3":"2018-03-21T23:11:47.457Z","1.1.2":"2017-04-08T12:04:19.459Z","1.1.1":"2014-07-25T19:10:18.389Z","1.1.0":"2014-07-23T15:56:35.802Z","1.0.0":"2014-07-23T15:19:14.308Z"},"users":{"timhudson":true},"author":{"name":"Mathias Buus"},"repository":{"type":"git","url":"git://github.com/mafintosh/peek-stream.git"},"versions":{"1.1.3":{"name":"peek-stream","version":"1.1.3","description":"Transform stream that lets you peek the first line before deciding how to parse it","main":"index.js","dependencies":{"buffer-from":"^1.0.0","duplexify":"^3.5.0","through2":"^2.0.3"},"devDependencies":{"concat-stream":"^1.6.0","tape":"^4.6.3"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git://github.com/mafintosh/peek-stream.git"},"keywords":["peek","stream","parse","swap"],"author":{"name":"Mathias Buus"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/peek-stream/issues"},"homepage":"https://github.com/mafintosh/peek-stream","gitHead":"93ee7f3ef52de411293be0e6b37edcd541b9d756","_id":"peek-stream@1.1.3","_npmVersion":"5.6.0","_nodeVersion":"9.7.1","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"3b35d84b7ccbbd262fff31dc10da56856ead6d67","size":3004,"noattachment":false,"key":"/peek-stream/-/peek-stream-1.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/peek-stream/download/peek-stream-1.1.3.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/peek-stream_1.1.3_1521673907391_0.47990638016893583"},"_hasShrinkwrap":false,"publish_time":1521673907457,"_cnpm_publish_time":1521673907457},"1.1.2":{"name":"peek-stream","version":"1.1.2","description":"Transform stream that lets you peek the first line before deciding how to parse it","main":"index.js","dependencies":{"duplexify":"^3.5.0","through2":"^2.0.3"},"devDependencies":{"concat-stream":"^1.6.0","tape":"^4.6.3"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git://github.com/mafintosh/peek-stream.git"},"keywords":["peek","stream","parse","swap"],"author":{"name":"Mathias Buus"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/peek-stream/issues"},"homepage":"https://github.com/mafintosh/peek-stream","gitHead":"c444747273f0f9b55aea3f38f36ea1540c3e3673","_id":"peek-stream@1.1.2","_shasum":"97eb76365bcfd8c89e287f55c8b69d4c3e9bcc52","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.9.5","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"97eb76365bcfd8c89e287f55c8b69d4c3e9bcc52","size":3008,"noattachment":false,"key":"/peek-stream/-/peek-stream-1.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/peek-stream/download/peek-stream-1.1.2.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/peek-stream-1.1.2.tgz_1491653057530_0.8997211237438023"},"directories":{},"publish_time":1491653059459,"_hasShrinkwrap":false,"_cnpm_publish_time":1491653059459},"1.1.1":{"name":"peek-stream","version":"1.1.1","description":"Transform stream that lets you peek the first line before deciding how to parse it","main":"index.js","dependencies":{"duplexify":"^3.0.1","through2":"^0.5.1"},"devDependencies":{"concat-stream":"^1.4.6","tape":"^2.13.4"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git://github.com/mafintosh/peek-stream"},"keywords":["peek","stream","parse","swap"],"author":{"name":"Mathias Buus"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/peek-stream/issues"},"homepage":"https://github.com/mafintosh/peek-stream","gitHead":"2496fd5f39c06ef3c53426c7b24ce63f01cfc831","_id":"peek-stream@1.1.1","_shasum":"5324259966a9c97ce2f0470f67c23bf248f8e7f0","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"maintainers":[{"name":"mafintosh","email":""}],"dist":{"shasum":"5324259966a9c97ce2f0470f67c23bf248f8e7f0","size":2364,"noattachment":false,"key":"/peek-stream/-/peek-stream-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/peek-stream/download/peek-stream-1.1.1.tgz"},"directories":{},"publish_time":1406315418389,"_cnpm_publish_time":1406315418389,"_hasShrinkwrap":false},"1.1.0":{"name":"peek-stream","version":"1.1.0","description":"Transform stream that lets you peek the first line before deciding how to parse it","main":"index.js","dependencies":{"duplexify":"^3.0.0","through2":"^0.5.1"},"devDependencies":{"concat-stream":"^1.4.6","tape":"^2.13.4"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git://github.com/mafintosh/peek-stream"},"keywords":["peek","stream","parse","swap"],"author":{"name":"Mathias Buus"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/peek-stream/issues"},"homepage":"https://github.com/mafintosh/peek-stream","gitHead":"abeb3591cbb943d79bf610de8ec6d5a61d268d7f","_id":"peek-stream@1.1.0","_shasum":"3a84321e40cf0530769928e4c5b4eb90f1784208","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"maintainers":[{"name":"mafintosh","email":""}],"dist":{"shasum":"3a84321e40cf0530769928e4c5b4eb90f1784208","size":2362,"noattachment":false,"key":"/peek-stream/-/peek-stream-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/peek-stream/download/peek-stream-1.1.0.tgz"},"directories":{},"publish_time":1406130995802,"_cnpm_publish_time":1406130995802,"_hasShrinkwrap":false},"1.0.0":{"name":"peek-stream","version":"1.0.0","description":"Transform stream that lets you peek the first line before deciding how to parse it","main":"index.js","dependencies":{"duplexify":"^3.0.0","through2":"^0.5.1"},"devDependencies":{"concat-stream":"^1.4.6","tape":"^2.13.4"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git://github.com/mafintosh/peek-stream"},"keywords":["peek","stream","parse","swap"],"author":{"name":"Mathias Buus"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/peek-stream/issues"},"homepage":"https://github.com/mafintosh/peek-stream","gitHead":"13f3b52cf59063ce63bd2502c5a6027a6ed295e9","_id":"peek-stream@1.0.0","_shasum":"cdfea6d156dec38bac396e0e86561f17ca38b5f6","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"maintainers":[{"name":"mafintosh","email":""}],"dist":{"shasum":"cdfea6d156dec38bac396e0e86561f17ca38b5f6","size":2340,"noattachment":false,"key":"/peek-stream/-/peek-stream-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/peek-stream/download/peek-stream-1.0.0.tgz"},"directories":{},"publish_time":1406128754308,"_cnpm_publish_time":1406128754308,"_hasShrinkwrap":false}},"readme":"# peek-stream\n\nTransform stream that lets you peek the first line before deciding how to parse it\n\n```\nnpm install peek-stream\n```\n\n[![build status](http://img.shields.io/travis/mafintosh/peek-stream.svg?style=flat)](http://travis-ci.org/mafintosh/peek-stream)\n![dat](http://img.shields.io/badge/Development%20sponsored%20by-dat-green.svg?style=flat)\n\n## Usage\n\n``` js\nvar peek = require('peek-stream')\nvar ldjson = require('ldjson-stream')\nvar csv = require('csv-parser')\n\nvar isCSV = function(data) {\n  return data.toString().indexOf(',') > -1\n}\n\nvar isJSON = function(data) {\n  try {\n    JSON.parse(data)\n    return true\n  } catch (err) {\n    return false\n  }\n}\n\n// call parser to create a new parser\nvar parser = function() {\n  return peek(function(data, swap) {\n    // maybe it is JSON?\n    if (isJSON(data)) return swap(null, ldjson())\n\n    // maybe it is CSV?\n    if (isCSV(data)) return swap(null, csv())\n\n    // we do not know - bail\n    swap(new Error('No parser available'))\n  })\n}\n```\n\nThe above parser will be able to parse both line delimited JSON and CSV\n\n``` js\nvar parse = parser()\n\nparse.write('{\"hello\":\"world\"}\\n{\"hello\":\"another\"}\\n')\nparse.on('data', function(data) {\n  console.log(data) // prints {hello:'world'} and {hello:'another'}\n})\n```\n\nOr\n\n``` js\nvar parse = parser()\n\nparse.write('test,header\\nvalue-1,value-2\\n')\nparse.on('data', function(data) {\n  console.log(data) // prints {test:'value-1', header:'value-2'}\n})\n```\n\nPer default `data` is the first line (or the first `65535` bytes if no newline is found).\nTo change the max buffer pass an options map to the constructor\n\n``` js\nvar parse = peek({\n  maxBuffer: 10000\n}, function(data, swap) {\n  ...\n})\n```\n\nIf you want to emit an error if no newline is found set `strict: true` as well.\n\n\n## License\n\nMIT","_attachments":{},"homepage":"https://github.com/mafintosh/peek-stream","bugs":{"url":"https://github.com/mafintosh/peek-stream/issues"},"license":"MIT"}