forked from alainbryden/bitburner-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsGet.js
48 lines (40 loc) · 1.16 KB
/
lsGet.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
import { lsKeys } from './constants.js'
import { getLSItem, formatMoney, formatNumberShort, formatMilliseconds } from './helpers.js'
export function autocomplete(data) {
return Object.keys(lsKeys)
}
/**
* @param {NS} ns
**/
export async function main(ns) {
let args = ns.flags([
['pretty', false],
['p', false],
])
if ( args._.length === 0 ) {
ns.tprint(`This script needs a recognized key!`)
ns.tprint('like: `run lsGet.js reserve`')
return
}
let keys = args._.slice()
let key = keys.shift()
if ( !lsKeys[key.toUpperCase()] ) {
ns.tprint(`That is not a recognized key. Use one of: `)
ns.tprint(Object.keys(lsKeys).join(", "))
return
}
let value = getLSItem(key), nextKey
while ( keys.length > 0 ) {
key = keys.shift()
value = value[key]
}
if (key == 'reserve') value = formatMoney(value)
if (key.toLowerCase().includes('money') ) value = formatMoney(value)
if (key == 'working') value = formatMilliseconds(value)
if (typeof value == 'number') value = formatNumberShort(value, 6, 3)
if ( args.p || args.pretty ) {
ns.tprint(`\n\r${JSON.stringify(value, null, 2)}`)
} else {
ns.tprint(value)
}
}