source: node_modules/expand-template/index.js@ 81bc7da

finki-main main
Last change on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 672 bytes
Line 
1module.exports = function (opts) {
2 var sep = opts ? opts.sep : '{}'
3 var len = sep.length
4
5 var whitespace = '\\s*'
6 var left = escape(sep.substring(0, len / 2)) + whitespace
7 var right = whitespace + escape(sep.substring(len / 2, len))
8
9 return function (template, values) {
10 Object.keys(values).forEach(function (key) {
11 var value = String(values[key]).replace(/\$/g, '$$$$')
12 template = template.replace(regExp(key), value)
13 })
14 return template
15 }
16
17 function escape (s) {
18 return [].map.call(s, function (char) {
19 return '\\' + char
20 }).join('')
21 }
22
23 function regExp (key) {
24 return new RegExp(left + key + right, 'g')
25 }
26}
Note: See TracBrowser for help on using the repository browser.