https://github.com/jmjuanes/repstr
Replace in a string all the values provided in an object
https://github.com/jmjuanes/repstr
nodejs string string-template template-string
Last synced: 10 months ago
JSON representation
Replace in a string all the values provided in an object
- Host: GitHub
- URL: https://github.com/jmjuanes/repstr
- Owner: jmjuanes
- License: mit
- Created: 2016-05-07T11:30:10.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-05T14:23:58.000Z (almost 9 years ago)
- Last Synced: 2024-02-26T09:03:40.756Z (about 2 years ago)
- Topics: nodejs, string, string-template, template-string
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RepStr
[](https://www.npmjs.com/package/repstr)
[](https://www.npmjs.com/package/repstr)
Replace in a template string all values provided in an object
## Installation
Use [NPM](https://www.npmjs.com/package/repstr) to install **RepStr**:
```
npm install repstr
```
## Usage
```javascript
//Import dependencies
var rep_str = require('repstr');
//Compile the template string
var str = rep_str('My car is {color}', { color: 'blue'});
//Display in console
console.log(str); //-> My car is blue
```
## API
### rep_str(str, obj [, prefix][, suffix])
Return a new string. Accepts the following arguments:
- `str`: template string.
- `obj`: an object with all the keys to be replaced in your template string.
- `prefix` **(optionally)**: a string with the prefix of the template variable. Default value is `{`.
- `suffix` **(optionally)**: a string with the suffix of the template variable. Default value is `}`.
## License
Under the [MIT LICENSE](LICENSE).