0.1.0 • Published 8 years ago
pipe-ops v0.1.0
pipe-ops
Pipe like transformations in JavaScript.
Pipes
- must implement:
value
,inject
andoptional
functions.
Examples
String transformation:
new StringPipe('Hi %name%! Asdf %other_name% and this is').
optional().
format('%name%', 'Jacob').
format('%other_name%', 'Buren').
truncate(26).
concat('Read more..').
surround('<h1>', '</h1>').
inject(function(value) { return '(:) ' + value }).
surround('<header>', '</header>').
value()
// "header>(:) <h1>Hi Jacob! Asdf Buren and..Read more..</h1></header>"
You can also move between different types:
var echo = function(data) { return data + '... ' + data; };
new StringPipe('Jacob,Buren').
split(',', ArrayPipe).map(function(el) { return '# ' + el + ' '; }).
join('', StringPipe).
inject(echo).
value()
// "# Jacob # Buren ... # Jacob # Buren"
0.1.0
8 years ago