{"id":15680544,"url":"https://github.com/doowb/capture-stream","last_synced_at":"2025-05-07T10:34:24.480Z","repository":{"id":55574309,"uuid":"43000978","full_name":"doowb/capture-stream","owner":"doowb","description":"Capture stream output.","archived":false,"fork":false,"pushed_at":"2020-12-21T09:24:52.000Z","size":12,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T10:33:47.884Z","etag":null,"topics":["node-streams","nodejs","stderr","stdio","stdio-stream","stdout","streams","test","testing","tests","unit-testing","unittest"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doowb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-23T12:59:05.000Z","updated_at":"2021-04-12T21:51:43.000Z","dependencies_parsed_at":"2022-08-15T03:30:32.168Z","dependency_job_id":null,"html_url":"https://github.com/doowb/capture-stream","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fcapture-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fcapture-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fcapture-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fcapture-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/capture-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252860140,"owners_count":21815475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node-streams","nodejs","stderr","stdio","stdio-stream","stdout","streams","test","testing","tests","unit-testing","unittest"],"created_at":"2024-10-03T16:42:43.427Z","updated_at":"2025-05-07T10:34:24.373Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","readme":"# capture-stream [![NPM version](https://img.shields.io/npm/v/capture-stream.svg)](https://www.npmjs.com/package/capture-stream) [![Build Status](https://img.shields.io/travis/doowb/capture-stream.svg)](https://travis-ci.org/doowb/capture-stream)\n\n\u003e Capture stream output.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install capture-stream --save\n```\n\n## Usage\n\n```js\nvar capture = require('capture-stream');\nvar restore = capture(process.stdout);\n\nconsole.log('Hello, world!!!');\nconsole.log('foo', 'bar');\n\nvar output = restore();\nconsole.log(output);\n//=\u003e [ [ 'Hello, world!!!\\n' ], [ 'foo bar\\n' ] ]\n```\n\nPass `true` to `restore` to return a string instead of an array of output.\n\n```js\nvar capture = require('capture-stream');\nvar restore = capture(process.stdout);\n\nconsole.log('Hello, world!!!');\nconsole.log('foo', 'bar');\n\nvar output = restore(true);\nconsole.log(output);\n//=\u003e Hello, world!!!\n//=\u003e foo bar\n//=\u003e\n```\n\nThis module has been built to be used in unit tests to easily capture output from `process.stdout` and `process.stderr` and test the results.\n\n```js\ndescribe('awesome module', function () {\n  function log () {\n    console.log.apply(console, arguments);\n  }\n\n  it('should write \"Hello, world!!!\" to stdout', function () {\n    var restore = capture(process.stdout);\n    log('Hello, world!!!');\n    var output = restore();\n    assert.equal(output.length, 1);\n    assert(output[0][0].indexOf('Hello, world!!!') === 0);\n  });\n});\n```\n\n## API\n\n### [captureStream](index.js#L27)\n\nCapture the output from a stream and store later.\n\n**Params**\n\n* `stream` **{Stream}**: A stream to capture output from (e.g. `process.stdout`, `process.stderr`)\n* `returns` **{Function}** `restore`: function that restores normal output and returns an array of output.\n\n**Example**\n\n```js\nvar restore = capture(process.stdout);\nconsole.log('Hello, world!!!');\nconsole.log('foo', 'bar');\n\nvar output = restore();\nconsole.log(output);\n//=\u003e [ [ 'Hello, world!!!\\n' ], [ 'foo bar\\n' ] ]\n```\n\n## Related projects\n\n* [composer-errors](https://www.npmjs.com/package/composer-errors): Listen for and output Composer errors. | [homepage](https://github.com/doowb/composer-errors)\n* [composer-runtimes](https://www.npmjs.com/package/composer-runtimes): Write composer task start and end times to a stream. | [homepage](https://github.com/doowb/composer-runtimes)\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/capture-stream/issues/new).\n\n## Building docs\n\nGenerate readme and API documentation with [verb][]:\n\n```sh\n$ npm install verb \u0026\u0026 npm run docs\n```\n\nOr, if [verb][] is installed globally:\n\n```sh\n$ verb\n```\n\n## Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 npm test\n```\n\n## Author\n\n**Brian Woodward**\n\n* [github/doowb](https://github.com/doowb)\n* [twitter/doowb](http://twitter.com/doowb)\n\n## License\n\nCopyright © 2016 [Brian Woodward](https://github.com/doowb)\nReleased under the [MIT license](https://github.com/doowb/capture-stream/blob/master/LICENSE).\n\n***\n\n_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on March 19, 2016._","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fcapture-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fcapture-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fcapture-stream/lists"}