Library to create chainable functions.
npm install chaino --save-dev # npm
yarn add chaino --save-dev # yarn
Define your library as chainable list of functions by providing the keys.
NOTE: Passing non-function keys is fine, but trying to call them will just return the property name.
// chainable-lib.js
const chaino = require("chaino");
const keys = {
red: (str, chain) => `${chain.join(",")} red(${str})`,
blue: (str, chain) => `${chain.join(",")} blue(${str})`,
yellow: (str, chain) => `${chain.join(",")} yellow(${str})`,
}
module.exports = chaino(keys);
Then your library can be used as:
// index.js
const library = require("chainable-lib");
library.red("abc"); // red(abc)
library.red.blue("abc") // red blue(abc)
library.blue.yellow.red("abc") // blue,yellow red(abc)
More examples available here. Initial motivation here.
MIT