forked from web3space/web3t
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig-parser.ls
More file actions
29 lines (29 loc) · 920 Bytes
/
config-parser.ls
File metadata and controls
29 lines (29 loc) · 920 Bytes
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
require! {
\prelude-ls : { map, pairs-to-obj, split, tail }
}
get-mode = (config)->
return config.split(\,).0 if typeof! config is \String
return get-mode config.mode if typeof! config is \Object
\testnet
parse-mapping-string = (config)->
all = config.split(\,).map(-> it.trim!)
return {} if not all.length is 1
all
|> tail
|> map split ' for '
|> map -> [it.1, it.0]
|> pairs-to-obj
parse-mapping-object = (config)->
mapping = parse-mapping-string config.mode
mapping <<<< config.network-mapping ? {}
mapping
get-mapping = (config)->
return parse-mapping-string config if typeof! config is \String
return parse-mapping-object config if typeof! config is \Object
{}
module.exports = (config)->
mode = get-mode config
mapping = get-mapping config
get-mode-for = (symbol)->
mapping[symbol] ? mode
{ get-mode-for }