# p-transform

> Promised out of order transform.

Latest version **5.0.1** (published 2024-10-12) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install p-transform
pnpm add p-transform
yarn add p-transform
bun add p-transform
```

## 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 | 5.0.1 |
| Published | 2024-10-12 |
| First published | 2021-11-05 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18.19.0 |
| Dependencies | 2 |
| Unpacked size | 22.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | mshima |

## Links

- npm: https://www.npmjs.com/package/p-transform
- Repository: https://github.com/mshima/p-transform
- Homepage: https://github.com/mshima/p-transform#readme
- Issues: https://github.com/mshima/p-transform/issues
- npm.io page: https://npm.io/package/p-transform

## Dependencies (2)

- [p-queue](https://npm.io/package/p-queue.md) ^8.0.1
- [@types/node](https://npm.io/package/@types/node.md) >=18.19.0

## Recent versions

- 5.0.1 (latest) — 2024-10-12
- 5.0.0 — 2024-10-12
- 4.1.6 — 2024-10-12
- 4.1.5 — 2023-10-27
- 4.1.4 — 2023-10-27
- 4.1.3 — 2023-10-11
- 4.1.2 — 2023-10-10
- 4.1.1 — 2023-10-10
- 4.1.0 — 2023-10-10
- 4.0.5 — 2023-06-01
- 4.0.4 — 2023-06-01
- 4.0.3 — 2023-05-30
- 4.0.2 — 2023-05-30
- 4.0.1 — 2023-05-30
- 4.0.0 — 2023-05-30
- … 10 more at https://npm.io/package/p-transform/versions

## README

# p-transform

Promised out of order transform.

## Usage

Builds a out-of-order [Duplex](https://nodejs.org/api/stream.html#class-streamduplex) using a [p-queue](https://github.com/sindresorhus/p-queue) parallel queue.
`transform` implementation must be sync or return a promise. Callback is not supported.

Promisified `pipeline` and `transform` shortcut are provided for convenience.

```
import { OutOfOrder, transform, pipeline, passthrough, filter } from 'p-transform';

await pipeline(
  new OutOfOrder(
    { transform: async file => file },
    { concurrency: 7 },
  ).duplex(() => console.log('done')),
  passthrough(async file => {}, () => console.log('done')),
  filter(async file => true, () => console.log('done')),
  transform(async file => file, () => console.log('done')),
)
```

## Debug

Use `DEBUG=p-transform:*` environment variable.

## License

Apache-2.0

# API

## Classes

<dl>
<dt><a href="#OutOfOrder">OutOfOrder</a></dt>
<dd></dd>
</dl>

## Constants

<dl>
<dt><a href="#pipeline">pipeline</a></dt>
<dd><p>Promisified pipeline</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#transform">transform(transform, end)</a></dt>
<dd><p>Shortcut to create a OutOfOrder with transform and end callback</p>
</dd>
<dt><a href="#passthrough">passthrough(spy, end)</a></dt>
<dd><p>Shortcut to create a passthrough OutOfOrder with spy and end callback</p>
</dd>
<dt><a href="#filter">filter(filter, end)</a></dt>
<dd><p>Shortcut to create a filter OutOfOrder with filter and end callback</p>
</dd>
</dl>

<a name="OutOfOrder"></a>

## OutOfOrder

**Kind**: global class

- [OutOfOrder](#OutOfOrder)
  - [new OutOfOrder(transform[, options])](#new_OutOfOrder_new)
  - [.duplex(endCallback)](#OutOfOrder+duplex) ⇒ [<code>Duplex</code>](https://nodejs.org/api/stream.html#class-streamduplex)

<a name="new_OutOfOrder_new"></a>

### new OutOfOrder(transform[, queueOptions])

OutOfOrder

| Param          | Type                  | Description                           |
| -------------- | --------------------- | ------------------------------------- |
| [transform]    | <code>function</code> | Transform.                            |
| [queueOptions] | <code>Object</code>   | Options forwarded to PQueue instance. |

<a name="OutOfOrder+duplex"></a>

### outOfOrder.duplex(end) ⇒ [<code>Duplex</code>](https://nodejs.org/api/stream.html#class-streamduplex)

Build Duplex.

**Kind**: instance method of [<code>OutOfOrder</code>](#OutOfOrder)
**Returns**: [<code>Duplex</code>](https://nodejs.org/api/stream.html#class-streamduplex)

| Param | Type                  |
| ----- | --------------------- |
| end   | <code>function</code> |

<a name="OutOfOrder+flushQueue"></a>

## pipeline

Promisified pipeline

**Kind**: global constant
<a name="transform"></a>

## transform(transform, end)

Shortcut to create a OutOfOrder with transform and end callback.

**Kind**: global function

| Param     | Type                  |
| --------- | --------------------- |
| transform | <code>function</code> |
| end       | <code>function</code> |

<a name="passthrough"></a>

## passthrough(spy, end)

Shortcut to create a passthrough OutOfOrder with spy and end callback.

**Kind**: global function

| Param | Type                  |
| ----- | --------------------- |
| spy   | <code>function</code> |
| end   | <code>function</code> |

<a name="filter"></a>

## filter(filter, end)

Shortcut to create a filter OutOfOrder with filter and end callback.

**Kind**: global function

| Param  | Type                  |
| ------ | --------------------- |
| filter | <code>function</code> |
| end    | <code>function</code> |

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