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 :)
yarn add dynamic-string
npm i dynamic-string
Import dynamicString
from dynamic-string
.
import { dynamicString } 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 = dynamicString('https://api.com/${id}', { id: '12101909' }) // https://api.com/12101909
const stringFn = dynamicString('Hey ${name}') // fn ({name}) => `Hey ${name}`