{
  "_id": "peek-stream",
  "maintainers": [
    {
      "name": "mafintosh",
      "email": "mathiasbuus@gmail.com"
    }
  ],
  "keywords": [
    "peek",
    "stream",
    "parse",
    "swap"
  ],
  "dist-tags": {
    "latest": "1.1.3"
  },
  "author": {
    "name": "Mathias Buus"
  },
  "_rev": "12-920abf6bf762d140e19a44f408106f73",
  "description": "Transform stream that lets you peek the first line before deciding how to parse it",
  "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",
  "repository": {
    "type": "git",
    "url": "git://github.com/mafintosh/peek-stream.git"
  },
  "users": {
    "timhudson": true
  },
  "bugs": {
    "url": "https://github.com/mafintosh/peek-stream/issues"
  },
  "license": "MIT",
  "versions": {
    "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": "mathiasbuus@gmail.com"
        }
      ],
      "dist": {
        "shasum": "cdfea6d156dec38bac396e0e86561f17ca38b5f6",
        "tarball": "https://archive.ito.gov.ir/npm/_packages/peek-stream/-/peek-stream-1.0.0.tgz",
        "integrity": "sha512-vCqrJSmfZKw4VH6aGbkN6NjqqOg6t8V6in7kcykdfw+Katg5ujltF4YouIS7ugZROf2Ls+0geD7T4nH2a+ywxg==",
        "signatures": [
          {
            "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
            "sig": "MEQCID9Ph1eKH3dspe4Iu7FTh+KxbCA9SzsmMGH2mL8AZGOiAiBcF4118UI9xO0QS8GyqihV+9ATXCLrK8Z5x8/hahWTSQ=="
          }
        ]
      },
      "directories": {}
    },
    "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": "mathiasbuus@gmail.com"
        }
      ],
      "dist": {
        "shasum": "3a84321e40cf0530769928e4c5b4eb90f1784208",
        "tarball": "https://archive.ito.gov.ir/npm/_packages/peek-stream/-/peek-stream-1.1.0.tgz",
        "integrity": "sha512-S7bhDqCYmSpFvMGYGPSjeY0O/ZKy8SGZYSpZPHzRpaIRqegYfwqQ7c/Zv+evWPODhxDRQEfYrExfbiGz3xK7Ag==",
        "signatures": [
          {
            "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
            "sig": "MEYCIQCoKTu+Z7MV3lUFk7WmhKFtswMWySIZXqDCKNUhW/zXRAIhAIgxl7qFh4VBgs3/llUUd9j+76ovZay3Ij0VWf9TQJ7b"
          }
        ]
      },
      "directories": {}
    },
    "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": "mathiasbuus@gmail.com"
        }
      ],
      "dist": {
        "shasum": "5324259966a9c97ce2f0470f67c23bf248f8e7f0",
        "tarball": "https://archive.ito.gov.ir/npm/_packages/peek-stream/-/peek-stream-1.1.1.tgz",
        "integrity": "sha512-Oqeh8S2GsUeRZGydUDs0hF9+od5tDQENO9A7vjx117uaHAdlOaOpw+Giox06Wxim9Iwy7ZCfcrDyU4nUi30YUg==",
        "signatures": [
          {
            "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
            "sig": "MEUCIB2YHl7JcMSIKwmMS9zsqLAUqenn2m78EA2aOHxxCR2zAiEA+OZQnp9uT0zVQOp19N+pAzPLqrX9a7zMvB/5Xmh+hGQ="
          }
        ]
      },
      "directories": {}
    },
    "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",
        "tarball": "https://archive.ito.gov.ir/npm/_packages/peek-stream/-/peek-stream-1.1.2.tgz",
        "integrity": "sha512-pygLfZnYswOTCPV/AW/9K2Y+fC2Gzv19D2wGefz5Sqfcq6+k4MbgtlyV1T65Y0cf8qfJFOPqUNliX59EGCchEw==",
        "signatures": [
          {
            "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
            "sig": "MEUCIQDHGQP8TBvCgML/JZ4d2jf2QC6kceHpQocXdoQt3B83RQIgKy4QqwI88XDhoyRdZS6md+iZ8Ph11LDGXANSXgByk7o="
          }
        ]
      },
      "maintainers": [
        {
          "name": "mafintosh",
          "email": "mathiasbuus@gmail.com"
        }
      ],
      "_npmOperationalInternal": {
        "host": "packages-12-west.internal.npmjs.com",
        "tmp": "tmp/peek-stream-1.1.2.tgz_1491653057530_0.8997211237438023"
      },
      "directories": {}
    },
    "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": {
        "integrity": "sha512-FhJ+YbOSBb9/rIl2ZeE/QHEsWn7PqNYt8ARAY3kIgNGOk13g9FGyIY6JIl/xB/3TFRVoTv5as0l11weORrTekA==",
        "shasum": "3b35d84b7ccbbd262fff31dc10da56856ead6d67",
        "tarball": "https://archive.ito.gov.ir/npm/_packages/peek-stream/-/peek-stream-1.1.3.tgz",
        "fileCount": 7,
        "unpackedSize": 8156,
        "signatures": [
          {
            "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
            "sig": "MEQCIHuWRgLBMsTgOiU5kBlk1m+XO6+Kc/rW5rBvfkvJOIMGAiAIUhCV4Y9Casiz7JpEMP5go59SgLdQ1iITp1Rmj9Bk8Q=="
          }
        ]
      },
      "maintainers": [
        {
          "name": "mafintosh",
          "email": "mathiasbuus@gmail.com"
        }
      ],
      "directories": {},
      "_npmOperationalInternal": {
        "host": "s3://npm-registry-packages",
        "tmp": "tmp/peek-stream_1.1.3_1521673907391_0.47990638016893583"
      },
      "_hasShrinkwrap": false
    }
  },
  "name": "peek-stream",
  "time": {
    "modified": "2026-05-13T13:50:47.141Z",
    "created": "2014-07-23T15:19:14.308Z",
    "1.0.0": "2014-07-23T15:19:14.308Z",
    "1.1.0": "2014-07-23T15:56:35.802Z",
    "1.1.1": "2014-07-25T19:10:18.389Z",
    "1.1.2": "2017-04-08T12:04:19.459Z",
    "1.1.3": "2018-03-21T23:11:47.457Z"
  },
  "readmeFilename": "README.md",
  "homepage": "https://github.com/mafintosh/peek-stream"
}