29 lines
430 B
JavaScript
29 lines
430 B
JavaScript
'use strict';
|
|
|
|
var Parser = require('./Parser.js');
|
|
|
|
function parse(data, options) {
|
|
const p = typeof options === "function" ? new options() : new Parser(options);
|
|
|
|
let result = null;
|
|
let error = null;
|
|
|
|
p.on("tree", (tree) => {
|
|
result = tree;
|
|
});
|
|
p.on("error", (e) => {
|
|
error = e;
|
|
});
|
|
|
|
p.write(data);
|
|
p.end();
|
|
|
|
if (error) {
|
|
throw error;
|
|
} else {
|
|
return result;
|
|
}
|
|
}
|
|
|
|
module.exports = parse;
|