Replaces the tokens in a string by the corresponding values.
- Source:
Methods
(static) interpolate(value, tokensopt, divideropt) → {string}
- Source:
Example
import { interpolate } from '@untemps/utils/string/interpolate'
const value = 'A %foo% with a "%bar%" wings and a lot of %fun%'
const tokens = {
foo: 'bird',
bar: 3,
fun: 'dignity'
}
const divider = '%'
interpolate(value, tokens, divider) // A bird with a "3" wings and a lot of dignity
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
string | The string value to interpolate. |
||
tokens |
object.<key, value> |
<optional> |
{}
|
An object of key/value pairs to replace the tokens. |
divider |
string |
<optional> |
'%'
|
The symbol that identifies a token. |
Returns:
The interpolated string.
- Type
- string