{"id":15390280,"url":"https://github.com/gajus/output-interceptor","last_synced_at":"2026-03-15T09:39:25.766Z","repository":{"id":57316938,"uuid":"164966212","full_name":"gajus/output-interceptor","owner":"gajus","description":"Intercepts stdout/ stderr.","archived":false,"fork":false,"pushed_at":"2020-01-30T17:11:16.000Z","size":27,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T01:34:33.047Z","etag":null,"topics":["async","interceptor","stderr","stdout"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gajus.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":"2019-01-10T01:23:06.000Z","updated_at":"2024-07-06T21:58:52.000Z","dependencies_parsed_at":"2022-08-25T21:11:28.518Z","dependency_job_id":null,"html_url":"https://github.com/gajus/output-interceptor","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Foutput-interceptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Foutput-interceptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Foutput-interceptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Foutput-interceptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gajus","download_url":"https://codeload.github.com/gajus/output-interceptor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249157960,"owners_count":21222031,"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":["async","interceptor","stderr","stdout"],"created_at":"2024-10-01T15:05:13.099Z","updated_at":"2026-03-15T09:39:20.735Z","avatar_url":"https://github.com/gajus.png","language":"JavaScript","readme":"# output-interceptor\n\n[![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/slonik?style=flat-square)](https://gitspo.com/mentions/gajus/slonik)\n[![Travis build status](http://img.shields.io/travis/gajus/output-interceptor/master.svg?style=flat-square)](https://travis-ci.org/gajus/output-interceptor)\n[![Coveralls](https://img.shields.io/coveralls/gajus/output-interceptor.svg?style=flat-square)](https://coveralls.io/github/gajus/output-interceptor)\n[![NPM version](http://img.shields.io/npm/v/output-interceptor.svg?style=flat-square)](https://www.npmjs.org/package/output-interceptor)\n[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social\u0026label=Follow)](https://twitter.com/kuizinas)\n\nIntercepts stdout/ stderr.\n\n## Implementation\n\nThis module uses [`domain`](https://nodejs.org/api/domain.html) to capture asynchronous function output.\n\nRead [Capturing stdout/ stderr in Node.js using Domain module](https://medium.com/@gajus/capturing-stdout-stderr-in-node-js-using-domain-module-3c86f5b1536d).\n\n## Usage\n\n```js\nimport {\n  createOutputInterceptor\n} from 'output-interceptor';\n\nconst interceptOutput = createOutputInterceptor();\n\nconst main = async () =\u003e {\n  const result = await interceptOutput(() =\u003e {\n    console.log('foo');\n    console.error('bar');\n\n    return Promise.resolve('baz');\n  });\n\n  result === 'baz';\n\n  interceptOutput.output === 'foo\\nbar\\n';\n};\n\nmain();\n\n```\n\n### Singleton or dependency injection pattern\n\nIt is recommended that you only create one instance of output-interceptor per entire project, e.g.\n\nCreate `./routines.js` file with contents:\n\n```js\nimport {\n  createOutputInterceptor\n} from 'output-interceptor';\n\nexport const interceptOutput = createOutputInterceptor();\n\n```\n\nThen just import the `{interceptOutput}` routine from elsewhere in your codebase.\n\nAlternatively, create an instance of output-interceptor at the top of the program and pass it down using dependency injection.\n\nThe benefit of this approach is that you do not create unnecessary wrappers around `process.stderr.write` and `process.stdout.write`.\n\n## API\n\n```js\n/**\n * @property interceptStderr Default: true.\n * @property interceptStdout Default: true.\n * @property stripAnsi Default: true.\n */\nexport type OutputInterceptorUserConfigurationType = {|\n  +interceptStderr?: boolean,\n  +interceptStdout?: boolean,\n  +stripAnsi?: boolean\n|};\n\n/**\n * @returns Intercepted output.\n */\ntype FlushType = () =\u003e string;\n\n/**\n * @property output Output produced during the executing of the `routine`.\n */\nexport type OutputInterceptorType = {|\n  \u003cT\u003e(routine: () =\u003e Promise\u003cT\u003e | T): Promise\u003cT\u003e,\n  output: ''\n|};\n\ncreateOutputInterceptor(userConfiguration?: OutputInterceptorUserConfigurationType): OutputInterceptorType;\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Foutput-interceptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgajus%2Foutput-interceptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Foutput-interceptor/lists"}