Initial commit
[yaffs-website] / node_modules / micromatch / lib / chars.js
1 'use strict';
2
3 var chars = {}, unesc, temp;
4
5 function reverse(object, prepender) {
6   return Object.keys(object).reduce(function(reversed, key) {
7     var newKey = prepender ? prepender + key : key; // Optionally prepend a string to key.
8     reversed[object[key]] = newKey; // Swap key and value.
9     return reversed; // Return the result.
10   }, {});
11 }
12
13 /**
14  * Regex for common characters
15  */
16
17 chars.escapeRegex = {
18   '?': /\?/g,
19   '@': /\@/g,
20   '!': /\!/g,
21   '+': /\+/g,
22   '*': /\*/g,
23   '(': /\(/g,
24   ')': /\)/g,
25   '[': /\[/g,
26   ']': /\]/g
27 };
28
29 /**
30  * Escape characters
31  */
32
33 chars.ESC = {
34   '?': '__UNESC_QMRK__',
35   '@': '__UNESC_AMPE__',
36   '!': '__UNESC_EXCL__',
37   '+': '__UNESC_PLUS__',
38   '*': '__UNESC_STAR__',
39   ',': '__UNESC_COMMA__',
40   '(': '__UNESC_LTPAREN__',
41   ')': '__UNESC_RTPAREN__',
42   '[': '__UNESC_LTBRACK__',
43   ']': '__UNESC_RTBRACK__'
44 };
45
46 /**
47  * Unescape characters
48  */
49
50 chars.UNESC = unesc || (unesc = reverse(chars.ESC, '\\'));
51
52 chars.ESC_TEMP = {
53   '?': '__TEMP_QMRK__',
54   '@': '__TEMP_AMPE__',
55   '!': '__TEMP_EXCL__',
56   '*': '__TEMP_STAR__',
57   '+': '__TEMP_PLUS__',
58   ',': '__TEMP_COMMA__',
59   '(': '__TEMP_LTPAREN__',
60   ')': '__TEMP_RTPAREN__',
61   '[': '__TEMP_LTBRACK__',
62   ']': '__TEMP_RTBRACK__'
63 };
64
65 chars.TEMP = temp || (temp = reverse(chars.ESC_TEMP));
66
67 module.exports = chars;