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