combiner is both a command-line utility and a library for merging and processing
files. The basic idea behind its is to take advantage of a functional,
flexible middleware that composes map/reduce/filter callbacks.
Install
From NPM:
$ npm install combiner
From Source Code:
$ git clone https://github.com/azer/combiner.git
$ cd combiner;
$ make deps
$ make install
Quick Start
Besides of the API provided by the library, combiner includes a command line
script to accomplish composite file merging aims.
Most basic usage example is running it without any parameters. Which produces a
merge of all files on the executed directory.
$ echo "foo">a;
$ echo "bar">b;
$ echo "qux">c;
$ combiner
foo
bar
qux
Specific filenames and directories can be picked as well.
$ combiner a c
foo
qux
The goal of combiner is to provide a middleware that lets us to process these
files easily;
$ combiner -map "function(el,callback){ callback(null, el.toUpperCase()) }"
FOO
BAR
QUX
The simple command above uppercases all combinerd contents, as you've supposed.
The other options available are reduce and filter. Reduce option basicly
replaces the default function joining the contens of the files;
$ combiner -reduce "function(a,b,callback){ callback(null,a+","+b) }"
FOO,BAR,QUX
It's quite similar with the map function as you've seen above. Unlike the map
and reduce options, filter callbacks take filenames instead of the contents of
the files.
$ combiner -filter "function(filename, cb){ cb(null,/^f|q/); }"
FOO
QUX
The reasion behind this approach lies on the basic design idea of the combiner
library. Its body is made up of a chain of functions, applying listed
operations below;
- find all files in the working directory
- include and flatten nested directories if any exists
- apply filter callbacks to gathered filenames
- apply map callbacks to the gathered filenames*
- apply specified reduce function or the default one joining passed contents
with new lines.
Dependencies
Development
status: under development
todo:
- usage example
- extend documentation (using ronn)
- build a website (combiner.kodfabrik.com)