<commit_before># gulp-string-replace [![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![dependencies][gulp-string-replace-dependencies-image]][gulp-string-replace-dependencies-url]
> Replaces strings on files by using string or regex patterns. Works with Gulp 3!

## Usage

```shell
npm install gulp-string-replace --save-dev
```
### Regex Replace
```javascript
var replace = require('gulp-string-replace');

gulp.task('replace_1', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace(new RegExp('@env@', 'g'), 'production'))
    .pipe(gulp.dest('./build/config.js'))
});

gulp.task('replace_2', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace(/@env@/g, '$1production'))
    .pipe(gulp.dest('./build/config.js'))
});

gulp.task('replace_3', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace(/foo/g, function () {
        return 'bar';
    }))
    .pipe(gulp.dest('./build/config.js'))
});
```
### String Replace
```javascript
gulp.task('replace_1', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace('@env@', 'production'))
    .pipe(gulp.dest('./build/config.js'))
});
```
### Function Replace
```javascript
gulp.task('replace_1', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace('environment', function () {
        return 'production';
    }))
    .pipe(gulp.dest('./build/config.js'))
});

gulp.task('replace_2', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace('environment', function (replacement) {
        return replacement + '_mocked';
    }))
    .pipe(gulp.dest('./build/config.js'))
});

```

### API

#### replace(string, replacement)

##### string
Type: `String`

The string to search for.

##### replacement
Type: `String` or `Function`

The replacement string or function. Called once for each match.

#### replace(regex, replacement)

##### regex
Type: `RegExp`

More details here: [MDN documentation for RegExp].

##### replacement
Type: `String` or `Function`

More details here: [MDN documentation for String.replace].


#### Release History
 * 2016-03-09   v0.0.1   Initial version of plugin.
---

Task submitted by [<NAME>](http://czechowski.pl/)

[travis-url]: http://travis-ci.org/tomaszczechowski/gulp-string-replace
[travis-image]: https://secure.travis-ci.org/tomaszczechowski/gulp-string-replace.svg?branch=master
[npm-url]: https://npmjs.org/package/gulp-string-replace
[npm-image]: https://badge.fury.io/js/gulp-string-replace.svg
[gulp-string-replace-dependencies-image]: https://david-dm.org/tomaszczechowski/gulp-string-replace/status.png
[gulp-string-replace-dependencies-url]: https://david-dm.org/tomaszczechowski/gulp-string-replace#info=dependencies<commit_msg>Updated README file<commit_after># gulp-string-replace [![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![dependencies][gulp-string-replace-dependencies-image]][gulp-string-replace-dependencies-url]
> Replaces strings on files by using string or regex patterns. Works with Gulp 3!

## Usage

```shell
npm install gulp-string-replace --save-dev
```
### Regex Replace
```javascript
var replace = require('gulp-string-replace');

gulp.task('replace_1', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace(new RegExp('@env@', 'g'), 'production'))
    .pipe(gulp.dest('./build/config.js'))
});

gulp.task('replace_2', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace(/@env@/g, '$1production'))
    .pipe(gulp.dest('./build/config.js'))
});

gulp.task('replace_3', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace(/foo/g, function () {
        return 'bar';
    }))
    .pipe(gulp.dest('./build/config.js'))
});
```
### String Replace
```javascript
gulp.task('replace_1', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace('@env@', 'production'))
    .pipe(gulp.dest('./build/config.js'))
});
```
### Function Replace
```javascript
gulp.task('replace_1', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace('environment', function () {
        return 'production';
    }))
    .pipe(gulp.dest('./build/config.js'))
});

gulp.task('replace_2', function() {
  gulp.src(["./config.js"]) // Every file allown.
    .pipe(replace('environment', function (replacement) {
        return replacement + '_mocked';
    }))
    .pipe(gulp.dest('./build/config.js'))
});

```

### API

#### replace(string, replacement)

##### string
Type: `String`

The string to search for.

##### replacement
Type: `String` or `Function`

The replacement string or function. Called once for each match.

#### replace(regex, replacement)

##### regex
Type: `RegExp`

More details here: [MDN documentation for RegExp].

##### replacement
Type: `String` or `Function`

More details here: [MDN documentation for String.replace].



#### Release History
 * 2016-03-09  v0.0.1  Initial version of plugin.


Task submitted by [<NAME>](http://czechowski.pl/)

[MDN documentation for RegExp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
[MDN documentation for String.replace]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter
[travis-url]: http://travis-ci.org/tomaszczechowski/gulp-string-replace
[travis-image]: https://secure.travis-ci.org/tomaszczechowski/gulp-string-replace.svg?branch=master
[npm-url]: https://npmjs.org/package/gulp-string-replace
[npm-image]: https://badge.fury.io/js/gulp-string-replace.svg
[gulp-string-replace-dependencies-image]: https://david-dm.org/tomaszczechowski/gulp-string-replace/status.png
[gulp-string-replace-dependencies-url]: https://david-dm.org/tomaszczechowski/gulp-string-replace#info=dependencies
{'fraction_non_alphanumeric': 0.2013151239251391, 'fraction_numerical': 0.0064070139942674085, 'mean_word_length': 4.282279608192342, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3413730', 'n_tokens_mistral': 2057, 'n_tokens_neox': 1974, 'n_words': 365}