output-interceptor
v4.1.0
Published
Intercepts stdout/ stderr.
Downloads
1,162
Readme
output-interceptor
Intercepts stdout/ stderr.
Implementation
This module uses domain
to capture asynchronous function output.
Read Capturing stdout/ stderr in Node.js using Domain module.
Usage
import {
createOutputInterceptor
} from 'output-interceptor';
const interceptOutput = createOutputInterceptor();
const main = async () => {
const result = await interceptOutput(() => {
console.log('foo');
console.error('bar');
return Promise.resolve('baz');
});
result === 'baz';
interceptOutput.output === 'foo\nbar\n';
};
main();
API
/**
* @property interceptStderr Default: true.
* @property interceptStdout Default: true.
* @property stripAnsi Default: true.
*/
export type OutputInterceptorUserConfigurationType = {|
+interceptStderr?: boolean,
+interceptStdout?: boolean,
+stripAnsi?: boolean
|};
/**
* @returns Intercepted output.
*/
type FlushType = () => string;
/**
* @property output Output produced during the executing of the `routine`.
*/
export type OutputInterceptorType = {|
<T>(routine: () => Promise<T> | T): Promise<T>,
output: ''
|};
createOutputInterceptor(userConfiguration?: OutputInterceptorUserConfigurationType): OutputInterceptorType;