string-replace-with-object
v1.0.0
Published
Replace contents of string with key/values from object
Downloads
4
Maintainers
Readme
string-replace-with-object
Replace contents of string with key/values from object
Install
npm install --save string-replace-with-object
Usage
import stringReplaceWithObject from 'string-replace-with-object'
stringReplaceWithObject('hello', {hello: 'cat'})
// => 'cat'
stringReplaceWithObject('hello world', {hello: 'goodbye', world: 'sky'})
// => 'goodbye sky'
stringReplaceWithObject('hello hello', {hello: 'hey'})
// => 'hey hey'
stringReplaceWithObject('__hello__', {hello: 'yo'}, '__')
// => 'yo'
API
stringReplaceWithObject(str, obj, [delimeter])
Returns a string with replaced contents where key name occurrences are replaced with the key value.
str
type: string
A string to replace the contents of.
obj
type: object
An object with key/value pairs to replace the contents of str
.
delimeter
type: string
default: ''
A delimeter to surround both sides of key names when searching string. For example, a str
value of xYhelloxY
, an obj
of {hello: 'cat'}
, and a delimeter
of xY
would result in cat
.
LICENSE
MIT © Dustin Specker