dynamic-string
v0.1.2
Published
Reuse string interpolation in JavaScript. `dynamic-string` is a a curried dynamic template string.
Downloads
22
Maintainers
Readme
Dynamic string
Reuse string interpolation in JavaScript. dynamic-string
is a a curried dynamic template string.
You can use it to replace id's in API endpoints, username's in greetings or whatever your imagination leads to :)
Install
yarn add dynamic-string
npm i dynamic-string
Getting started
Import dynamicString
from dynamic-string
.
import { dynamicTemplate } from 'dynamic-string'
This curried function receives two positional arguments:
- A string template with '${}' for interpolation
- An object with the variables to be interpolated as keys.
You can use it directly or not, as in:
const string = dynamicTemplate('https://api.com/${id}', { id: '12101909' }) // https://api.com/12101909
const stringFn = dynamicTemplate('Hey ${name}') // fn ({name}) => `Hey ${name}`