Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including repstr with all npm packages installed. Try it out:

var repstr = require("repstr")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

repstr v1.1.0

Replace in a template string all values provided in an object

RepStr

npm npm

Replace in a template string all values provided in an object

Installation

Use NPM to install RepStr:

npm install repstr

Usage

//Import dependencies 
var rep_str = require('repstr');

//Compile the template string
var str = rep_str('My car is {color}', { color: 'blue'});

//Display in console
console.log(str); //-> My car is blue

API

rep_str(str, obj [, prefix][, suffix])

Return a new string. Accepts the following arguments:

  • str: template string.
  • obj: an object with all the keys to be replaced in your template string.
  • prefix (optionally): a string with the prefix of the template variable. Default value is {.
  • suffix (optionally): a string with the suffix of the template variable. Default value is }.

License

Under the MIT LICENSE.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free