Skip to content

Easily create a library of chain-able functions.

License

Notifications You must be signed in to change notification settings

adityavm/chaino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chaino 🔗

Library to create chainable functions.

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

About

Easily create a library of chain-able functions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published