0.1.4 • Published 9 years ago

substitution v0.1.4

Weekly downloads
9
License
MIT
Repository
github
Last release
9 years ago

substitution.js

Build Status

JavaScript library to recursively substitute placeholders, possibly through a callback.

The library is intended for substituting placeholders in small strings. It will recursively replace all strings in an object or array. When a callback is provided as replacement, it will only be called if the placeholder is used.

Works in node.js or in the browser (optional AMD support).

Installation

npm

npm install substitution --save

bower

bower install substitution --save

Usage

var substitute = require('substitution'); // Node.js / AMD

var rawObject = {
  link: 'http://{domain}',
  dir: '{path}/bar',
  list: [
    'Go to {domain}',
    'Found on {path}'
  ]
};

var replacements = {
  path: 'www/assets',
  url: function(callback) {
    fs.readFile('domain.txt', 'utf-8', function(err, url) {
      callback(err, url);
    })
  }
};

substitute(rawObject, replacements, function(err, myObject) {
  // Use myObject
});
0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago