Git Product home page Git Product logo

each-line's Introduction

essed

essed is a simple program with purpose similar to sed or awk

Pros and cons

When to use essed

  • Dealing with line-delimited JSON
  • One-time time-consuming task
  • Playing around
  • Want to leverage knowledge of JavaScript

When not to use essed

  • Performance - sed is strongly optimized C code. JavaScript is much slower. It's totally possible for essed to be 200 times slower than C-based tools.
  • Non-UTF8 encodings (at least yet)
  • Dealing with binary files

Consider

  • Portability - you can use essed in your npm scripts. Though, it won't be installed globally on your CI.

TODO

map

Examples

Remove whitespace from each line:

cat ~/.bashrc | essed --map "line.trim()"

Reverse lines:

cat ~/.bashrc | essed --map "$0.reverse()"

Remove comments (nulls and undefineds are filtered out from output):

cat ~/.zshrc | essed --map "value.trim().startsWith('#') ? null : line"

Color even lines (terminal):

cat ~/.zshrc | essed -m "i % 2 ? line.yellow : line"

filter

Examples

Remove comments:

essed --filter "line.trim().startsWith('#')" ~/.zshrc

Comming

Allowed return values

  • string
  • Promise<string>
  • highland<string>
  • ReadableStream<string>

Enviroment

For your convenience we expose following "globals":

  • shared - empty object shared by many invocations
  • P, Bluebird - Bluebird instance
  • lodash, _ - lodash instance
  • hl, highland - highland instance
  • deburr, pad, trim, truncate, upperFirst, replace - exported from lodash
  • execFile, execFileSync - exported from native child_process
  • colors - colors instance
  • log - function that logs it's input on stderr and returns first argument.
  • fs - native Node.js module ** log(line) === line

colors module is avalaible by default.

Line is available as line, l, value, $0.

Number of line is avalaiable as i and index.

Resources to read:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.