Skip to content
Tiny library for building fluent interfaces in JavaScript
JavaScript HTML
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist
lib Add browser build
.gitignore
.jshintrc Fix linting
.travis.yml
README.md Add npm publish
bower.json
gulpfile.js
package.json Release patch
test-browser.html Add browser build

README.md

fluent.js Build Status

A tiny library for building fluent interfaces in JavaScript

Installation

npm install fluent.js --save

Usage

Simple functions

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]

Extending objects (and prototypes)

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']

TODO

  • Argument validation
  • ES6 object destructuring
  • Branching functions
  • ???

Contributing

Make sure gulp build passes, otherwise try to maintain similar code style.

License

MIT

Something went wrong with that request. Please try again.