forked from ajaxorg/ace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.js
More file actions
38 lines (29 loc) · 1.07 KB
/
lib.js
File metadata and controls
38 lines (29 loc) · 1.07 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
var plist = require("plist");
var util = require("util");
exports.parsePlist = function(themeXml, callback) {
var result = ""
plist.parseString(themeXml, function(_, theme) {
result = theme[0];
callback && callback(theme[0]);
});
return result;
}
exports.formatJSON = function(object, initialIndent) {
return util.inspect(object, false, 40).replace(/^/gm, initialIndent||"")
}
exports.fillTemplate = function(template, replacements) {
return template.replace(/%(.+?)%/g, function(str, m) {
return replacements[m] || "";
});
}
exports.hyphenate = function(str) {
return str.replace(/([A-Z])/g, "-$1").replace(/_/g, "-").toLowerCase();
}
exports.quoteString = function(str) {
return '"' + str.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"';
}
exports.restoreJSONComments = function(objStr) {
return objStr.replace(/^(\s*)comment: '(.*)'/gm, function(_, i, c) {
return i + "//" + c.replace(/\\n(\\t)*/g, "\n" + i + "//") + "\n" + i
}).replace(/ \/\/ ERROR/g, '", // ERROR');
}