-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpp.js
53 lines (44 loc) · 1.13 KB
/
pp.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
//--------------------------------------------------------------------------------
// pretty print
//--------------------------------------------------------------------------------
const os = require("os");
function ppNow() {
return "[" + new Date().toLocaleTimeString().padStart(11) + "]";
}
function ppPath(pth) {
return pth.replace(os.homedir(), "~");
}
// pp number with 2 decimals
function pp2Dec(num) {
return (Math.round(num * 100) / 100).toFixed(2);
}
// pp right ascension: 21h36m14.42s
function ppRa([hours, mins, secs]) {
return `${Math.round(hours)}h${Math.round(mins)}m${pp2Dec(secs)}s`;
}
// pp declination: 57°34'28.16"
function ppDec([degs, mins, secs]) {
return `${Math.round(degs)}°${Math.round(mins)}'${pp2Dec(secs)}"`;
}
// pp degrees: 57.57°
function ppDeg(degs) {
return `${pp2Dec(degs)}°`;
}
// pp radians: 0.69rad
function ppRad(degs) {
return `${pp2Dec(degs)}rad`;
}
// pp J2000: [0.50, 0.76, 0.41][j2000]
function ppJ2000([x, y, z]) {
return `[j2000 | x:${pp2Dec(x)}, y:${pp2Dec(y)}, z:${pp2Dec(z)}]`;
}
module.exports = {
ppNow,
ppPath,
pp2Dec,
ppRa,
ppDec,
ppDeg,
ppRad,
ppJ2000,
};