{"_id":"hook-std","_rev":"4129751","name":"hook-std","description":"Hook and modify stdout and stderr","dist-tags":{"latest":"4.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-03-01T18:30:42.000Z","created":"2015-12-13T19:36:01.427Z","4.0.0":"2025-09-09T19:53:24.525Z","3.0.0":"2021-09-17T18:37:09.042Z","2.0.0":"2019-04-05T06:10:56.170Z","1.2.0":"2018-11-20T14:50:10.522Z","1.1.0":"2018-07-17T11:19:28.821Z","1.0.1":"2018-06-10T07:49:55.431Z","1.0.0":"2018-06-08T18:09:30.750Z","0.4.0":"2017-04-26T05:46:03.736Z","0.3.0":"2017-02-18T06:47:24.414Z","0.2.0":"2016-01-12T11:58:26.710Z","0.1.0":"2015-12-13T19:36:01.427Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"versions":{"4.0.0":{"name":"hook-std","version":"4.0.0","description":"Hook and modify stdout and stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && ava && tsd"},"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"@types/node":"^24.3.1","ava":"^6.4.1","tsd":"^0.33.0","xo":"^1.2.2"},"ava":{"serial":true},"_id":"hook-std@4.0.0","gitHead":"dfd8e540d6c157a94c97ca7dfbe5c3a91110d304","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_nodeVersion":"20.19.1","_npmVersion":"10.9.2","dist":{"shasum":"8ad817e2405f0634fa128822a8b27054a8120262","size":3591,"noattachment":false,"key":"/hook-std/-/hook-std-4.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-4.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hook-std_4.0.0_1757447604349_0.19063105075070808"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-09-09T19:53:24.525Z","publish_time":1757447604525,"_source_registry_name":"default","_cnpm_publish_time":1757447604525},"3.0.0":{"name":"hook-std","version":"3.0.0","description":"Hook and modify stdout and stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && ava && tsd"},"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"@types/node":"^16.9.2","ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"ava":{"serial":true},"gitHead":"9cff60c517afe15d205460f4f5e298fc5a10e720","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_id":"hook-std@3.0.0","_nodeVersion":"12.22.1","_npmVersion":"7.20.3","dist":{"shasum":"47038a01981e07ce9d83a6a3b2eb98cad0f7bd58","size":2940,"noattachment":false,"key":"/hook-std/-/hook-std-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-3.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hook-std_3.0.0_1631903828891_0.13854417280732334"},"_hasShrinkwrap":false,"publish_time":1631903829042,"_cnpm_publish_time":1631903829042},"2.0.0":{"name":"hook-std","version":"2.0.0","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"@types/node":"^11.13.0","ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"a61e22616bbf4036d662e56cd0ec5bfd2c5a76d8","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_id":"hook-std@2.0.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"ff9aafdebb6a989a354f729bb6445cf4a3a7077c","size":3094,"noattachment":false,"key":"/hook-std/-/hook-std-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-2.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hook-std_2.0.0_1554444655980_0.80891180133258"},"_hasShrinkwrap":false,"publish_time":1554444656170,"_cnpm_publish_time":1554444656170},"1.2.0":{"name":"hook-std","version":"1.2.0","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"@types/node":"^10.12.9","ava":"^0.25.0","tsd-check":"^0.2.1","xo":"^0.23.0"},"gitHead":"f429639e9d60ae3259a17cd4aefaf62a9e4f15c1","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_id":"hook-std@1.2.0","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"b37d533ea5f40068fe368cb4d022ee1992588c27","size":2901,"noattachment":false,"key":"/hook-std/-/hook-std-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-1.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hook-std_1.2.0_1542725410406_0.9173615132436459"},"_hasShrinkwrap":false,"publish_time":1542725410522,"_cnpm_publish_time":1542725410522},"1.1.0":{"name":"hook-std","version":"1.1.0","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"a2ab03642aaf055259e4259c473c02eeb149e45a","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_id":"hook-std@1.1.0","_npmVersion":"6.2.0","_nodeVersion":"8.11.3","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"7f76b74b6f96d3cd4106afb50a66bdb0af2d2a2d","size":2357,"noattachment":false,"key":"/hook-std/-/hook-std-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-1.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hook-std_1.1.0_1531826368711_0.42516100920996225"},"_hasShrinkwrap":false,"publish_time":1531826368821,"_cnpm_publish_time":1531826368821},"1.0.1":{"name":"hook-std","version":"1.0.1","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"6942796f0c65e38d737f7e07b1787dd30efa0b53","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_id":"hook-std@1.0.1","_npmVersion":"5.6.0","_nodeVersion":"8.11.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"fc91e6836c5b174f405dc4b57aa2228e4c599981","size":2231,"noattachment":false,"key":"/hook-std/-/hook-std-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-1.0.1.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hook-std_1.0.1_1528616995359_0.16988802648085288"},"_hasShrinkwrap":false,"publish_time":1528616995431,"_cnpm_publish_time":1528616995431},"1.0.0":{"name":"hook-std","version":"1.0.0","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"69f1a9f4148c129eea9813bdeb06acb8f6b88ec4","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_id":"hook-std@1.0.0","_npmVersion":"6.1.0","_nodeVersion":"8.11.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"e72708fd9cccf435c9a2243ffd65418eff25f342","size":2178,"noattachment":false,"key":"/hook-std/-/hook-std-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hook-std_1.0.0_1528481370666_0.3802871925092197"},"_hasShrinkwrap":false,"publish_time":1528481370750,"_cnpm_publish_time":1528481370750},"0.4.0":{"name":"hook-std","version":"0.4.0","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"bc2dd621545e7c9e3eb5830b038792cc26132fde","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_id":"hook-std@0.4.0","_shasum":"fa8b2f84d358763137cb7d17e3308b28714bd174","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.7.3","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"fa8b2f84d358763137cb7d17e3308b28714bd174","size":2008,"noattachment":false,"key":"/hook-std/-/hook-std-0.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-0.4.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/hook-std-0.4.0.tgz_1493185561709_0.32538316608406603"},"directories":{},"publish_time":1493185563736,"_cnpm_publish_time":1493185563736,"_hasShrinkwrap":false},"0.3.0":{"name":"hook-std","version":"0.3.0","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/hook-std.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"af811485be685c57f524c4c67539cf20cba2ed3e","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std#readme","_id":"hook-std@0.3.0","_shasum":"1e75f0658967ac1f9d7c17b9ec6ebd993f8828e5","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.5.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"1e75f0658967ac1f9d7c17b9ec6ebd993f8828e5","size":1958,"noattachment":false,"key":"/hook-std/-/hook-std-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-0.3.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/hook-std-0.3.0.tgz_1487400444171_0.9513783762231469"},"directories":{},"publish_time":1487400444414,"_cnpm_publish_time":1487400444414,"_hasShrinkwrap":false},"0.2.0":{"name":"hook-std","version":"0.2.0","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"https://github.com/sindresorhus/hook-std"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=0.10.0"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"e586fa81f25cf22a0c3faa3f306b7d45a2832932","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std","_id":"hook-std@0.2.0","_shasum":"ea51c136b0196fada7595ec8de95014034ca1fe6","_from":".","_npmVersion":"2.14.12","_nodeVersion":"4.2.4","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"ea51c136b0196fada7595ec8de95014034ca1fe6","size":1949,"noattachment":false,"key":"/hook-std/-/hook-std-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-0.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"publish_time":1452599906710,"_cnpm_publish_time":1452599906710,"_hasShrinkwrap":false},"0.1.0":{"name":"hook-std","version":"0.1.0","description":"Hook and modify stdout/stderr","license":"MIT","repository":{"type":"git","url":"https://github.com/sindresorhus/hook-std"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=0.10.0"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["hook","intercept","capture","modify","change","test","assert","check","std","stdio","stdout","stderr","console","log","process"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"a5c2cc2810dba9e4c4f5672b546e576cbd2d61d0","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"homepage":"https://github.com/sindresorhus/hook-std","_id":"hook-std@0.1.0","_shasum":"381c466373e424f34d1bd912c2a96597b0e9ce3c","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"381c466373e424f34d1bd912c2a96597b0e9ce3c","size":1856,"noattachment":false,"key":"/hook-std/-/hook-std-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hook-std/download/hook-std-0.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"publish_time":1450035361427,"_cnpm_publish_time":1450035361427,"_hasShrinkwrap":false}},"readme":"# hook-std\n\n> Hook and modify stdout and stderr\n\n## Install\n\n```sh\nnpm install hook-std\n```\n\n## Usage\n\n```js\nimport assert from 'node:assert';\nimport {hookStdout} from 'hook-std';\n\nconst promise = hookStdout(output => {\n\tpromise.unhook();\n\tassert.strictEqual(output.trim(), 'unicorn');\n});\n\nconsole.log('unicorn');\nawait promise;\n```\n\nYou can also unhook using the second `transform` method parameter:\n\n```js\nimport assert from 'node:assert';\nimport {hookStdout} from 'hook-std';\n\nconst promise = hookStdout((output, unhook) => {\n\tunhook();\n\tassert.strictEqual(output.trim(), 'unicorn');\n});\n\nconsole.log('unicorn');\nawait promise;\n```\n\nAutomatically collect output without a transform function:\n\n```js\nimport {hookStdout} from 'hook-std';\n\nconst promise = hookStdout();\nconsole.log('unicorn');\nconsole.log('rainbow');\nconsole.log(promise.output); // 'unicorn\\nrainbow\\n'\npromise.unhook();\nawait promise;\n```\n\n## API\n\n### hookStd(options?, transform?)\n\nHook streams in [`streams` option](#streams), or stdout and stderr if none are specified.\n\nReturns a `Promise` with a `unhook()` method which, when called, unhooks both stdout and stderr and resolves the `Promise` with an empty result. The returned promise also has an `output` property to access the collected output.\n\nWhen hooking multiple streams, the `output` property contains the interleaved output in the order the writes occurred:\n\n```js\nimport {hookStd} from 'hook-std';\n\nconst promise = hookStd();\nprocess.stdout.write('A');\nprocess.stderr.write('B');\nprocess.stdout.write('C');\nconsole.log(promise.output); // 'ABC' (interleaved in order)\npromise.unhook();\n```\n\n### hookStdout(options?, transform?)\n\nHook stdout.\n\nReturns a `Promise` with a `unhook()` method which, when called, unhooks stdout and resolves the `Promise` with an empty result. The returned promise also has an `output` property to access the collected output.\n\n### hookStderr(options?, transform?)\n\nHook stderr.\n\nReturns a `Promise` with a `unhook()` method which, when called, unhooks stderr and resolves the `Promise` with an empty result. The returned promise also has an `output` property to access the collected output.\n\n#### options\n\nType: `object`\n\n##### silent\n\nType: `boolean`\\\nDefault: `true`\n\nSuppress stdout/stderr output.\n\n##### once\n\nType: `boolean`\\\nDefault: `false`\n\nAutomatically unhook after the first call.\n\n##### streams\n\nType: `stream.Writable[]`\\\nDefault: `[process.stdout, process.stderr]`\n\nThe [writable streams](https://nodejs.org/api/stream.html#stream_writable_streams) to hook. This can be useful for libraries allowing users to configure a writable stream to write to.\n\n#### transform\n\nType: `Function`\n\nReceives stdout/stderr as the first argument and the unhook method as the second argument. Return a string to modify it. Optionally, when in silent mode, you may return a `boolean` to influence the return value of `.write(…)`.\n\nOutput is automatically collected and can be accessed via the `output` property of the returned promise, regardless of whether a transform function is provided.\n","_attachments":{},"homepage":"https://github.com/sindresorhus/hook-std#readme","bugs":{"url":"https://github.com/sindresorhus/hook-std/issues"},"license":"MIT"}