# stream-replace

> replace text in a stream

Latest version **1.0.0** (published 2014-12-23) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2014-12-23 |
| First published | 2014-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Aleksey Smolenchuk |
| Maintainers | lxe |
| Keywords | stream, replace |

## Links

- npm: https://www.npmjs.com/package/stream-replace
- Repository: https://github.com/lxe/stream-replace
- Homepage: https://github.com/lxe/stream-replace.js
- Issues: https://github.com/lxe/stream-replace.js/issues
- npm.io page: https://npm.io/package/stream-replace

## 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.0.0 (latest) — 2014-12-23

## README

# stream-replace

[![Build Status](https://travis-ci.org/lxe/stream-replace.svg)](https://travis-ci.org/lxe/stream-replace)

Returns a transform stream that outputs data with 'needle' replaced with 'replacer'.

#### Features

 - Same API as [`String.replace()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
 - Honors needles appearing on chunk boundaries.

#### `streamReplace(regexp|substr, newSubStr|function)`

 - Returns a `Stream.Transform` instance, whose output has some or all matches of a pattern in the stream's input replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match. See [`String.prototype.replace()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace).

#### Examples

```javascript
// Repalce all occurrences of 'foo' in 'data.txt' with 'bar',
// and output to stdout

var fs = require('fs');
var replace = require('stream-replace');

fs.createReadStream('data.txt')
  .pipe(replace(/foo/g, 'bar'))
  .pipe(process.stdout);
```

```javascript
// Create a server listening on port 3000 that
// proxies www.example.com, and replaces
// 'example' with 'zombocom', and 'domain' with 'web page'

var replace = require('stream-replace');
var http = require('http');

http.createServer(function handler(req, res) {
  http.request('http://www.example.com/', function onResponse(response) {
    response
      .pipe(replace(/example/ig, 'zombocom'))
      .pipe(replace(/domain/ig,  'web page'))
      .pipe(res);
  }).end();
}).listen(3000);
```

#### License

MIT

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