# call-chainer

> Combine a regular function and a class so that methods of the class become chainable properties of the function that get called automatically.

Latest version **3.0.1** (published 2025-01-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install call-chainer
pnpm add call-chainer
yarn add call-chainer
bun add call-chainer
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2025-01-25 |
| First published | 2021-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | fabiospampinato |
| Keywords | call, chain, methods, automatic, properties, options |

## Links

- npm: https://www.npmjs.com/package/call-chainer
- Repository: https://github.com/fabiospampinato/call-chainer
- Homepage: https://github.com/fabiospampinato/call-chainer#readme
- Issues: https://github.com/fabiospampinato/call-chainer/issues
- npm.io page: https://npm.io/package/call-chainer

## Recent versions

- 3.0.1 (latest) — 2025-01-25
- 3.0.0 — 2022-04-05
- 2.0.1 — 2021-07-23
- 2.0.0 — 2021-07-22
- 1.0.0 — 2021-07-22

## README

# Call Chainer

Combine a regular function and a class so that methods of the class become chainable properties of the function that get called automatically.

## Install

```sh
npm install call-chainer
```

## Usage

```ts
import chainer from 'call-chainer';

// First of all you need a class containing some methods
// It can contain non-methods too, those are not attached to the function

class Methods {
  flags = {
    always: false,
    skip: false,
    todo: false
  }
  always = () => {
    this.flags.always = true;
  }
  skip = () => {
    this.flags.skip = true;
  }
  todo = () => {
    this.flags.todo = true;
  }
}

// Then you need a function
// The function must receive as its first argument an instance of Methods
// That first argument is not exposed in the final chained function

const fn = ( methods: Methods, title: string ) => {
  console.log ( title );
  console.log ( methods.flags );
};

// Finally you need to chain the two together to get a new, chained, function

const fnChained = chainer ( Methods, fn );

// Then you can call methods on the chained function just by retrieving them as properties

fnChained.always.skip ( 'My title' );
// => 'My Title'
// => { always: true, skip: true, todo: false }

fnChained ( 'My title' );
// => 'My Title'
// => { always: false, skip: false, todo: false }
```

## License

MIT © Fabio Spampinato

---
_Source: https://npm.io/package/call-chainer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
