0.1.2 • Published 5 months ago

node-shell-helper v0.1.2

Weekly downloads
-
License
AGPL-3.0
Repository
-
Last release
5 months ago

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.

0.1.2

5 months ago

0.1.1

6 months ago

0.1.0

6 months ago