interpolate-regex
Version:
Useful for basic templating by interpolating values into placeholders. Takes a left and right delimiter and returns a regex object for matching them and capturing the contents.
30 lines (20 loc) • 706 B
Markdown
for basic templating by interpolating values into placeholders. Takes a left and right delimiter and returns a regex object for matching them and capturing the contents.
```sh
npm install interpolate-regex
```
```js
const Regex = require('interpolate-regex')
const data = {place: 'world'}
'Hello, {{place}}'.replace(Regex('{{', '}}'), (_, contents) => {
console.log(contents) // -> 'place'
return data[contents] // -> 'world'
}) // -> 'Hello, world'
```
- `left: string` left delimiter
- `right: string` right delimiter
- `matchEmpty: boolean, true` match when there is nothing in between delimiters
Useful