提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
502 B

  1. const matchValueName = /[$]?[\w-]+/g;
  2. const replaceValueSymbols = (value, replacements) => {
  3. let matches;
  4. while ((matches = matchValueName.exec(value))) {
  5. const replacement = replacements[matches[0]];
  6. if (replacement) {
  7. value =
  8. value.slice(0, matches.index) +
  9. replacement +
  10. value.slice(matchValueName.lastIndex);
  11. matchValueName.lastIndex -= matches[0].length - replacement.length;
  12. }
  13. }
  14. return value;
  15. };
  16. module.exports = replaceValueSymbols;