{"id":13454908,"url":"https://github.com/sindresorhus/hook-std","last_synced_at":"2025-07-08T16:33:26.789Z","repository":{"id":55420209,"uuid":"47933131","full_name":"sindresorhus/hook-std","owner":"sindresorhus","description":"Hook and modify stdout and stderr","archived":false,"fork":false,"pushed_at":"2022-07-09T03:07:47.000Z","size":65,"stargazers_count":54,"open_issues_count":3,"forks_count":12,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-30T17:11:41.296Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-12-13T19:29:13.000Z","updated_at":"2025-01-07T20:11:17.000Z","dependencies_parsed_at":"2022-08-15T00:00:27.647Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/hook-std","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fhook-std","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fhook-std/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fhook-std/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fhook-std/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/hook-std/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332495,"owners_count":20921851,"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":[],"created_at":"2024-07-31T08:00:59.283Z","updated_at":"2025-04-06T19:13:05.134Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# hook-std\n\n\u003e 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 =\u003e {\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) =\u003e {\n\tunhook();\n\tassert.strictEqual(output.trim(), 'unicorn');\n});\n\nconsole.log('unicorn');\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.\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.\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.\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","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","包","目录","Testing","Number"],"sub_categories":["Testing","测试","测试相关"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fhook-std","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fhook-std","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fhook-std/lists"}