https://github.com/dustinspecker/string-replace-with-object
https://github.com/dustinspecker/string-replace-with-object
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/dustinspecker/string-replace-with-object
- Owner: dustinspecker
- License: mit
- Created: 2016-03-29T21:46:55.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-28T20:12:56.000Z (about 8 years ago)
- Last Synced: 2025-03-17T04:18:49.528Z (4 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# string-replace-with-object
[](https://badge.fury.io/js/string-replace-with-object) [](https://travis-ci.org/dustinspecker/string-replace-with-object) [](https://coveralls.io/r/dustinspecker/string-replace-with-object?branch=master)[](https://codeclimate.com/github/dustinspecker/string-replace-with-object) [](https://david-dm.org/dustinspecker/string-replace-with-object/#info=dependencies&view=table) [](https://david-dm.org/dustinspecker/string-replace-with-object/#info=devDependencies&view=table)
> Replace contents of string with key/values from object
## Install
```
npm install --save string-replace-with-object
```## Usage
```javascript
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](https://github.com/dustinspecker)