Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dustinspecker/string-replace-with-object
https://github.com/dustinspecker/string-replace-with-object
Last synced: 2 days 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 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-28T20:12:56.000Z (over 7 years ago)
- Last Synced: 2024-10-07T04:48:26.574Z (about 1 month ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# string-replace-with-object
[![NPM version](https://badge.fury.io/js/string-replace-with-object.svg)](https://badge.fury.io/js/string-replace-with-object) [![Build Status](https://travis-ci.org/dustinspecker/string-replace-with-object.svg)](https://travis-ci.org/dustinspecker/string-replace-with-object) [![Coverage Status](https://img.shields.io/coveralls/dustinspecker/string-replace-with-object.svg)](https://coveralls.io/r/dustinspecker/string-replace-with-object?branch=master)[![Code Climate](https://codeclimate.com/github/dustinspecker/string-replace-with-object/badges/gpa.svg)](https://codeclimate.com/github/dustinspecker/string-replace-with-object) [![Dependencies](https://david-dm.org/dustinspecker/string-replace-with-object.svg)](https://david-dm.org/dustinspecker/string-replace-with-object/#info=dependencies&view=table) [![DevDependencies](https://david-dm.org/dustinspecker/string-replace-with-object/dev-status.svg)](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)