0.0.2 • Published 6 years ago

chaino v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

Chaino 🔗

Library to create chainable functions.

npm.io

Installation

npm install chaino --save-dev # npm
yarn add chaino --save-dev # yarn

Usage

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.

License

MIT

0.0.2

6 years ago

0.0.1

6 years ago