Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
228 lines (209 loc) · 6.77 KB

File metadata and controls

228 lines (209 loc) · 6.77 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Generated by CoffeeScript 1.6.3
(function() {
var ForComparison, isObject, isString, rotateText, supportsCanvas, values;
isString = function(obj) {
return Object.prototype.toString.call(obj) === "[object String]";
};
isObject = function(obj) {
return Object.prototype.toString.call(obj) === "[object Object]";
};
ForComparison = (function() {
function ForComparison(item) {
var match, mtch;
this.item = item;
/*
The goal here is to get a string that evaluates to the desired
value. This string is set to object.asString
For complicated cases which can't be passed in JSON the value
can be passed as a string wrapped in backticks which is evaluated
here.
example: "`parseFloat("nan")`" means NaN.
*/
this.asString = "" + this.item;
if (isString(this.item)) {
if (this.item.length > 0 && (mtch = this.item.match(/^`(.*)`$/))) {
match = mtch[1];
this.item = new Function("return " + match)();
if (isString(this.item)) {
this.asString = JSON.stringify(this.item);
} else if (this.item === undefined) {
this.asString = "undefined";
} else if (isObject(this.item)) {
this.asString = JSON.stringify(this.item);
} else if (isNaN(this.item)) {
this.asString = "NaN";
} else {
this.asString = JSON.stringify(this.item);
}
} else if (this.item.length === 0) {
this.asString = '""';
}
} else if (this.item.toString() === "[object Object]") {
this.asString = "{}";
} else if (this.item instanceof Array) {
this.asString = JSON.stringify(this.item);
}
}
ForComparison.prototype.testResults = function(fc2, comparator) {
var evalStr;
if (comparator == null) {
comparator = "===";
}
evalStr = "" + this.asString + comparator + fc2.asString;
return [evalStr, eval('(' + evalStr + ')')];
};
ForComparison.prototype.toString = function() {
return this.asString;
};
return ForComparison;
})();
/*
The values which are strings wrapped in backticks (`) are evaluated
before being compared.
*/
values = [true, false, 1, 0, -1, "`'true'`", "`'false'`", "`'1'`", "`'0'`", "`'-1'`", "", "`null`", "`undefined`", "`[]`", "`{}`", [[]], [0], [1], "`parseFloat('nan')`"];
(function() {
var testRepr;
testRepr = function(what, shouldBe) {
var fc;
fc = new ForComparison(what);
if (fc.toString() !== shouldBe) {
throw new Error("Value is not being represented correctly.");
}
};
testRepr(true, "true");
testRepr(false, "false");
testRepr(1, "1");
testRepr(0, "0");
testRepr(-1, "-1");
testRepr("`'true'`", "\"true\"");
testRepr("`'false'`", "\"false\"");
testRepr("`'1'`", "\"1\"");
testRepr("`'0'`", "\"0\"");
testRepr("`'-1'`", "\"-1\"");
testRepr("", "\"\"");
testRepr("`null`", "null");
testRepr("`undefined`", "undefined");
testRepr("`[]`", "[]");
testRepr("`{}`", "{}");
testRepr([[]], "[[]]");
testRepr([0], "[0]");
testRepr([1], "[1]");
return testRepr("`parseFloat('nan')`", "NaN");
})();
(function() {
var testEquality;
testEquality = function(tf, item, comparator) {
var fc1;
fc1 = new ForComparison(item);
if (fc1.testResults(fc1, comparator)[1] !== tf) {
throw new Error("Condition should be " + tf);
}
};
testEquality(true==true, "`true`", "==");
testEquality([[]]==[[]], "`[[]]`", "==");
return testEquality([]==[], "`[]`", "==");
})();
supportsCanvas = (function() {
var el;
el = document.createElement("canvas");
return !!(el.getContext && el.getContext("2d"));
})();
this.buildComparisonTable = function(values, comparator) {
var $el, $headRow, $table, $tr, comp, comps, evalStr, td, tf, v, valX, valY, x, y, _i, _j, _k, _len, _len1, _len2, _ref;
comps = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = values.length; _i < _len; _i++) {
v = values[_i];
_results.push(new ForComparison(v));
}
return _results;
})();
$table = $("<table>", {
"class": "comparisons"
});
$headRow = $("<tr>").append("<td>").appendTo($table);
for (_i = 0, _len = comps.length; _i < _len; _i++) {
comp = comps[_i];
$el = supportsCanvas ? rotateText(comp.asString) : $("<span>", {
"class": "rotate",
text: comp.asString
});
$("<td>", {
"class": "header col"
}).html($el).appendTo($headRow);
}
for (x = _j = 0, _len1 = comps.length; _j < _len1; x = ++_j) {
valX = comps[x];
$tr = $("<tr>").appendTo($table);
$("<td>", {
"class": "row header"
}).text(valX.asString).appendTo($tr);
for (y = _k = 0, _len2 = comps.length; _k < _len2; y = ++_k) {
valY = comps[y];
td = $("<td>", {
"class": "cell",
html: "<div>&nbsp;</div>"
}).appendTo($tr);
_ref = valX.testResults(valY, comparator), evalStr = _ref[0], tf = _ref[1];
td.attr("title", "" + evalStr + " // " + tf);
if (tf) {
td.addClass("equal");
}
}
}
return $table;
};
this.buildComparisonTableForIf = function(values) {
var $table, $td, $tr, comp, comps, expression, v, val, _i, _len;
comps = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = values.length; _i < _len; _i++) {
v = values[_i];
_results.push(new ForComparison(v));
}
return _results;
})();
$table = $("<table>", {
"class": "comparisons"
});
for (_i = 0, _len = comps.length; _i < _len; _i++) {
comp = comps[_i];
$tr = $("<tr>").html($("<td>", {
"class": "header row",
text: comp.asString
})).appendTo($table);
$td = $("<td>", {
"class": "cell"
}).html($("<div>", {
html: "&nbsp;"
})).appendTo($tr);
val = (new Function("if(" + comp.asString + "){return true}else{return false}"))();
if (val) {
$td.addClass("equal");
}
expression = " if (" + comp.asString + ") { /* " + (val ? 'executes' : 'does not execute') + " */ } ";
$("<td>", {
"class": "expression"
}).html(expression).appendTo($tr);
}
return $table;
};
rotateText = function(txt, cHeight) {
var c, canv;
if (cHeight == null) {
cHeight = 80;
}
canv = document.createElement("canvas");
canv.width = "25";
canv.height = cHeight;
c = canv.getContext("2d");
c.rotate(Math.PI / 2);
c.font = "15px Monospace";
c.textAlign = "right";
c.fillText(txt, cHeight, -10);
return canv;
};
}).call(this);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.