Write undefined to stderr

js-version
Anton Medvedev 6 years ago
parent 3a728d66e4
commit 4b8a4bfe3c

@ -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:

@ -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}))

Loading…
Cancel
Save