1.0.0 • Published 6 years ago

@darkkenergy/interpolate v1.0.0

Weekly downloads
1
License
SEE LICENSE IN LI...
Repository
bitbucket
Last release
6 years ago

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!';
1.0.0

6 years ago