Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

lotaris/metalsmith-text-replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ Unmaintained.


metalsmith-text-replace

This is a plugin for Metalsmith that allows globally replacing text.

Usage

This plugin matches files using the minimatch pattern and applies Javascript's String.prototype.replace() on its contents. Parameters are passed as defined, so you can provide regular expressions and functions as well.

If using the CLI for Metalsmith, metalsmith-text-replace can be used like any other plugin by including it in metalsmith.json. For example:

{
  "plugins": {
    "metalsmith-text-replace": {
      "**/**": {
        "find": "cat",
        "replace": "dog"
      }
    }
  }
}

Note that when applied this way, only string can be passed as arguments.

For Metalscript's JavaScript API, metalsmith-text-replace can be used like any other plugin, by attaching it to the function invocation chain on the Metalscript object. For example:

var replace = require('metalsmith-text-replace');
require('metalsmith')(__dirname)
  .use(replace({
    '**/**': {
      find: /cat/gi,
      replace: "dog"
    }
  })
  .build();

You can also provide an array if you want to replace multiple strings in the same match:

var replace = require('metalsmith-text-replace');
require('metalsmith')(__dirname)
  .use(replace({
    '**/**': [
      {
        find: /cat/gi,
        replace: "dog"
      },
      {
        find: /foobar/g,
        replace: function(match) { return match.toUpperCase(); }
      }
    ]
  })
  .build();

Options

You can pass additional options to minimatch using the options property.

License

MIT, see LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •