string-replace-with-object

1.0.0 • Public • Published

string-replace-with-object

NPM version Build Status Coverage Status

Code Climate Dependencies DevDependencies

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

Package Sidebar

Install

npm i string-replace-with-object

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • dustinspecker