|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
604 bytes
|
| Line | |
|---|
| 1 | import keys from './keys.js';
|
|---|
| 2 |
|
|---|
| 3 | // Internal helper to generate functions for escaping and unescaping strings
|
|---|
| 4 | // to/from HTML interpolation.
|
|---|
| 5 | export default function createEscaper(map) {
|
|---|
| 6 | var escaper = function(match) {
|
|---|
| 7 | return map[match];
|
|---|
| 8 | };
|
|---|
| 9 | // Regexes for identifying a key that needs to be escaped.
|
|---|
| 10 | var source = '(?:' + keys(map).join('|') + ')';
|
|---|
| 11 | var testRegexp = RegExp(source);
|
|---|
| 12 | var replaceRegexp = RegExp(source, 'g');
|
|---|
| 13 | return function(string) {
|
|---|
| 14 | string = string == null ? '' : '' + string;
|
|---|
| 15 | return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
|
|---|
| 16 | };
|
|---|
| 17 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.