Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-replace

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-replace - npm Package Compare versions

Comparing version 0.5.4 to 0.6.0

7

index.js

@@ -14,3 +14,8 @@ 'use strict';

}
if (typeof replacement === 'function') {
// Pass the vinyl file object as this.file
replacement = replacement.bind({ file: file });
}
function doReplace() {

@@ -17,0 +22,0 @@ if (file.isStream()) {

4

package.json
{
"name": "gulp-replace",
"version": "0.5.4",
"version": "0.6.0",
"description": "A string replace plugin for gulp",

@@ -11,3 +11,3 @@ "dependencies": {

"devDependencies": {
"concat-stream": "^1.5.0",
"concat-stream": "^1.5.2",
"mocha": "^2.1.0",

@@ -14,0 +14,0 @@ "should": "^7.0.1",

@@ -14,3 +14,3 @@ # gulp-replace [![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url]

### Regex Replace
### Simple string replace
```javascript

@@ -21,7 +21,20 @@ var replace = require('gulp-replace');

gulp.src(['file.txt'])
.pipe(replace('bar', 'foo'))
.pipe(gulp.dest('build/'));
});
```
### Simple regex replace
```javascript
var replace = require('gulp-replace');
gulp.task('templates', function(){
gulp.src(['file.txt'])
// See http://mdn.io/string.replace#Specifying_a_string_as_a_parameter
.pipe(replace(/foo(.{3})/g, '$1foo'))
.pipe(gulp.dest('build/file.txt'));
.pipe(gulp.dest('build/'));
});
```
### String Replace
### String replace with function callback
```javascript

@@ -32,8 +45,43 @@ var replace = require('gulp-replace');

gulp.src(['file.txt'])
.pipe(replace('bar', 'foo'))
.pipe(gulp.dest('build/file.txt'));
.pipe(replace('foo', function(match) {
// Replaces instances of "foo" with "oof"
return match.reverse();
}))
.pipe(gulp.dest('build/'));
});
```
### Regex replace with function callback
```javascript
var replace = require('gulp-replace');
gulp.task('templates', function(){
gulp.src(['file.txt'])
.pipe(replace(/foo(.{3})/g, function(match, p1, offset, string) {
// Replace foobaz with barbaz and log a ton of information
// See http://mdn.io/string.replace#Specifying_a_function_as_a_parameter
console.log('Found ' + match + ' with param ' + p1 + ' at ' + offset + ' inside of ' + string);
return 'bar' + p1;
}))
.pipe(gulp.dest('build/'));
});
```
### Function callback with file object
```javascript
var replace = require('gulp-replace');
gulp.task('templates', function(){
gulp.src(['file.txt'])
.pipe(replace('filename', function() {
// Replaces instances of "filename" with "file.txt"
// this.file is also available for regex replace
// See https://github.com/gulpjs/vinyl#instance-properties for details on available properties
return this.file.relative;
}))
.pipe(gulp.dest('build/'));
});
```
## API

@@ -55,2 +103,4 @@

The value of `this.file` will be equal to the [vinyl instance](https://github.com/gulpjs/vinyl#instance-properties) for the file being processed.
### replace(regex, replacement[, options])

@@ -66,4 +116,6 @@

The replacement string or function. See the [MDN documentation for String.replace] for details.
The replacement string or function. See the [MDN documentation for String.replace] for details on special replacement string patterns and arguments to the replacement function.
The value of `this.file` will be equal to the [vinyl instance](https://github.com/gulpjs/vinyl#instance-properties) for the file being processed.
### gulp-replace options

@@ -70,0 +122,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc