1
0
Fork
You've already forked node-shell-helper
0
Helper functions for shell scripting
  • JavaScript 100%
2023年12月16日 13:50:36 +02:00
modules Fixed Node.js v16 support. 2023年12月16日 13:50:15 +02:00
cli.mjs Fixed Node.js v16 support. 2023年12月16日 13:50:15 +02:00
LICENSE.txt Initial commit. 2023年10月04日 11:35:38 +03:00
package.json 0.1.2 2023年12月16日 13:50:36 +02:00
README.md Updated README. 2023年11月01日 09:02:04 +02:00

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 dev@emilis.net

This is free software, and you are welcome to redistribute it under certain conditions; see LICENSE.txt for details.