-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathminify.json.js
More file actions
106 lines (102 loc) · 2.14 KB
/
minify.json.js
File metadata and controls
106 lines (102 loc) · 2.14 KB
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
/*! JSON.minify()
v3.0.0 (c) Kyle Simpson
MIT License
*/
(function(global){
if (typeof global.JSON == "undefined" || !global.JSON) {
global.JSON = {};
}
global.JSON.minify = function JSON_minify(json) {
var in_string = false,
in_multiline_comment = false,
in_singleline_comment = false,
backslash = false,
len = json.length,
i = 0,
c,
new_str = [],
from = 0,
new_chars = 0,
add_chars = 0;
while (i < len) {
backslash = !backslash && c == "\\"
c = json[i++];
if (in_singleline_comment) {
if (c == "\r" || c == "\n") {
in_singleline_comment = false;
}
}
else if (in_multiline_comment) {
if (c == "*") {
if (i >= len) {
break;
}
c = json[i++];
if (c == "/") {
in_multiline_comment = false;
}
}
}
else {
if (c == "\"" && !backslash) {
in_string = !in_string;
add_chars = 1;
}
else if (in_string) {
if (c != "\n" && c != "\r") {
add_chars = 1;
}
}
else {
if (c == "/") {
if (i >= len) {
add_chars = 1;
if (new_chars == 0) {
from = i - add_chars;
}
new_chars += add_chars;
break;
}
backslash = !backslash && c == "\\"
c = json[i++];
if (c == "/") {
in_singleline_comment = true;
}
else if (c == "*") {
in_multiline_comment = true;
}
else {
add_chars = 2;
}
}
else if (c !== " " && c !== "\t" && c !== "\n" && c !== "\r") {
add_chars = 1;
}
}
}
if (add_chars > 0) {
if (new_chars == 0) {
from = i - add_chars;
}
new_chars += add_chars;
add_chars = 0;
}
else if (new_chars > 0) {
new_str.push(json.substring(from, from + new_chars));
new_chars = 0;
}
}
if (new_chars > 0) {
new_str.push(json.substring(from, from + new_chars));
}
return new_str.join("");
};
})(
// attempt to reference the global object
typeof globalThis != "undefined" ? globalThis :
typeof global != "undefined" ? global :
typeof window != "undefined" ? window :
typeof self != "undefined" ? self :
typeof this != "undefined" ? this :
{}
);