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-token-replace

v1.1.5

Published

A token replace plugin for gulp

Downloads

13,793

Readme

gulp-token-replace NPM version Build status

A token replace plugin for gulp 3

Installation

First, install gulp-token-replace as a development dependency:

npm install --save-dev gulp-token-replace

Usage

Add it to your gulpfile.js:

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

gulp.task('token-replace', function(){
  var config = require('./configuration/config.json');
  return gulp.src(['src/*.js', 'src/*.html'])
    .pipe(replace({global:config}))
    .pipe(gulp.dest('dist/'))
});

Example config

module.exports = {
  "tokens":{
    "RMLibs":"http://ads.pictela.com/ads/jsapi/ADTECH.js",
    "size":"320x50",
    "Copyrights":"Copyright 2010-2014 AOL Platforms.",
    "Author":"Martin Wojtala"
  },
  "main":{
      "name":"example",
      "title":"EXAMPLE TITLE"
    }
};

In a file (also works for JavaScript)

<!--{{tokens.Copyrights}}-->
<!--canvasSize:{{tokens.size}}-->
<!DOCTYPE html>
<html lang="en">
<head><title>{{main.title}}</title>
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    <meta charset="UTF-8">
    <script src="{{tokens.RMLibs}}"></script>
    <script src="swipe.min.js"></script>
    <link rel="stylesheet" href="{{main.name}}.css">
    <script src="{{main.name}}.debug.js"></script>
</head>
<body>
<div id="content"></div>
<div id="debug"></div>
</body>
</html>

CHANGELOG

  • [1.1.5] Node LTS change.
  • [1.1.4] Packages audit fixes and Event-stream downgrade due to the security flag (downgraded to non-malicious version, 3.3.4 from 3.3.6).
  • [1.1.3] Legacy plugin updates (Thanks coreyfarrell).
  • [1.1.2] Full support for arrays (thank you for the feature request Daniel Jost & @gregmcor).
  • [1.1.1] Minor documentation adjustments.
  • [1.1.0] Added support for nested arrays. Tokens can now include an array which can be retrieved by specific order number (i.e. array[0]);
  • [1.0.4] Dependencies bump (contribution by @coreyfarrell).
  • [1.0.3] Custom token delimiter added (contribution by @ejurgelionis).
  • [1.0.2] Added a object replace feature.

API

gulp-token-replace can be called with a config object with these attributes:

  • prefix (defaults to '{{')
  • suffix (defaults to '}}')
  • tokens (or global) - An object containing all the tokens to be used for replacement. This object can contain sub-objects with hierarchical tokens.
  • preserveUnknownTokens (defaults to false) - By default unknown tokens will be removed from the source file and replaced with an empty string. By setting the preserveUnknownTokens option to true, the source file will not be changed when an unknown token is encountered.
  • delimiter (defaults to '.') - By default dot-notation is used to search for values in sub-objects. By setting the delimiter option to any other value, tokens like {{main.css}} or {{styles/main.css}} can be used.

replace(object)

object

Type: Object

configuration object.

Note: gulp-token-replace cannot perform regex replacement on streams.