-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
33 lines (29 loc) · 978 Bytes
/
index.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
require('dotenv').config();
const downloadDpbMd = require('./dbp-download-md/index.js');
const mdToNestedJson = require('./md-to-json/index.js');
const mdToJson = require('./md-to-json/linear.js');
// pass your access token
async function dbpMdToJson(options) {
try {
const mdData = await downloadDpbMd(options.accessToken, options.dbp_doc_id);
let nested;
// default for nested if undefined in options arguments to be true;
if (options.nested === undefined) {
nested = true;
} else {
nested = options.nested;
}
let jsonResult;
if (nested) {
// convert to nested json
jsonResult = mdToNestedJson(mdData);
} else {
// convert to linear json
jsonResult = mdToJson(mdData);
}
return Promise.resolve(jsonResult);
} catch (e) {
return Promise.reject(new Error(e));
}
}
module.exports = dbpMdToJson;