key-value-replace
v3.0.0
Published
Replace key/value pairs in a string
Downloads
1,306
Maintainers
Readme
key-value-replace
Replace key/value pairs in a string.
Install
npm install key-value-replace
Usage
const replace = require('key-value-replace')
replace('hello {{ name }}', { name: 'world' }) // hello world
replace('{{ greeting }} {{ name }}', { greeting: 'hi', name: 'world' }) // hi world
replace('hello {{ name }}', { name: (key, i, data, str) => key }) // hello name
replace('hello !! name !!', { name: 'world' }, [ '!! ', ' !!' ]) // hello world
Parameters
str
{String}
- A string to replace the contents of.obj
{Object}
- Key/value pairs, where value must be a function or a string.delimiter
{Array}
- Optional array with a start and end delimiter.{String}
Start delimiter. Defaults to'{{ '
.{String}
End delimiter. Defaults to' }}'
.
Returns
{String}
- A string with replaced content.