Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80758 views
1
// Generated by CoffeeScript 1.9.1
2
var extend, flatten, last, ref, ref1, repeat, syntaxErrorToString;
3
4
exports.starts = function(string, literal, start) {
5
return literal === string.substr(start, literal.length);
6
};
7
8
exports.ends = function(string, literal, back) {
9
var len;
10
len = literal.length;
11
return literal === string.substr(string.length - len - (back || 0), len);
12
};
13
14
exports.repeat = repeat = function(str, n) {
15
var res;
16
res = '';
17
while (n > 0) {
18
if (n & 1) {
19
res += str;
20
}
21
n >>>= 1;
22
str += str;
23
}
24
return res;
25
};
26
27
exports.compact = function(array) {
28
var i, item, len1, results;
29
results = [];
30
for (i = 0, len1 = array.length; i < len1; i++) {
31
item = array[i];
32
if (item) {
33
results.push(item);
34
}
35
}
36
return results;
37
};
38
39
exports.count = function(string, substr) {
40
var num, pos;
41
num = pos = 0;
42
if (!substr.length) {
43
return 1 / 0;
44
}
45
while (pos = 1 + string.indexOf(substr, pos)) {
46
num++;
47
}
48
return num;
49
};
50
51
exports.merge = function(options, overrides) {
52
return extend(extend({}, options), overrides);
53
};
54
55
extend = exports.extend = function(object, properties) {
56
var key, val;
57
for (key in properties) {
58
val = properties[key];
59
object[key] = val;
60
}
61
return object;
62
};
63
64
exports.flatten = flatten = function(array) {
65
var element, flattened, i, len1;
66
flattened = [];
67
for (i = 0, len1 = array.length; i < len1; i++) {
68
element = array[i];
69
if (element instanceof Array) {
70
flattened = flattened.concat(flatten(element));
71
} else {
72
flattened.push(element);
73
}
74
}
75
return flattened;
76
};
77
78
exports.del = function(obj, key) {
79
var val;
80
val = obj[key];
81
delete obj[key];
82
return val;
83
};
84
85
exports.last = last = function(array, back) {
86
return array[array.length - (back || 0) - 1];
87
};
88
89
exports.some = (ref = Array.prototype.some) != null ? ref : function(fn) {
90
var e, i, len1;
91
for (i = 0, len1 = this.length; i < len1; i++) {
92
e = this[i];
93
if (fn(e)) {
94
return true;
95
}
96
}
97
return false;
98
};
99
100
exports.find = (ref1 = Array.prototype.find) != null ? ref1 : function(fn) {
101
var e, i, len1;
102
for (i = 0, len1 = this.length; i < len1; i++) {
103
e = this[i];
104
if (fn(e)) {
105
return e;
106
}
107
}
108
};
109
110
exports.throwSyntaxError = function(message, location) {
111
var error;
112
error = new SyntaxError(message);
113
error.location = location;
114
error.toString = syntaxErrorToString;
115
error.stack = error.toString();
116
throw error;
117
};
118
119
exports.updateSyntaxError = function(error, code, filename) {
120
if (error.toString === syntaxErrorToString) {
121
error.code || (error.code = code);
122
error.filename || (error.filename = filename);
123
error.stack = error.toString();
124
}
125
return error;
126
};
127
128
syntaxErrorToString = function() {
129
var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, ref2, ref3, start;
130
if (!(this.code && this.location)) {
131
return Error.prototype.toString.call(this);
132
}
133
ref2 = this.location, first_line = ref2.first_line, first_column = ref2.first_column, last_line = ref2.last_line, last_column = ref2.last_column;
134
if (last_line == null) {
135
last_line = first_line;
136
}
137
if (last_column == null) {
138
last_column = first_column;
139
}
140
filename = this.filename || '[stdin]';
141
codeLine = this.code.split('\n')[first_line];
142
start = first_column;
143
end = first_line === last_line ? last_column + 1 : codeLine.length;
144
marker = repeat(' ', start) + repeat('^', end - start);
145
if (typeof process !== "undefined" && process !== null) {
146
colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
147
}
148
if ((ref3 = this.colorful) != null ? ref3 : colorsEnabled) {
149
colorize = function(str) {
150
return "\x1B[1;31m" + str + "\x1B[0m";
151
};
152
codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
153
marker = colorize(marker);
154
}
155
return filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
156
};
157
158
exports.nameWhitespaceCharacter = function(string) {
159
switch (string) {
160
case ' ':
161
return 'space';
162
case '\n':
163
return 'newline';
164
case '\r':
165
return 'carriage return';
166
case '\t':
167
return 'tab';
168
default:
169
return string;
170
}
171
};
172
173
exports.invertLiterate = function(code) {
174
var line, lines, maybe_code;
175
maybe_code = true;
176
lines = (function() {
177
var i, len1, ref2, results;
178
ref2 = code.split('\n');
179
results = [];
180
for (i = 0, len1 = ref2.length; i < len1; i++) {
181
line = ref2[i];
182
if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {
183
results.push(line);
184
} else if (maybe_code = /^\s*$/.test(line)) {
185
results.push(line);
186
} else {
187
results.push('# ' + line);
188
}
189
}
190
return results;
191
})();
192
return lines.join('\n');
193
};
194
195