Skip to content

lionel87/interpolate-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String interpolation

Replaces the marked parts of a text with values from a given set, similar to a templating engine, but less robust.

Installation

npm install --save interpolate-string

Usage

const interpolate = require("interpolate-string");

const text = "Hello {{ name.first }}!";
const data = { name: { first: "John", last: "Doe" }};

const result = interpolate(text, data);

console.log(result); // Hello John!

Alternatively you can also specify a pattern for the replacement format:

const interpolate = require("interpolate-string");

const text = "Hello ${name.first}!";
const pattern = /\$\{(.+?)\}/g;
const data = { name: { first: "John", last: "Doe" }};

const result = interpolate(text, data, pattern);

console.log(result); // Hello John!

About

Simple string interpolation without dependencies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors