-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjsonstat2arrobj
executable file
·67 lines (62 loc) · 2.05 KB
/
jsonstat2arrobj
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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-arrobj.json", "converts JSON-stat file oecd.json into a new file (oecd-arrobj.json) containing an array of objects.")
.example("$0 < oecd.json > oecd-arrobj.json -t", "converts JSON-stat stream oecd.json into a new stream (oecd-arrobj.json) containing an array of objects.")
.boolean("s")
.alias("s", "status")
.describe("s", "Include status information")
.boolean("c")
.alias("c", "cid")
.describe("c", "Identify categories by ID instead of label")
.boolean("u")
.alias("u", "unit")
.describe("u", "Include unit information when available")
.boolean("m")
.alias("m", "meta")
.describe("m", "Use the metadata enriched output (object of objects)")
.alias("b", "by")
.describe("b", "Transpose by the specified dimension")
.boolean("l")
.alias("l", "bylabel")
.describe("l", "Use labels instead of IDs to identify categories of the transposed dimension")
.alias("p", "prefix")
.describe("p", "Prefix to be used when data is transposed")
.alias("d", "drop")
.describe("d", "Comma-separated single category dimensions to be dropped when data is transposed")
.boolean("k")
.alias("k", "comma")
.describe("k", "Represent values as strings with comma as the decimal mark")
.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: "arrobj",
status: argv.status,
content: argv.cid ? "id": "label",
unit: argv.unit,
meta: argv.meta,
by: argv.by,
bylabel: argv.bylabel,
prefix: argv.prefix,
drop: (typeof argv.drop==="undefined") ? [] : argv.drop.split(","),
comma: argv.comma
})
;
if(tbl===null){
console.error("Error: The input does not containt valid JSON-stat.");
process.exit(1);
}
return tbl;
}
;
inout.main(argv, callback);