npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-replace-task

v2.0.1

Published

Replace text patterns with applause.

Downloads

35,402

Readme

gulp-replace-task

Build Status Version Prerequisite License: MIT Twitter: outa7iME

Replace text patterns with applause.

Install

From NPM:

npm install gulp-replace-task --save-dev

Usage

Assuming installation via NPM, you can use gulp-replace-task in your gulpfile like this:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/index.html')
    .pipe(
      replace({
        patterns: [
          {
            match: 'foo',
            replacement: 'bar'
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Options

Supports all the applause options.

Examples

Basic

File src/manifest.appcache:

CACHE MANIFEST
# @@timestamp

CACHE:

favicon.ico
index.html

NETWORK:
*

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/manifest.appcache')
    .pipe(
      replace({
        patterns: [
          {
            match: 'timestamp',
            replacement: Date.now()
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

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

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');
var pkg = require('./package.json');

gulp.task('default', function () {
  gulp
    .src(['src/manifest.appcache', 'src/humans.txt'])
    .pipe(
      replace({
        patterns: [
          {
            match: 'version',
            replacement: pkg.version
          },
          {
            match: 'timestamp',
            replacement: Date.now()
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Cache busting

File src/index.html:

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

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/index.html')
    .pipe(
      replace({
        patterns: [
          {
            match: 'timestamp',
            replacement: Date.now()
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Include file

File src/index.html:

<body>
  @@include
</body>

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');
var fs = require('fs');

gulp.task('default', function () {
  gulp
    .src('src/index.html')
    .pipe(
      replace({
        patterns: [
          {
            match: 'include',
            replacement: fs.readFileSync('./includes/content.html', 'utf8')
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Regular expression

File src/username.txt:

John Smith

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/username.txt')
    .pipe(
      replace({
        patterns: [
          {
            match: /(\w+)\s(\w+)/,
            replacement: '$2, $1' // Replaces "John Smith" with "Smith, John"
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Lookup for foo instead of @@foo

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/foo.txt')
    .pipe(
      replace({
        patterns: [
          {
            match: /foo/g, // Explicitly using a regexp
            replacement: 'bar'
          }
        ]
      })
    )
    .pipe(
      replace({
        patterns: [
          {
            match: 'foo',
            replacement: 'bar'
          }
        ],
        usePrefix: false // Using the option provided
      })
    )
    .pipe(
      replace({
        patterns: [
          {
            match: 'foo',
            replacement: 'bar'
          }
        ],
        prefix: '' // Removing the prefix manually
      })
    )
    .pipe(gulp.dest('build'));
});

Related

License

MIT © outaTiME