+13
-4
@@ -9,3 +9,6 @@ 'use strict'; | ||
| opts = Object.assign({silent: true}, opts); | ||
| opts = Object.assign({ | ||
| silent: true, | ||
| once: false | ||
| }, opts); | ||
@@ -15,5 +18,13 @@ const std = process[type]; | ||
| const unhook = () => { | ||
| std.write = write; | ||
| }; | ||
| std.write = (str, enc, cb2) => { | ||
| const cbRet = cb(str, enc); | ||
| if (opts.once) { | ||
| unhook(); | ||
| } | ||
| if (opts.silent) { | ||
@@ -27,5 +38,3 @@ return typeof cbRet === 'boolean' ? cbRet : true; | ||
| return () => { | ||
| std.write = write; | ||
| }; | ||
| return unhook; | ||
| } | ||
@@ -32,0 +41,0 @@ |
+1
-1
| { | ||
| "name": "hook-std", | ||
| "version": "0.3.0", | ||
| "version": "0.4.0", | ||
| "description": "Hook and modify stdout/stderr", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+7
-0
@@ -58,2 +58,9 @@ # hook-std [](https://travis-ci.org/sindresorhus/hook-std) | ||
| ##### once | ||
| Type: `boolean`<br> | ||
| Default: `false` | ||
| Automatically unhooks after the first call. | ||
| ##### callback | ||
@@ -60,0 +67,0 @@ |
3923
4.73%38
22.58%75
10.29%