{"_id":"capture-console","_rev":"6-bf3ccfb28d851d5d3adab53da9f218fa","name":"capture-console","description":"Simple and easy stdio capture for Node.js","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"capture-console","version":"1.0.0","description":"Simple and easy stdio capture for Node.js","author":{"name":"Isaac Whitfield","email":"iw@zackehh.com"},"repository":{"type":"git","url":"git+ssh://git@github.com/zackehh/capture-console.git"},"bugs":{"url":"http://github.com/zackehh/capture-console/issues","email":"iw@zackehh.com"},"license":"MIT","keywords":["stdio","stderr","stdout","logging","capture","console","intercept"],"scripts":{"test":"mocha -u tdd test/index.js"},"dependencies":{"argle":"~1.1.1","lodash.isfunction":"~3.0.8","randomstring":"~1.1.5"},"devDependencies":{"mocha":"^3.2.0","should":"^11.2.0"},"gitHead":"e2853bd7aad6f5981fd0ba6719fc459de8fc030f","homepage":"https://github.com/zackehh/capture-console#readme","_id":"capture-console@1.0.0","_shasum":"d91607dc486816e0bf5e69a3065bd6b55c9db5fa","_from":".","_npmVersion":"4.1.2","_nodeVersion":"6.9.4","_npmUser":{"name":"zackehh","email":"iw@zackehh.com"},"dist":{"shasum":"d91607dc486816e0bf5e69a3065bd6b55c9db5fa","tarball":"https://registry.npmjs.org/capture-console/-/capture-console-1.0.0.tgz","integrity":"sha512-6qgCCYo4VLutGaWDaCkqOo/ZaL6ewmjPCVsjcve77TxOMTGSe0Y35G6yqwYtzPYBKnhEzqT/NTgTFEW1/gdjfg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHqDf9w+goiE96aZ0r5WNY4PrHqhZHQZTWNuBFMFWvZ0AiEA4Fy52ZwfYctfHx1zIALoAP7W0N4mypPnnCUtCcsUI50="}]},"maintainers":[{"name":"zackehh","email":"iw@zackehh.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/capture-console-1.0.0.tgz_1486492051109_0.9423192758113146"},"directories":{}},"1.0.1":{"name":"capture-console","version":"1.0.1","description":"Simple and easy stdio capture for Node.js","author":{"name":"Isaac Whitfield","email":"iw@zackehh.com"},"repository":{"type":"git","url":"git+ssh://git@github.com/zackehh/capture-console.git"},"bugs":{"url":"http://github.com/zackehh/capture-console/issues","email":"iw@zackehh.com"},"license":"MIT","keywords":["stdio","stderr","stdout","logging","capture","console","intercept"],"scripts":{"test":"mocha -u tdd test/index.js"},"dependencies":{"argle":"~1.1.1","lodash.isfunction":"~3.0.8","randomstring":"~1.1.5"},"devDependencies":{"mocha":"^3.2.0","should":"^11.2.0"},"gitHead":"e870587698d8f101e32bdd2699be4b979315010a","homepage":"https://github.com/zackehh/capture-console#readme","_id":"capture-console@1.0.1","_shasum":"db63c39ac73239019badd7fbb10143eda380ff71","_from":".","_npmVersion":"4.1.2","_nodeVersion":"6.9.4","_npmUser":{"name":"zackehh","email":"iw@zackehh.com"},"dist":{"shasum":"db63c39ac73239019badd7fbb10143eda380ff71","tarball":"https://registry.npmjs.org/capture-console/-/capture-console-1.0.1.tgz","integrity":"sha512-gUPJV8XKeCK7//SLa6XhI2a9Y+FtatkjrebAcldL5ilGhvfvJXALiJO2lMqBf6vkqWvrZ9nm/vcxxiNNwMsSbw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCIA6fDyOVxeRcw6/AgZYJwQ6G/cydgTTO6Mru+R10grAIhAMYFXoFyeh0OX8FZpwQKy5BV69oj/hSNbs1CCLpKFU16"}]},"maintainers":[{"name":"zackehh","email":"iw@zackehh.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/capture-console-1.0.1.tgz_1486493234966_0.7323556568007916"},"directories":{}},"1.0.2":{"name":"capture-console","version":"1.0.2","description":"Simple and easy stdio capture for Node.js","author":{"name":"Isaac Whitfield","email":"iw@whitfin.io"},"repository":{"type":"git","url":"git+ssh://git@github.com/whitfin/capture-console.git"},"bugs":{"url":"http://github.com/whitfin/capture-console/issues","email":"iw@whitfin.io"},"license":"MIT","keywords":["stdio","stderr","stdout","logging","capture","console","intercept"],"scripts":{"lint":"eslint lib/* test/*.js *.js","test":"mocha -u tdd test/index.js"},"dependencies":{"argle":"~1.1.1","lodash.isfunction":"~3.0.8","randomstring":"^1.3.0"},"devDependencies":{"eslint":"^8.53.0","mocha":"^10.2.0","should":"^13.2.3"},"gitHead":"3c690046c168eadcd0d4961bb6d8cc141a21220b","homepage":"https://github.com/whitfin/capture-console#readme","_id":"capture-console@1.0.2","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-vQNTSFr0cmHAYXXG3KG7ZJQn0XxC3K2di/wUZVb6yII6gqSN/10Egd3vV4XqJ00yCRNHy2wkN4uWHE+rJstDrw==","shasum":"742d370705566a5a1ccbda7ba500691e577cc774","tarball":"https://registry.npmjs.org/capture-console/-/capture-console-1.0.2.tgz","fileCount":5,"unpackedSize":12251,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGZF4fIJ8AJ2PbLI47NHaPdfr0AG0Pq2jfAzMD5ZFsmAAiEAj10mZaJgk1lh/lDawTqqJGiWXOc+hTrlQZBKsO83dH4="}]},"_npmUser":{"name":"whitfin","email":"iw@whitfin.io"},"directories":{},"maintainers":[{"name":"whitfin","email":"iw@whitfin.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/capture-console_1.0.2_1699949104177_0.23644773253557383"},"_hasShrinkwrap":false}},"readme":"# capture-console\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/whitfin/capture-console/ci.yml?branch=main)](https://github.com/whitfin/capture-console/actions) [![Published Version](https://img.shields.io/npm/v/capture-console.svg)](https://npmjs.com/package/capture-console) [![Published Downloads](https://img.shields.io/npm/dt/capture-console)](https://npmjs.com/package/capture-console)\n\ncapture-console is a small Node.js library built to help when capturing log output via `process.stdout` and `process.stderr`. The main use case is unit testing (which is why I built it), but there's no reason it can't be used in production code paths.\n\n### Installation\n\ncapture-console lives on npm, so just install it via the command line and you're good to go.\n\n```\n$ npm install --save-dev capture-console\n```\n\n### Usage\n\nThere are a whole bunch of ways to use `capture-console`, mainly due to scoping, with the two easiest defined below. Depending on your use case you might be pushed more towards one than the other, but in general you can just choose your preference.\n\n#### Scoped Captures\n\nThe easiest way to use `capture-console` is with scoping; this is when the output of a provided function is captured.\n\nNote that this form assumes synchronous execution - async stuff will require manual hookups (below).\n\n```javascript\nconst capcon = require('capture-console');\n\nlet stderr = capcon.captureStderr(() => {\n  // whatever is done in here has stderr captured,\n  // the return value is a string containing stderr\n});\n\nlet stdout = capcon.captureStdout(() => {\n  // whatever is done in here has stdout captured,\n  // the return value is a string containing stdout\n});\n\nlet stdio = capcon.captureStdio(() => {\n  // whatever is done in here has both stdout and stderr captured,\n  // the return value is an object with 'stderr' and 'stdout' keys\n});\n```\n\n#### Manual Captures\n\nThere are also ways to manually stop and start a capture context, by passing a process stream to watch and a callback to fire on each message.\n\n```javascript\nconst capcon = require('capture-console');\n\n// our buffer\nlet output = '';\n\n// the first parameter here is the stream to capture, and the\n// second argument is the function receiving the output\ncapcon.startCapture(process.stdout, stdout => {\n  output += stdout;\n});\n\n// whatever is done here has stdout captured - but note\n// that `output` is updated throughout execution\n\ncapcon.stopCapture(process.stdout);\n\n// anything logged here is no longer captured\n```\n\n### Intercepting\n\nYou should be aware that all `capture` functions will still pass the values through to the main stdio `write()` functions, so logging will still go to your standard IO devices.\n\nIf this is not desirable, you can use the `intercept` functions. These functions are literally `s/capture/intercept` when compared to those shown above, and the only difference is that calls aren't forwarded through to the base implementation.\n","maintainers":[{"name":"whitfin","email":"iw@whitfin.io"}],"time":{"modified":"2023-11-14T08:05:04.638Z","created":"2017-02-07T18:27:32.976Z","1.0.0":"2017-02-07T18:27:32.976Z","1.0.1":"2017-02-07T18:47:15.196Z","1.0.2":"2023-11-14T08:05:04.409Z"},"homepage":"https://github.com/whitfin/capture-console#readme","keywords":["stdio","stderr","stdout","logging","capture","console","intercept"],"repository":{"type":"git","url":"git+ssh://git@github.com/whitfin/capture-console.git"},"author":{"name":"Isaac Whitfield","email":"iw@whitfin.io"},"bugs":{"url":"http://github.com/whitfin/capture-console/issues","email":"iw@whitfin.io"},"license":"MIT","readmeFilename":"README.md"}