@darkkenergy/interpolate
v1.0.0
Published
Interpolates placeholders from a string into some specified values.
Downloads
1
Maintainers
Readme
Interpolate
Interpolates placeholders from a string into some specified values - placeholder shall be wrapped in single curly braces & named after some model property - model is provided to replace the placeholders with values.
Install
npm i @darkkenergy/interpolate -S
Inclusion
// CommonJS
var Interpolate = require('@darkkenergy/interpolate');
// ES6
import Interpolate from '@darkkenergy/interpolate';
Usage
/**
* Interpolates placeholders from a string into some specified values -
* placeholder shall be wrapped in single curly braces & named after some
* model property - model is provided to replace the placeholders with
* values.
*
* @param str {string} :The placeholder-inclusive string to interpolate.
* @param model {object} :The model of values to replace the placeholders
* with.
*
* @return {string} :The newly interpolated string.
*/
function Interpolate(str, model) {
// Interpolate(string, object)
import Interpolate from '@darkkenergy/interpolate';
Example:
const first = 'John';
const last = 'Smith';
Interpolate('Hello { first } { last }!', { first, last });
// Outputs: 'Hello John Smith!';