A tiny library for building fluent interfaces in JavaScript
npm install fluent.js --save
var fluent = require('fluent.js');
var insert = fluent({
insert: '*',
into: '[]',
after: '*'
}, function handler(value, array, otherValue) {
array.splice(array.indexOf(otherValue) + 1, 0, value);
return array;
});
console.log(insert(2).into([1, 3]).after(1)); //[1, 2, 3]
var fluent = require('fluent.js');
fluent({
with: '*',
after: '*'
}, function handler(value, otherValue) {
var copy = this.slice(0);
copy.splice(copy.indexOf(otherValue) + 1, 0, value);
return copy;
}, Array.prototype);
console.log(['this', 'awesome'].with('is').after('this')); //['this', 'is', 'awesome']
- Argument validation
- ES6 object destructuring
- Branching functions
- ???
Make sure gulp build
passes, otherwise try to maintain similar code style.
MIT