# ruit

> Tasks serialization minilibrary

Latest version **1.0.4** (published 2018-06-03) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-06-03 |
| First published | 2017-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Gianluca Guarini |
| Maintainers | gianlucaguarini |
| Keywords | series, promises, flow, functional, composition, tasks |

## Links

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

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@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

## Recent versions

- 1.0.4 (latest) — 2018-06-03
- 1.0.3 — 2017-11-21
- 1.0.2 — 2017-11-21
- 1.0.1 — 2017-09-26
- 1.0.0 — 2017-09-15
- 0.0.1 — 2017-09-14
- 0.0.0 — 2017-09-14

## README

<img src="ruit-logo.svg" width="46%"/>

Functional tasks serialization mini script (0.3kb)

[![Build Status][travis-image]][travis-url]

[![NPM version][npm-version-image]][npm-url]
[![NPM downloads][npm-downloads-image]][npm-url]
[![MIT License][license-image]][license-url]

## Installation

```js
import ruit from 'ruit'
```

[travis-image]: https://img.shields.io/travis/GianlucaGuarini/ruit.svg?style=flat-square

[travis-url]: https://travis-ci.org/GianlucaGuarini/ruit

[license-image]: http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square

[license-url]: LICENSE.txt

[npm-version-image]: http://img.shields.io/npm/v/ruit.svg?style=flat-square

[npm-downloads-image]: http://img.shields.io/npm/dm/ruit.svg?style=flat-square

[npm-url]: https://npmjs.org/package/ruit

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### ruit

Serialize a list of sync and async tasks from left to right

**Parameters**

-   `tasks` **any** list of tasks to process sequentially

**Examples**

```javascript
const curry = f => a => b => f(a, b)
const add = (a, b) => a + b

const addOne = curry(add)(1)

const squareAsync = (num) => {
  return new Promise(r => {
    setTimeout(r, 500, num * 2)
  })
}

// a -> a + a -> a * 2
// basically from left to right: 1 => 1 + 1 => 2 * 2
ruit(1, addOne, squareAsync).then(result => console.log(result)) // 4
```

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** a promise containing the result of the whole chain

#### cancel

Helper that can be returned by ruit function to cancel the tasks chain

**Examples**

```javascript
ruit(
  100,
  num => Math.random() * num
  num => num > 50 ? ruit.cancel() : num
  num => num - 2
).then(result => {
  console.log(result) // here we will get only number lower than 50
})
```

Returns **[Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)** internal private constant

#### compose

The same as ruit() but with the arguments inverted from right to left

**Parameters**

-   `tasks` **any** list of tasks to process sequentially

**Examples**

```javascript
const curry = f => a => b => f(a, b)
const add = (a, b) => a + b

const addOne = curry(add)(1)

const squareAsync = (num) => {
  return new Promise(r => {
    setTimeout(r, 500, num * 2)
  })
}

// a -> a + a -> a * 2
// basically from right to left: 1 => 1 + 1 => 2 * 2
ruit.compose(squareAsync, addOne, 1).then(result => console.log(result)) // 4
```

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** a promise containing the result of the whole chain

# Ruit meaning

`ruit` comes from the `ruere` latin verb that means `It falls`, It expresses properly the essence of this script and sounds also similar to `run it`

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