# patch-text

> Make multiple changes to a block of text by providing start and end indices and replacement text

Latest version **1.0.2** (published 2015-06-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install patch-text
pnpm add patch-text
yarn add patch-text
bun add patch-text
```

## 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.2 |
| Published | 2015-06-05 |
| First published | 2015-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | replace, code, index |

## Links

- npm: https://www.npmjs.com/package/patch-text
- Repository: https://github.com/bendrucker/patch-text
- Homepage: https://github.com/bendrucker/patch-text#readme
- Issues: https://github.com/bendrucker/patch-text/issues
- npm.io page: https://npm.io/package/patch-text

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2015-06-05
- 1.0.1 — 2015-06-05

## README

# patch-text [![Build Status](https://travis-ci.org/bendrucker/patch-text.svg?branch=master)](https://travis-ci.org/bendrucker/patch-text)

> Make multiple changes to a block of text by providing start and end indices and replacement text


## Install

```
$ npm install --save patch-text
```


## Usage

```js
var patch = require('patch-text');
var text = 'Hello guys!'
var updated = patch(text, [
  {
    start: 0,
    end: 5,
    replacement: 'Hi'
  },
  {
    start: 7,
    end: 9,
    replacement: 'al'
  }
])
// => 'Hi gals!'
```

Your patches shouldn't overlap, but they can shrink or increase the character count and your patches will still apply to the right text. 

## API

#### `patch(text, patches)` -> `string`

##### text

*Required*  
Type: `string`

The text to patch.

##### patches

*Required*  
Type: `array[object]`

The patches to apply to the text, each with:

* start (number)
* end (number)
* replacement (string)


## License

MIT © [Ben Drucker](http://bendrucker.me)

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