# broccoli-replace

> Replace text patterns with applause.

Latest version **2.0.2** (published 2021-03-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install broccoli-replace
pnpm add broccoli-replace
yarn add broccoli-replace
bun add broccoli-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 | 2.0.2 |
| Published | 2021-03-04 |
| First published | 2014-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 3 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | outaTiME |
| Maintainers | outatime |
| Keywords | broccoli-plugin, replace, replacement, pattern, patterns, match, text, string, regex, regexp, json, yaml, cson, flatten, applause |

## Links

- npm: https://www.npmjs.com/package/broccoli-replace
- Repository: https://github.com/outaTiME/broccoli-replace
- Homepage: https://github.com/outaTiME/broccoli-replace#readme
- Issues: https://github.com/outaTiME/broccoli-replace/issues
- npm.io page: https://npm.io/package/broccoli-replace

## Dependencies (3)

- [applause](https://npm.io/package/applause.md) ^2.0.0
- [minimatch](https://npm.io/package/minimatch.md) ^3.0.4
- [broccoli-filter](https://npm.io/package/broccoli-filter.md) ^1.3.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.2 (latest) — 2021-03-04
- 2.0.1 — 2021-02-28
- 2.0.0 — 2021-02-26
- 0.12.0 — 2016-04-19
- 0.11.0 — 2015-09-09
- 0.10.1 — 2015-08-20
- 0.3.3 — 2015-08-06
- 0.3.1 — 2015-05-07
- 0.3.0 — 2015-05-01
- 0.2.0 — 2014-10-10
- 0.1.7 — 2014-06-10
- 0.1.6 — 2014-04-20
- 0.1.5 — 2014-03-23
- 0.1.4 — 2014-03-22
- 0.1.3 — 2014-03-21
- … 7 more at https://npm.io/package/broccoli-replace/versions

## README

# broccoli-replace

[![Build Status](https://img.shields.io/travis/outaTiME/broccoli-replace.svg)](https://travis-ci.org/outaTiME/broccoli-replace)
[![Version](https://img.shields.io/npm/v/broccoli-replace.svg)](https://www.npmjs.com/package/broccoli-replace)
![Prerequisite](https://img.shields.io/badge/node-%3E%3D10-blue.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#)
[![Twitter: outa7iME](https://img.shields.io/twitter/follow/outa7iME.svg?style=social)](https://twitter.com/outa7iME)

> Replace text patterns with [applause](https://github.com/outaTiME/applause).

## Install

From NPM:

```shell
npm install broccoli-replace --save-dev
```

## Usage

Assuming installation via NPM, you can use `broccoli-replace` in your Brocfile.js like this:

```javascript
var BroccoliReplace = require('broccoli-replace');

module.exports = new BroccoliReplace('src', {
  files: [
    '**/*.html'
  ],
  patterns: [
    {
      match: 'foo',
      replacement: 'bar'
    }
  ]
});
```

## Options

Supports all the applause [options](https://github.com/outaTiME/applause#options).

## Examples

### Basic

File `src/manifest.appcache`:

```
CACHE MANIFEST
# @@timestamp

CACHE:

favicon.ico
index.html

NETWORK:
*
```

Brocfile.js:

```javascript
var BroccoliReplace = require('broccoli-replace');

module.exports = new BroccoliReplace('src', {
  files: [
    'manifest.appcache'
  ],
  patterns: [
    {
      match: 'timestamp',
      replacement: Date.now()
    }
  ]
});
```

### Multiple matching

File `src/manifest.appcache`:

```
CACHE MANIFEST
# @@timestamp

CACHE:

favicon.ico
index.html

NETWORK:
*
```

File `src/humans.txt`:

```
              __     _
   _    _/__  /./|,//_`
  /_//_// /_|///  //_, outaTiME v.@@version

/* TEAM */
  Web Developer / Graphic Designer: Ariel Oscar Falduto
  Site: https://www.outa.im
  Twitter: @outa7iME
  Contact: afalduto at gmail dot com
  From: Buenos Aires, Argentina

/* SITE */
  Last update: @@timestamp
  Standards: HTML5, CSS3, robotstxt.org, humanstxt.org
  Components: H5BP, Modernizr, jQuery, Bootstrap, LESS, Jade, Grunt
  Software: Sublime Text, Photoshop, LiveReload
```

Brocfile.js:

```javascript
var BroccoliReplace = require('broccoli-replace');
var pkg = require('./package.json');

module.exports = new BroccoliReplace('src', {
  files: [
    'manifest.appcache',
    'humans.txt'
  ],
  patterns: [
    {
      match: 'version',
      replacement: pkg.version
    },
    {
      match: 'timestamp',
      replacement: Date.now()
    }
  ]
});
```

### Cache busting

File `src/index.html`:

```html
<head>
  <link rel="stylesheet" href="/css/style.css?rel=@@timestamp">
  <script src="/js/app.js?rel=@@timestamp"></script>
</head>
```

Brocfile.js:

```javascript
var BroccoliReplace = require('broccoli-replace');

module.exports = new BroccoliReplace('src', {
  files: [
    'index.html'
  ],
  patterns: [
    {
      match: 'timestamp',
      replacement: Date.now()
    }
  ]
});
```

### Include file

File `src/index.html`:

```html
<body>
  @@include
</body>
```

Brocfile.js:

```javascript
var BroccoliReplace = require('broccoli-replace');
var fs = require('fs');

module.exports = new BroccoliReplace('src', {
  files: [
    'index.html'
  ],
  patterns: [
    {
      match: 'include',
      replacement: fs.readFileSync('./includes/content.html', 'utf8')
    }
  ]
});
```

### Regular expression

File `src/username.txt`:

```
John Smith
```

Brocfile.js:

```javascript
var BroccoliReplace = require('broccoli-replace');

module.exports = new BroccoliReplace('src', {
  files: [
    'username.txt'
  ],
  patterns: [
    {
      match: /(\w+)\s(\w+)/,
      replacement: '$2, $1' // Replaces "John Smith" with "Smith, John"
    }
  ]
});
```

### Lookup for `foo` instead of `@@foo`

Brocfile.js:

```javascript
var BroccoliMergeTrees = require('broccoli-merge-trees');
var BroccoliReplace = require('broccoli-replace');

var inputNodes = [
  new BroccoliReplace('src', {
    files: [
      'foo.txt'
    ],
    patterns: [
      {
        match: /foo/g, // Explicitly using a regexp
        replacement: 'bar'
      }
    ]
  }),
  new BroccoliReplace('src', {
    files: [
      'foo.txt'
    ],
    patterns: [
      {
        match: 'foo',
        replacement: 'bar'
      }
    ],
    usePrefix: false // Using the option provided
  }),
  new BroccoliReplace('src', {
    files: [
      'foo.txt'
    ],
    patterns: [
      {
        match: 'foo',
        replacement: 'bar'
      }
    ],
    prefix: '' // Removing the prefix manually
  })
];

module.exports = new BroccoliMergeTrees(nodes);
```

## Related

- [applause](https://github.com/outaTiME/applause) - Human-friendly replacements

## License

MIT © [outaTiME](https://outa.im)

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