woltsu / chainify-object

Make any object's functions chainable!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chainify-object

Note

This tool is primarily a POC and has not been battle-tested in production

Make any object's functions chainable, without losing the types! Works for class instances as well.

Installation

npm i @woltsu/chainify-object

Usage

Considering the following builder-like object:

const obj = {
  doWorkA: async () => {...},
  doWorkB: () => {...},
  doWorkC: () => async () => {...}
}

Normally, we would use its functions like so:

await obj.doWorkA();
obj.doWorkB();
await obj.doWorkC();

With chainify-object, we can instead make the object's functions chainable:

import { chainify } from "@woltsu/chainify-object";

await chainify(obj).doWorkA().doWorkB().doWorkC();

About

Make any object's functions chainable!

License:MIT License


Languages

Language:TypeScript 100.0%