forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
67 lines (54 loc) · 1.45 KB
/
utils.js
File metadata and controls
67 lines (54 loc) · 1.45 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
const promisify = require("promisify-node");
const fse = require("fs-extra");
const fs = require("fs");
const path = require("path");
// Make a locally bound path joiner, (bound to generate).
var local = path.join.bind(null, __dirname, "../");
var util = {
pointerRegex: /\s*\*\s*/,
doublePointerRegex: /\s*\*\*\s*/,
readFile: function(file) {
try {
return fs.readFileSync(local(file)).toString();
}
catch (unhandledException) {
return "";
}
},
writeFile: function(file, content) {
try {
var file = local(file);
if (typeof content == "object") {
content = JSON.stringify(content, null, 2)
}
fse.ensureFileSync(file);
fse.writeFileSync(file, content);
return true;
}
catch (exception) {
return false;
}
},
titleCase: function(str) {
return str.split(/_|\//).map(function(val, index) {
if (val.length) {
return val[0].toUpperCase() + val.slice(1);
}
return val;
}).join("");
},
camelCase: function(str) {
return str.split(/_|\//).map(function(val, index) {
return (index >= 1
? val[0].toUpperCase() + val.slice(1)
: val[0].toLowerCase() + val.slice(1));
}).join("");
},
isPointer: function(type) {
return util.pointerRegex.test(type) || util.doublePointerRegex.test(type);
},
isDoublePointer: function(type) {
return util.doublePointerRegex.test(type);
}
};
module.exports = util;