-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsonstat2object
executable file
·52 lines (47 loc) · 1.47 KB
/
jsonstat2object
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
#!/usr/bin/env node
var
argv=require("yargs")
.version()
.usage("Usage:\n $0 [input filename] [output filename]\n $0 < [input] > [output] -t")
.example("$0 oecd.json oecd-object.json", "converts JSON-stat file oecd.json into a new file (oecd-object.json) containing an object.")
.example("$0 < oecd.json > oecd-object.json -t", "converts JSON-stat stream oecd.json into a new stream (oecd-object.json) containing an object.")
.boolean("s")
.alias("s", "status")
.describe("s", "Include status information")
.alias("v", "vlabel")
.describe("v", "Label of the value field (default is 'Value')")
.alias("l", "slabel")
.describe("l", "Label of the status field (default is 'Status')")
.boolean("f")
.alias("f", "fid")
.describe("f", "Identify dimensions, value and status by ID instead of label")
.boolean("c")
.alias("c", "cid")
.describe("c", "Identify categories by ID instead of label")
.boolean("t")
.alias("t", "stream")
.describe("t", "Enable the stream interface")
.help("h")
.alias("h", "help")
.argv
,
inout=require("./inout"),
callback=function(contents){
var
tbl=inout.dataset(contents).toTable({
type: "object",
vlabel: argv.vlabel,
slabel: argv.slabel,
status: argv.status,
content: argv.cid ? "id": "label",
field: argv.fid ? "id": "label"
})
;
if(tbl===null){
console.error("Error: The input does not containt valid JSON-stat.");
process.exit(1);
}
return tbl;
}
;
inout.main(argv, callback);