diff --git a/README.md b/README.md index 6e1b2a1..03e9a57 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,20 @@ $ npm install -g lodash $ cat package.json | fx 'require("lodash").keys(this.dependencies)' ``` +### Formatting + +If you need something different then JSON (for example arguments for xargs) do not return anything from reducer. +Undefined value printed into stderr by default. +``` +echo '[]' | fx 'void 0' +undefined +``` + +``` +echo '[1,2,3]' | fx 'this.forEach(x => console.log(x))' 2>/dev/null | xargs echo +1 2 3 +``` + ### Other examples Convert object to array: diff --git a/index.js b/index.js index 3c7e39c..0610cc6 100755 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ async function main() { const result = cli.input.reduce(reduce, json) if (typeof result === 'undefined') { - console.log(undefined) + process.stderr.write('undefined\n') } else { const text = JSON.stringify(result, null, 4) console.log(highlight(text, {theme}))