Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
502 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | const matchValueName = /[$]?[\w-]+/g;
|
---|
| 2 |
|
---|
| 3 | const replaceValueSymbols = (value, replacements) => {
|
---|
| 4 | let matches;
|
---|
| 5 |
|
---|
| 6 | while ((matches = matchValueName.exec(value))) {
|
---|
| 7 | const replacement = replacements[matches[0]];
|
---|
| 8 |
|
---|
| 9 | if (replacement) {
|
---|
| 10 | value =
|
---|
| 11 | value.slice(0, matches.index) +
|
---|
| 12 | replacement +
|
---|
| 13 | value.slice(matchValueName.lastIndex);
|
---|
| 14 |
|
---|
| 15 | matchValueName.lastIndex -= matches[0].length - replacement.length;
|
---|
| 16 | }
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | return value;
|
---|
| 20 | };
|
---|
| 21 |
|
---|
| 22 | module.exports = replaceValueSymbols;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.