{"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":{"integrity":"sha512-IHI4bEVOt3vRUDJ+bFA9VUJlo7SzvFARPNLw75pqSmAOP2HmTWfFJtPvLBrDrlgjEYXY9zs7SFdHPQaJShkSCQ==","shasum":"8ad817e2405f0634fa128822a8b27054a8120262","tarball":"http://registry-npm.ywwl.com/hook-std/download/hook-std-4.0.0.tgz","fileCount":5,"unpackedSize":12920,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDFU2dAaNF34sP0pyETCtlgqnOHRvfiJaaUIP3cTcgbxgIgOAwMXmUZ1CtYZk80bfQCWwdH1uei1BgQPxzdnG/DXQA="}],"size":3591,"noattachment":false,"key":"/hook-std/-/hook-std-4.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hook-std_4.0.0_1757447604349_0.19063105075070808"},"_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","publish_time":1757447604525,"_cnpm_publish_time":1757447604525,"dist-tags":{"latest":"4.0.0"}}