1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | 'use strict';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function escape(key) {
|
22 | var escapeRegex = /[=:]/g;
|
23 | var escaperLookup = {
|
24 | '=': '=0',
|
25 | ':': '=2'
|
26 | };
|
27 | var escapedString = ('' + key).replace(escapeRegex, function (match) {
|
28 | return escaperLookup[match];
|
29 | });
|
30 |
|
31 | return '$' + escapedString;
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function unescape(key) {
|
41 | var unescapeRegex = /(=0|=2)/g;
|
42 | var unescaperLookup = {
|
43 | '=0': '=',
|
44 | '=2': ':'
|
45 | };
|
46 | var keySubstring = key[0] === '.' && key[1] === '$' ? key.substring(2) : key.substring(1);
|
47 |
|
48 | return ('' + keySubstring).replace(unescapeRegex, function (match) {
|
49 | return unescaperLookup[match];
|
50 | });
|
51 | }
|
52 |
|
53 | var KeyEscapeUtils = {
|
54 | escape: escape,
|
55 | unescape: unescape
|
56 | };
|
57 |
|
58 | module.exports = KeyEscapeUtils; |
\ | No newline at end of file |