node-shell-helper
v0.1.2
Published
Helper functions for shell scripting.
Downloads
4
Readme
Node Shell Helper
A small utility to use Node.js for common shell tasks: handling STDIN, using file system, etc..
Installation
Prerequisites
- Node.js v16.9 or later.
npm i -g node-shell-helper
Make sure the installed executable ns
is in your PATH
.
Documentation
Usage: ns MODE CODE ...args
Modes:
-c STDIN.slice( CODE, args[0] )
-e CODE
-f STDIN.filter( line => CODE )
-fb STDIN.filter( line => { CODE })
-l lines[] = STDIN; CODE
-m STDIN.map( line => CODE )
-ma STDIN.flatMap( line => CODE )
-mab STDIN.flatMap( line => { CODE })
-mb STDIN.map( line => { CODE })
-p console.log( CODE )
-pb console.log( (() => { CODE })() )
-r STDIN.reduce(( result, line ) => CODE, args[0] )
-rb STDIN.reduce(( result, line ) => { CODE }, args[0] )
-s STDIN.sort(( lineA, lineB ) => CODE )
-sb STDIN.sort(( lineA, lineB ) => { CODE })
Variables available in scope: args, atob, basename, btoa, child_process, clearImmediate, clearInterval, clearTimeout, crypto, dirname, execSync, fetch, filter, flatMap, fs, global, map, os, path, performance, print, process, queueMicrotask, readFileSync, readdirSync, reduce, setImmediate, setInterval, setTimeout, slice, sort, structuredClone, writeFileSync.
NOTE: you need to use `return ...` in -*b modes!
Examples
$ ls | ns -m "line.toUpperCase()"
Async results are supported:
$ ns -p "fetch( 'https://example.org/' ).then( r => r.status )"
200
License
Copyright 2023 Emilis Dambauskas [email protected]
This is free software, and you are welcome to redistribute it under certain conditions; see LICENSE.txt for details.