执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var REVERSE_SOLIDUS = 0x5c; // \
var QUOTATION_MARK = 0x22;  // "
var APOSTROPHE = 0x27;      // '
var TAB = 0x09;             // tab
var WHITESPACE = 0x20;      // space
var AMPERSAND = 0x26;
var LESSTHANSIGN = 0x3C;
var GREATERTHANSIGN = 0x3E;
 
function isHex(code) {
    return (code >= 48 && code <= 57) || // 0 .. 9
           (code >= 65 && code <= 70) || // A .. F
           (code >= 97 && code <= 102);  // a .. f
}
 
function decodeString(str) {
    var decoded = '';
    var len = str.length;
    var firstChar = str.charCodeAt(0);
    var start = firstChar === QUOTATION_MARK || firstChar === APOSTROPHE ? 1 : 0;
    var end = start === 1 && len > 1 && str.charCodeAt(len - 1) === firstChar ? len - 2 : len - 1;
 
    for (var i = start; i <= end; i++) {
        var code = str.charCodeAt(i);
 
        if (code === REVERSE_SOLIDUS) {
            // special case at the ending
            if (i === end) {
                // if the next input code point is EOF, do nothing
                // otherwise include last quote as escaped
                if (i !== len - 1) {
                    decoded = str.substr(i + 1);
                }
                break;
            }
 
            code = str.charCodeAt(++i);
 
            // ignore escaped newline
            if (code !== 0x0A && code !== 0x0C && code !== 0x0D) { // TODO: should treat a "CR/LF" pair (U+000D/U+000A) as a single white space character
                // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
                for (var j = 0; j < 6 && i + j <= end;) {
                    code = str.charCodeAt(i + j);
 
                    if (isHex(code)) {
                        j++;
                    } else {
                        break;
                    }
                }
 
                if (j > 0) {
                    code = str.charCodeAt(i + j);
 
                    // include space into sequence
                    // TODO: add newline support
                    if (code === WHITESPACE || code === TAB) {
                        j++;
                    }
 
                    code = parseInt(str.substr(i, j), 16);
 
                    if (
                        (code === 0) ||                       // If this number is zero,
                        (code >= 0xD800 && code <= 0xDFFF) || // or is for a surrogate,
                        (code > 0x10FFFF)                     // or is greater than the maximum allowed code point
                       ) {
                        // ... return U+FFFD REPLACEMENT CHARACTER
                        code = 0xFFFD;
                    }
 
                    // FIXME: code above 0xFFFF will be converted incorrectly,
                    // better to use String.fromCharPoint() but it lack of support by engines
                    decoded += String.fromCharCode(code);
                    i += j - 1;
                } else {
                    decoded += str.charAt(i);
                }
            }
        } else {
            decoded += str.charAt(i);
        }
    }
 
    return decoded;
}
 
function encodeString(str, apostrophe) {
    var quote = apostrophe ? '\'' : '"';
    var quoteCode = apostrophe ? APOSTROPHE : QUOTATION_MARK;
    var encoded = quote;
    var wsBeforeHexIsNeeded = false;
 
    for (var i = 0; i < str.length; i++) {
        var code = str.charCodeAt(i);
 
        if (code <= 0x1F || code === AMPERSAND || code === LESSTHANSIGN || code === GREATERTHANSIGN) {
            encoded += '\\' + code.toString(16);
            wsBeforeHexIsNeeded = true;
        } else if (code === REVERSE_SOLIDUS || code === quoteCode) {
            encoded += '\\' + str.charAt(i);
            wsBeforeHexIsNeeded = false;
        } else {
            if (wsBeforeHexIsNeeded && isHex(code)) {
                encoded += ' ';
            }
 
            encoded += str.charAt(i);
            wsBeforeHexIsNeeded = false;
        }
    }
 
    encoded += quote;
 
    return encoded;
}
 
module.exports = {
    decode: decodeString,
    encode: encodeString
};