Pipe terminal commands into JavaScript
$ npm i -g js-shell
$ ls | js 'lines.map(line => line.toUpperCase())'
These are the variables passed into the context of the script:
data
: One string of all the incoming data.
items
: Incoming data split into array from newlines, then each line contains line
(whole line) and parts
which is the line split by whitespace.
lines
: Incoming data split into array from newlines.
parts
: Incoming data split into array from newlines, then each line is split by whitespace (two-dimensional array).
console
: Directly mapped console
for convenience, e.g., lines.forEach(line => console.log(line))
.
Find all files larger than 10K
Parse JSON (similar to jq)
Stringify JSON (similar to jo)
Similar to iostreamer-X/Awkward except this is meant to be used between pipes of other commands, e.g., while doing bash scripting.
MIT © Eirik Brandtzæg