1 | 'use strict';
|
2 | const config = require('./config.js');
|
3 |
|
4 | const SUB_WITH_MATCH = '%VAL%';
|
5 |
|
6 | module.exports = text => {
|
7 | const replacer = config.get('replace');
|
8 | for (const key in replacer) {
|
9 | if (Object.prototype.hasOwnProperty.call(replacer, key)) {
|
10 | const value = replacer[key];
|
11 | const regex = new RegExp(key, 'gi');
|
12 | const matches = text.match(regex);
|
13 | for (let i = 0; i < matches.length; ++i) {
|
14 | const match = matches[i];
|
15 | text = text.replace(match, value);
|
16 | text =
|
17 | text.replace(
|
18 | new RegExp(SUB_WITH_MATCH, 'gi'),
|
19 | match);
|
20 | }
|
21 | }
|
22 | }
|
23 | return text;
|
24 | };
|