Narcissistic Pickle Meister
Miss any of our Open RFC calls?Watch the recordings here! »

@darkkenergy/interpolate

1.0.0 • Public • Published

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

Install

npm i @darkkenergy/interpolate

DownloadsWeekly Downloads

1

Version

1.0.0

License

SEE LICENSE IN LICENSE.txt

Unpacked Size

4.21 kB

Total Files

4

Last publish

Collaborators

  • avatar