forked from bokeh/bokeh
-
Notifications
You must be signed in to change notification settings - Fork 11
/
util.js
52 lines (46 loc) · 1.25 KB
/
util.js
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
(function() {
var repeat, specialCharacters;
exports.repeat = repeat = function(string, count) {
return Array(count + 1).join(string);
};
exports.indent = function(string, width) {
var line, lines, space;
space = repeat(" ", width);
lines = (function() {
var _i, _len, _ref, _results;
_ref = string.split("\n");
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
_results.push(space + line);
}
return _results;
})();
return lines.join("\n");
};
exports.trim = function(string) {
return string.replace(/^\s+/, "").replace(/\s+$/, "");
};
specialCharacters = {
'\\': '\\\\',
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t'
};
exports.inspectString = function(string) {
var contents;
contents = string.replace(/[\x00-\x1f\\]/g, function(character) {
var code;
if (character in specialCharacters) {
return specialCharacters[character];
} else {
code = character.charCodeAt(0).toString(16);
if (code.length === 1) code = "0" + code;
return "\\u00" + code;
}
});
return "'" + contents.replace(/'/g, '\\\'') + "'";
};
}).call(this);