EXJ(1) exj NAME exj - node.js standard input processor SYNOPSIS exj [OPTIONS] 'fn' exj [OPTIONS] -f | --file 'fnfile' DESCRIPTION Exj executes the given fn upon the standard input. Fn is expected to be a JavaScript function expression. The result of fn execution is printed to standard output. If the result type of fn is a string, the result is printed directly to standard output. If the result type of fn is null or undefined, no action is taken. Any other result type is converted to JSON using JSON.stringify() and pretty-printed to standard output. If the result of fn is a Promise, the promise will be resolved and the result printed according to the above rules. GLOBALS EXEC A tagged template string which will execute escape and execute the contents as a child process, similar to running with -x EXAMPLE - print all files in the current directory: echo ls | exj -l 'x => EXEC`cat ${x}`' OPTIONS -j, --json Treat the input text as JSON. Input text will be parsed to JavaScript objects using JSON.parse() before being passed to fn. -p, --pretty Pretty print JSON output -l, --line Process each line of input separately. For each line of standard input, fn will be invoked for each line encountered, and the result will be written to standard output. -x, --exec Execute each output entry as a child process. The standard output of the finished process will be written to standard out. NOTE: Output entry MUST be an array of the format ['executable', 'arg1', 'arg2', ...] -f, --file 'fnfile' Read fn from a file, whose path is located at 'fnfile'. -g, --group-lines 'num' When processing lines, group batches of num lines together as an array -c, --concurrency 'num' When executing results via --exec option, execute at most num commands at once. Concurrency level also applies to awaiting of Promise results: no more lines of input will be processed while 'num' results are in flight. -r, --require package[:alias] An NPM package to be required into the namespace of 'fn', with optional alias --help Print usage text EXAMPLES ls | exj -l 'x => x.toUpperCase()' Print the contents of the current directory in uppercase curl https://jsonplaceholder.typicode.com/photos \ | exj -j 'res => res.map((image) => `${image.title} - ${image.thumbnailUrl}`).join("\n")' | pbcopy Fetch and process a JSON payload of album artwork to the clipboard ls *.js | exj -lx 'x => ["mv", x, x.replace(/\.js$/, ".ts")]' convert javascript files to typescript cat urls.txt -l --concurrency 5 --require 'node-fetch:fetch' 'url => fetch(url).then(r => r.json())' Fetch the json contents of a list of URLs, fetching up to five URLs simultaneously SEE ALSO awk(1), jq(1), xargs(1)
-
Notifications
You must be signed in to change notification settings - Fork 1
sberan/exj
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
command line utility for processing standard input using node.js
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published