This repository has been archived by the owner on May 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (55 loc) · 1.69 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
module.exports = fs = require('fs')
module.exports = path = require('path')
module.exports = os = require('os')
// path.join() shorthand
module.exports = join = path.join
module.exports = parse = path.parse
module.exports = normalize = path.normalize
module.exports = relative_path = path.relative
module.exports = separator = path.sep
// JSON
module.exports = jparse = JSON.parse
module.exports = jstringify = JSON.stringify
// Various console commands
module.exports = log = console.log
module.exports = warn = console.warn
module.exports = err = console.error
// FS read & write | Async
module.exports = write = fs.writeFile
module.exports = writeSync = fs.writeFileSync
// FS read & write | Sync
module.exports = read = fs.readFile
module.exports = readSync = fs.readFileSync
// System Infos
module.exports = home = os.homedir()
module.exports = user = home.split('/')[home.split('/').length - 1]
// Capitalize
module.exports = String.prototype.capitalize = function(divider = ' ', joiner = divider) {
var cap_str = [];
this.toLowerCase().split(divider).forEach( item => {
item = item.charAt(0).toUpperCase() + item.slice(1, item.length)
cap_str.push(item)
})
return cap_str.join(joiner)
}
// relative path
module.exports = String.prototype.relativeTo = function(path) {
return relative_path(this.toString(), path)
}
// Sum all array items (Must be number)
module.exports = Array.prototype.sum = function() {
let counter = [];
this.forEach((item) => {
if (typeof item != 'number') {
item = 0;
counter.push(item)
} else {
item = Number(item);
counter.push(item)
}
});
return counter.reduce((a, b) => {
return a + b;
}, 0);
}