-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.js
executable file
·36 lines (33 loc) · 902 Bytes
/
utils.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
export const relativeDate = (date) => {
if (typeof date !== "object") {
date = parseInt(date) * 1000
date = new Date(date)
}
const diff = new Date() - date
const day = 1000 * 60 * 60 * 24
const hour = 1000 * 60 * 60
const minute = 1000 * 60
if (diff / day > 1) {
return `${Math.floor(diff / day)} days ago`
}
if (diff / hour > 1) {
return `${Math.floor(diff / hour)} hours ago`
}
if (diff / minute > 1) {
return `${Math.floor(diff / minute)} minutes ago`
}
return "just now"
}
export const escapeShell = (cmd) => {
return cmd.replace(/(["'$`\\])/g, "\\$1")
}
export const concatPath = (path1, path2) => {
let newPath = path1.replace(/\/$/, "") + "/" + path2.replace(/^\//, "")
return compatiblePath(newPath)
}
export const compatiblePath = (path) => {
if (process.platform === "win32") {
return path.replace(/\//g, "\\")
}
return path
}