# chainik

> Simple helper for building async chainable classes without external dependencies

Latest version **1.0.0** (published 2020-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install chainik
pnpm add chainik
yarn add chainik
bun add chainik
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-10-01 |
| First published | 2020-10-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Georgy Farniev |
| Maintainers | nomadick |
| Keywords | promise, chaining, async, await, helper, nodeps |

## Links

- npm: https://www.npmjs.com/package/chainik
- Repository: https://github.com/georgyfarniev/chainik
- Homepage: https://github.com/georgyfarniev/chainik#readme
- Issues: https://github.com/georgyfarniev/chainik/issues
- npm.io page: https://npm.io/package/chainik

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-10-01

## README

# chainik

<a href="https://www.npmjs.com/package/chainik" alt="Downloads">
  <img src="https://img.shields.io/npm/dm/chainik" />
</a>

<a href="https://www.npmjs.com/package/chainik">
  <img src="https://img.shields.io/npm/v/chainik" />
</a>

## Motivation
Simple helper for building async chainable classes without external dependencies

**Chainik** means **teapot** in Russian. I took this name because it associated with chains and
**cantik**, which means **beautiful** in Indonesian and some other languages. Also, other names
containing **chain** word and suitable for this module was occupied in NPM.

## Features
 - Typescript types out of the box
 - No external dependencies
 - Works in browser and node
 - Simple
 
## Installation
```shell
npm i -g chainik
```

## For usage, see example below (more examples and documentation coming soon!):

```ts
import Chainik from 'chainik'

const delay = (t: number) => new Promise(r => setTimeout(r, t))

type Data = string[]
type Params = { foo: string }

class Chainable extends Chainik<Data, Params> {
  step1(d: number) {
    console.log('queued step1')
    return this.queue(async () => {
      await delay(d)
      this.data.push('step1')
      console.log('executed step1')
    })
  }

  step2(d: number) {
    console.log('queued step2')
    return this.queue(async () => {
      await delay(d)
      this.data.push('step2')
      console.log('executed step2')
    })
  }

  step3() {
    console.log('queued step3')
    return this.queue(() => {
      // Using params from constructor as context
      this.data.push(`using ctor param: ${this.params.foo}`)
      console.log('executed step3')
    })
  }
}

async function main() {
  console.log('started')

  const chain = new Chainable([], { foo: 'bar' })
  const data = await chain.step1(1000).step2(2000).step3().exec()

  console.log('data: ', data)
}

if (require.main === module) {
  main()
}
```

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