Skip to content

Repository files navigation

lbl NPM versionBuild StatusDependency Status

Process stdin, line by line, sort of like AWK but 100% JS

Prerequisites

  • There are a couple of handy globals available
    • $ is an alias for global
    • log is an alias for console.log
    • chalk is available for adding color to ouput

Installation

$ npm install lbl --global

Usage

Usage
$ lbl <Options><STDIN>
Options
# Pass processing functions on CLI
-a, --after functionto run after processing lines [optional]
-b, --before functionto run before processing lines [optional]
-e, --each functionto run on each line [required]
# Or, use a node module file with processing functions:# before(), after(), each()
-r, --require module file with functions
-h, --help show this usage info
--version show the current version installed
Examples
$ cat ./data/x.file | lbl -r ./scripts/X.js
<<BEGIN>> > XX > Matched 1 from 3 $ printf 'x\\nXX\\nxXx' | lbl -e 'x => { n++; if (x.match(/^X/)) { log(chalk.yellow('> ') + x); f++; } }' -b '() => { $.n = 0; $.f = 0; log('<<BEGIN>>'); }' -a '() => { log('> Matched ' + f + ' from ' + n); }' <<BEGIN>> > XX > Matched 1 from 3

Sample Module File

'use strict';/* global $, log, chalk, n:true, f:true */module.exports={each: x=>{n++;if(x.match(/^X/)){log(chalk.yellow('> ')+x);f++;}},before: ()=>{$.n=0;$.f=0;log('<<BEGIN>>');},after: ()=>{log('> Matched '+f+' from '+n);}};

License

ISC © Buster Collings

About

💲 Process stdin, line by line, sort of like AWK but 100% JS

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages