node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org »

tagged-replace

tagged-replace

Build Status Coverage Status

Replace pieces of your source using comment tags to identify the location.

Usage

/* configuration.js */
 
var myServer = /*host*/ '' /*/host*/;
var fs = require('fs');
var taggedReplace = require('tagged-replace');
 
var content = fs.readFileSync('./configuration.js');
console.log( taggedReplace( content, { host: '\'myhost.example.com\'' } ) );
/* console */
 
var myServer = /*host*/ 'myhost.example.com' /*/host*/;

taggedReplace(contents[, values[, options]])

contents

contents is the string which may contains some tags

values

values is an object where each key is the name of a tag and its value will be replaced, as a string in the characters between the starting and ending tag.

options

options is an object with overrides for the default parameters described below.

Configuration

Tag characters

startPrefix

The beginning of the start tag. Defaults to '/*'.

startSuffix

The ending of the start tag. Defaults to '*/'.

endPrefix

The beginning of the end tag. Defaults to '/*/'.

endSuffix

The ending of the end tag. Defaults to '*/'.

Result padding

space

Set to true to keep the contents separated from the tags by a space. Defaults to true.

The default options are:

defaultOptions = {
   startPrefix: '/*',
   startSuffix: '*/',
   endPrefix: '/*/',
   endSuffix: '*/',
   space: true
};