1.4.0 • Published 8 years ago
essed v1.4.0
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 -
sedis strongly optimized C code. JavaScript is much slower. It's totally possible foressedto be 200 times slower than C-based tools. - Non-UTF8 encodings (at least yet)
- Dealing with binary files
Consider
- Portability - you can use
essedin yournpmscripts. Though, it won't be installed globally on your CI.
TODO
- Loading code from file
assert- assert input match some criteria. If it doesn't, break pipeline, otherwise return untouchedfind- find first line matching some criterialimitparameter onfilter- if number of matched items exceed limit, drop them downlimitparameter onmaptakeWhiletakeUntilfindLastreduce- Native support for line-delimited JSON
- Provide Webpack compiled build to improve startup time
- Provide way to load external modules
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('#')" ~/.zshrcComming
Allowed return values
stringPromise<string>highland<string>ReadableStream<string>
Enviroment
For your convenience we expose following "globals":
shared- empty object shared by many invocationsP,Bluebird- Bluebird instancelodash,_- lodash instancehl,highland- highland instancedeburr,pad,trim,truncate,upperFirst,replace- exported fromlodashexecFile,execFileSync- exported from nativechild_processcolors-colorsinstancelog- function that logs it's input onstderrand 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.