fr

fez-replace

Replace text patterns with applause.

Showing:

Popularity

Downloads/wk

15

GitHub Stars

1

Maintenance

Last Commit

4mos ago

Contributors

0

Package

Dependencies

1

Size (min+gzip)

27.4KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

fez-replace

Build Status Version Prerequisite License: MIT Commitizen friendly Twitter: outa7iME

Replace text patterns with applause.

Install

From NPM:

npm install fez-replace --save-dev

Usage

Assuming installation via NPM, you can use fez-replace in your script like this:

var fez = require('fez');
var replace = require('fez-replace');

exports.default = function (spec) {
  spec.with('src/index.html').one(function (file) {
    spec.rule(file, 'build/index.html', replace({
      patterns: [
        {
          match: 'foo',
          replacement: 'bar'
        }
      ]
    }));
  });
};

fez(module);

Options

Supports all the applause options.

Examples

Basic

File src/manifest.appcache:

CACHE MANIFEST
# @@timestamp

CACHE:

favicon.ico
index.html

NETWORK:
*

fez.js:

var fez = require('fez');
var replace = require('fez-replace');

exports.default = function (spec) {
  spec.with('src/manifest.appcache').one(function (file) {
    spec.rule(file, 'build/manifest.appcache', replace({
      patterns: [
        {
          match: 'timestamp',
          replacement: Date.now()
        }
      ]
    }));
  });
};

fez(module);

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

fez.js:

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

exports.default = function (spec) {
  spec.with(['src/manifest.appcache', 'src/humans.txt']).each(function (file) {
    spec.rule(file, file.patsubst('src/%', 'build/%'), replace({
      patterns: [
        {
          match: 'version',
          replacement: pkg.version
        },
        {
          match: 'timestamp',
          replacement: Date.now()
        }
      ]
    }));
  });
};

fez(module);

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>

fez.js:

var fez = require('fez');
var replace = require('fez-replace');

exports.default = function (spec) {
  spec.with('src/index.html').one(function (file) {
    spec.rule(file, 'build/index.html', replace({
      patterns: [
        {
          match: 'timestamp',
          replacement: Date.now()
        }
      ]
    }));
  });
};

fez(module);

Include file

File src/index.html:

<body>
  @@include
</body>

fez.js:

var fs = require('fs');
var fez = require('fez');
var replace = require('fez-replace');

exports.default = function (spec) {
  spec.with('src/index.html').one(function (file) {
    spec.rule(file, 'build/index.html', replace({
      patterns: [
        {
          match: 'include',
          replacement: fs.readFileSync('./includes/content.html', 'utf8')
        }
      ]
    }));
  });
};

fez(module);

Regular expression

File src/username.txt:

John Smith

fez.js:

var fez = require('fez');
var replace = require('fez-replace');

exports.default = function (spec) {
  spec.with('src/username.txt').one(function (file) {
    spec.rule(file, 'build/username.html', replace({
      patterns: [
        {
          match: /(\w+)\s(\w+)/,
          replacement: '$2, $1' // Replaces "John Smith" with "Smith, John"
        }
      ]
    }));
  });
};

fez(module);

Lookup for foo instead of @@foo

fez.js:

var fez = require('fez');
var replace = require('fez-replace');

exports.default = function (spec) {
  spec.with('src/foo.txt').one(function (file) {
    spec.rule(file, 'build/foo.txt', replace({
      patterns: [
        {
          match: /foo/g, // Explicitly using a regexp
          replacement: 'bar'
        }
      ]
    }));
    spec.rule(file, 'build/foo.txt', replace({
      patterns: [
        {
          match: 'foo',
          replacement: 'bar'
        }
      ],
      usePrefix: false // Using the option provided
    }));
    spec.rule(file, 'build/foo.txt', replace({
      patterns: [
        {
          match: 'foo',
          replacement: 'bar'
        }
      ],
      prefix: '' // Removing the prefix manually
    }));
  });
};

fez(module);
  • applause - Human-friendly replacements

License

MIT © outaTiME

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100