Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Latest commit

 

History

History
61 lines (42 loc) · 1.71 KB

README.md

File metadata and controls

61 lines (42 loc) · 1.71 KB

token-substitute

Build Status npm

Substitute tokens in an object.

Installation

npm install token-substitute --save

Getting Started

var substitute = require('token-substitute');

var configObject = { key: '#{config.key}', url: '#{host.url}' }; // Can also just be a string value

var options = {
  tokens: {
    'config.key': 'abcd1234',
    host: {
      url: 'https://api.trustpilot.com'
    }
  }
};

var config = substitute(configObject, options);

console.log(config);

// outputs
// { key: 'abcd1234', url: 'https://api.trustpilot.com' }

API

substitute(object config [, object options])

parameters

  • object config: The object with values that should be substituted
  • object options [optional]: object with configurable parameters [[connect|Client#wiki-method-connect]]

returns

  • object: object with substituted variables

Options

  • prefix: string (default #{)
  • suffix: string (default })
  • configFile: Default path to a json file with key and values - string (default ./config.json)
  • tokens: A object of string:value pairs. Will be overritten with values from configFile if file exists - object
  • preserveUnknownTokens: bool (default false)
  • delimiter: Tokens delimeter to match target object string (default .)

Modified from Pictela/gulp-token-replace