# replacements

> Transform a string with an array of replacement patterns.

Latest version **0.2.1** (published 2015-12-20) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2015-12-20 |
| First published | 2014-07-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 | 5 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | escape, expression, match, modify, pattern, regex, regular expression, replace, replacement, search, structure, substitute |

## Links

- npm: https://www.npmjs.com/package/replacements
- Repository: https://github.com/jonschlinkert/replacements
- Issues: https://github.com/jonschlinkert/replacements/issues
- npm.io page: https://npm.io/package/replacements

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2015-12-20
- 0.2.0 — 2015-03-13
- 0.1.3 — 2014-07-08
- 0.1.2 — 2014-07-08
- 0.1.1 — 2014-07-05
- 0.1.0 — 2014-07-05

## README

# replacements [![NPM version](https://img.shields.io/npm/v/replacements.svg)](https://www.npmjs.com/package/replacements) [![Build Status](https://img.shields.io/travis/jonschlinkert/replacements.svg)](https://travis-ci.org/jonschlinkert/replacements)

> Transform a string with an array of replacement patterns.

- [Install](#install)
- [Usage](#usage)
  * [object of replacement patterns](#object-of-replacement-patterns)
  * [key-value replacement patterns](#key-value-replacement-patterns)
  * [array of replacement patterns](#array-of-replacement-patterns)
  * [functions as replacements](#functions-as-replacements)
- [Related projects](#related-projects)
- [Running tests](#running-tests)
- [Contributing](#contributing)
- [Author](#author)
- [License](#license)

_(TOC generated by [verb](https://github.com/verbose/verb))_

## Install

Install with [npm](https://www.npmjs.com/)

```sh
$ npm i replacements --save
```

## Usage

```js
var replace = require('replacements');
```

### object of replacement patterns

```js
var transformers = {
  pattern: /a/g,
  replacement: 'bbb'
};
console.log(replace('aaa', transformers));
//=> 'bbbbbbbbb'
```

### key-value replacement patterns

For basic string transformations, you can pass the string to replace as the key, and the replacement as a value:

```js
var transformers = {
  'a': 'b'
  'c': 'd'
};
console.log(replace('aaabbbccc', transformers));
//=> 'bbbbbbddd'
```

_Note that only the first matching string will only be replaced using this format. If you need more flexibility, use the pattern-replacement regex syntax._.

### array of replacement patterns

```js
var transformers = [
  {pattern: /a/g, replacement: 'bbb'},
  {pattern: /b/g, replacement: 'ccc'},
  {pattern: /c/g, replacement: 'ddd'},
  {pattern: /d/g, replacement: 'eee'},
  {pattern: /[e]+/g, replacement: '_DONE_'}
];
console.log(replace('aaa', transformers));
//=> '__DONE__'
```

### functions as replacements

```js
var transformers = {
  pattern: /a+/g,
  replacement: function(match) {
    return match.split('').map(function(str, i) {
      if (i === 0) {return 'b'; }
      if (i === 1) {return str.toUpperCase();}
      return str;
    }).join('');
  }
};
console.log(replace('aaa', transformers));
//=> 'bAa'
```

## Related projects

[easy-renamer](https://www.npmjs.com/package/easy-renamer): Easily rename files using custom rename functions that are automatically used against any filepaths that… [more](https://www.npmjs.com/package/easy-renamer) | [homepage](https://github.com/jonschlinkert/easy-renamer)

## Running tests

Install dev dependencies:

```sh
$ npm i -d && npm test
```

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/replacements/issues/new).

## Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License

Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
Released under the MIT license.

***

_This file was generated by [verb](https://github.com/verbose/verb) on December 20, 2015._

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