1.0.0 • Published 4 years ago

stringin v1.0.0

Weekly downloads
6
License
-
Repository
github
Last release
4 years ago

stringin logo

stringin

A teeny-weeny utility to programatically interpolate ES6 string templates.

NPM Version Shield NPM Size Shield

Get Started

Install as a dependency in the console:

npm i stringin

Import and use in your JS/TS project:

import interpolate from 'stringin'

// Define your template with '${}'s inside
const template = 'There are ${choreCount} chores to do today'

// Then interpolate with static values
interpolate(template, { choreCount: 4 })
// 'There are 4 chores to do today'

// Or use a function to get a value
interpolate(template, { choreCount: () => 2 + 5 })
// 'There are 7 chores to do today'

Usage

replace (template, data)

Parameters:

NameTypeDescription
templatestringThe template string containing the different ${fieldNames}.
dataObjectThe data to insert into the template.

Returns:

Type: String