Bee transforms data using modules referred to as transformations. It can run data through a single transformation or a pipeline of many transformations. The data returned from the last transformations will be written to standard out.
- $
npm i bumble-bee -g
- $
cowsay moo | bee --file map.json run replace-map
- Pipe text to
bee
, loadmap.json
file, and executereplace-map.js
- Pipe text to
replace-map.js
:
module.exports = function({pipe, file}){
for(var key in file){
if(file.hasOwnProperty(key)){
pipe = pipe.replace(key, file[key]);
}
}
return pipe;
};
map.json
:
{
"moo": "foo"
}
Output:
_____
< foo >
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Usage: bee [options] [command]
Options:
-V, --version output the version number
-f, --file [file] Path to input file to be passed to transformation(s)
-p, --pretty Indent JSON output
-h, --help output usage information
Commands:
run <script> [moreScripts...] Execute transformation(s).
add <name> Create new transformation script
A transformation is just a module that exports a function.
Bee will call transformations with an object
as the first argument, the object
will have pipe
and file
properties, pipe
being the text that was piped to bee, file
being the contents of the file specified with the --file
argument, files with a .json
extension will be parsed automatically.
The value returned by the transformation will be serialized if it's not already a string
, with the exception of Promise
s, the resolved value will be used instead, and serialized, if needed. The value will then be passed to the next transformation, or written to standard out if there are no remaining transformations specified to run.
Example Transformation:
module.exports = function({pipe, file}){
// Modify pipe here
return pipe; // Return value or promise
};