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

A string replace plugin for gulp

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
240K
decreased by-8.95%
Maintainers
1
Weekly downloads
 
Created

What is gulp-replace?

The gulp-replace npm package is a plugin for Gulp, a streaming build system, that allows you to search and replace text in files. It is useful for tasks such as modifying configuration files, updating version numbers, or replacing placeholders in templates.

What are gulp-replace's main functionalities?

Basic String Replacement

This feature allows you to replace a specific string with another string in the files matched by the gulp.src() method. In this example, all occurrences of 'foo' in text files within the 'src' directory are replaced with 'bar' and the modified files are saved to the 'dist' directory.

const gulp = require('gulp');
const replace = require('gulp-replace');

gulp.task('replace-text', function() {
  return gulp.src('src/*.txt')
    .pipe(replace('foo', 'bar'))
    .pipe(gulp.dest('dist'));
});

Regular Expression Replacement

This feature allows you to use regular expressions for more complex search and replace operations. In this example, any string matching the pattern 'foo' followed by one or more digits is replaced with 'bar'.

const gulp = require('gulp');
const replace = require('gulp-replace');

gulp.task('replace-regex', function() {
  return gulp.src('src/*.txt')
    .pipe(replace(/foo\d+/g, 'bar'))
    .pipe(gulp.dest('dist'));
});

Replacement with a Function

This feature allows you to use a function to determine the replacement value. The function receives the matched string and can return a modified version of it. In this example, all occurrences of 'foo' are replaced with 'FOO'.

const gulp = require('gulp');
const replace = require('gulp-replace');

gulp.task('replace-function', function() {
  return gulp.src('src/*.txt')
    .pipe(replace('foo', function(match) {
      return match.toUpperCase();
    }))
    .pipe(gulp.dest('dist'));
});

Other packages similar to gulp-replace

Keywords

FAQs

Package last updated on 06 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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