mirror of
https://github.com/stCarolas/setup-maven.git
synced 2024-11-27 05:36:09 +08:00
18 lines
604 B
JavaScript
18 lines
604 B
JavaScript
|
import keys from './keys.js';
|
||
|
|
||
|
// Internal helper to generate functions for escaping and unescaping strings
|
||
|
// to/from HTML interpolation.
|
||
|
export default function createEscaper(map) {
|
||
|
var escaper = function(match) {
|
||
|
return map[match];
|
||
|
};
|
||
|
// Regexes for identifying a key that needs to be escaped.
|
||
|
var source = '(?:' + keys(map).join('|') + ')';
|
||
|
var testRegexp = RegExp(source);
|
||
|
var replaceRegexp = RegExp(source, 'g');
|
||
|
return function(string) {
|
||
|
string = string == null ? '' : '' + string;
|
||
|
return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
|
||
|
};
|
||
|
}
|