# stream-insert

> Transform stream which insert text into the passing stream

Latest version **1.1.0** (published 2016-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-insert
pnpm add stream-insert
yarn add stream-insert
bun add stream-insert
```

## 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.1.0 |
| Published | 2016-09-16 |
| First published | 2016-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Florent Dubois |
| Maintainers | fldubois |
| Keywords | stream, transform, insert |

## Links

- npm: https://www.npmjs.com/package/stream-insert
- Repository: https://github.com/fldubois/stream-insert
- Homepage: https://github.com/fldubois/stream-insert#readme
- Issues: https://github.com/fldubois/stream-insert/issues
- npm.io page: https://npm.io/package/stream-insert

## Dependencies (2)

- [yatc](https://npm.io/package/yatc.md) ^0.1.0
- [merge](https://npm.io/package/merge.md) ^1.2.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2016-09-16
- 1.0.0 — 2016-09-09

## README

# stream-insert

[![npm](https://img.shields.io/npm/v/stream-insert.svg?maxAge=3600)](https://www.npmjs.com/package/stream-insert)
[![Build Status](https://travis-ci.org/fldubois/stream-insert.svg?branch=master)](https://travis-ci.org/fldubois/stream-insert)
[![Coverage Status](https://coveralls.io/repos/github/fldubois/stream-insert/badge.svg?branch=master)](https://coveralls.io/github/fldubois/stream-insert?branch=master)
[![dependencies Status](https://david-dm.org/fldubois/stream-insert/status.svg)](https://david-dm.org/fldubois/stream-insert)
[![devDependencies Status](https://david-dm.org/fldubois/stream-insert/dev-status.svg)](https://david-dm.org/fldubois/stream-insert?type=dev)

> Transform stream which insert text into the passing stream

## Usage

`stream-insert` implements the [Tranform Stream API](https://nodejs.org/api/stream.html#stream_implementing_a_transform_stream).

```js
var fs = require('fs');

var StreamInsert = require('stream-insert');

var insert = new StreamInsert('Line to append', /^Searched line$/);

fs.createReadStream('input.txt').pipe(insert).pipe(fs.createWriteStream('output.txt'));
```

## API

```js
StreamInsert(insertions, query, options)
```

##### Parameters

| Parameter    | Type(s)                                              | Required | Default | Description                                                                                        |
| ------------ | ---------------------------------------------------- | -------- | ------- | -------------------------------------------------------------------------------------------------- |
| `insertions` | `string`, `string[]`                                 | *Yes*    |         | Strings to insert into the stream.                                                                 |
| `query`      | `object`, `string`, `string[]`, `RegExp`, `RegExp[]` | *Yes*    |         | Query object (see below) or RegExp(s)/string(s) used to detect where the strings will be inserted. |
| `options`    | `object`, `string`                                   | No       | `{}`    | Additional options. If a string is passed, set the separator option.                               |

##### Query

| Filter             | Type(s)                                    | Required | Default | Description                                                                                               |
| ------------------ | ------------------------------------------ | -------- | ------- | --------------------------------------------------------------------------------------------------------- |
| `searches`         | `string`, `string[]`, `RegExp`, `RegExp[]` | *Yes*    |         | RegExp(s)/string(s) used to detect where the strings will be inserted.                                    |
| `operator`         | `string`                                   | No       | `AND`   | If `AND`, insert after all searches are found (sequentially). If `OR`, insert after each matching search. |
| `before`           | `RegExp`, `string`                         | No       | `null`  | Don't insert after this RegExp matched.                                                                   |
| `after`            | `RegExp`, `string`                         | No       | `null`  | Don't insert until this RegExp matched.                                                                   |
| `strict`           | `boolean`                                  | No       | `true`  | In strict mode, boudaries (before & after) are not tested against searches.                               |

##### Options

| Option             | Type(s)            | Required | Default | Description                                                                                               |
| ------------------ | ------------------ | -------- | ------- | --------------------------------------------------------------------------------------------------------- |
| `prepend`          | `boolean`          | No       | `false` | Insert strings before the last match, after otherwise.                                                    |
| `separator`        | `string`           | No       | `\n`    | Separator used to split the stream. Default to `\n` to read the input stream line by line.                |
| `limit`            | `number`           | No       | `-1`    | Maximum number of insertions (-1 for infinity).                                                           |
| `insertSeparator`  | `boolean`          | No       | `true`  | If `true`, insert the separator between the insert and the matched string.                                |

## Examples

* [Insert lines into a file](examples/lines)
* [Insert words into a sentence](examples/words)
* [Insert lines between two boundaries](examples/section)
* [Insert a line at the end of a file](examples/end)
* [Insert a limited number of times](examples/limit)

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