-
Notifications
You must be signed in to change notification settings - Fork 1
/
sdmx2jsonstat
50 lines (45 loc) · 1.29 KB
/
sdmx2jsonstat
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
#!/usr/bin/env node
var
utils=require("jsonstat-suite"),
argv=require("yargs")
.version()
.usage("Usage:\n $0 [input filename] [output filename]\n $0 < [input] > [output] -t")
.example("$0 sdmx.json jsonstat.json", "converts SDMX-JSON file sdmx.json into JSON-stat (jsonstat.json).")
.example("$0 < sdmx.json > jsonstat.json -t", "converts JSDMX-JSON stream sdmx.json into a JSON-stat stream (jsonstat.json).")
.boolean("o")
.alias("o", "ovalue")
.describe("o", "Type of value: object instead of array")
.boolean("s")
.alias("s", "ostatus")
.describe("s", "Type of status: object instead of array")
.boolean("t")
.alias("t", "stream")
.describe("t", "Enable the stream interface")
.help("h")
.alias("h", "help")
.argv
,
inout=require("./inout"),
callback=function(contents){
try{
var json=JSON.parse(contents);
}catch (e){
console.error("Error: The input does not containt JSON.");
process.exit(1);
}
var json=utils.fromSDMX(
json,
{
ovalue: argv.ovalue,
ostatus: argv.ostatus
}
);
if(json===null){
console.error("Error: Check your SDMX-JSON. Only flat SDMX-JSON with a single dataset is supported.");
process.exit(1);
}else{
return json;
}
}
;
inout.main(argv, callback);