chain-simple
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

chain-simple

npm downloads

The purpose of this library is - build simple and flexible chainable call of the object` methods

import { makePropertiesChainable } from 'chain-simple';
import type { TChainable } from 'chain-simple';

const obj = {
  async method1() {
    return Promise.resolve(1).then(value => {
      console.log('method1', value);
      return value;
    });
  },
  async method2() {
    return Promise.resolve(2).then(value => {
      console.log('method2', value);
      return value;
    });
  },
  async method3() {
    return Promise.resolve(3).then(value => {
      console.log('method3', value);
      return value;
    });
  },
};

const chainableObj: TChainable<typeof obj> = makePropertiesChainable(obj);

chainableObj
  .method1()
  .method3()
  .then(val => console.log(val)); // method1 1 \n method3 3 \n 3
const { makePropertiesChainable } = require('chain-simple');

const obj = {
  async method1() {
    return Promise.resolve(1).then(value => {
      console.log('method1', value);
      return value;
    });
  },
  async method2() {
    return Promise.resolve(2).then(value => {
      console.log('method2', value);
      return value;
    });
  },
  async method3() {
    return Promise.resolve(3).then(value => {
      console.log('method3', value);
      return value;
    });
  },
};

const chainableObj: TChainable<typeof obj> = makePropertiesChainable(obj);

chainableObj
  .method1()
  .method3()
  .then(val => console.log(val)); // method1 1 \n method3 3 \n 3

Package Sidebar

Install

npm i chain-simple

Weekly Downloads

1,312

Version

1.3.2

License

ISC

Unpacked Size

22.5 kB

Total Files

13

Last publish

Collaborators

  • potapovdim