I'm trying to convert a TSV file into JSON and write it to disk using text2json
.
Input data
There is an empty line at the end
U+2B695 shī
U+2B699 pū
U+2B6DB zhī
U+2B6DE jué
U+2B6E2 níng
U+2B6F6 chì
U+2B6F8 tí
Test
I've this test running with ava
import fs from "fs";
import test from "ava";
import jsonfile from "jsonfile";
import dataminer from "../src/dataminer";
test("extractPronunciation()", t => {
const filepath = "src/codepoint-ruby.tsv";
const data = dataminer.convertToJson(filepath, { separator: " " });
t.is(data > 0);
});
Code
And this method based on text2json:
import jsonfile from "jsonfile";
import text2json from "text2json";
export default {
convertToJson: (filepath, options) => {
const data = [];
const parse = new text2json.Parser({ ...options, hasHeader: true });
parse
.text2json(filepath)
.on("row", row => {
data.push(row);
})
.on("end", () => {
console.log("Done >>>>>");
return data;
});
},
};
Question
I see not trace of the end
event being triggered, and the convertToJson()
return nothing so my test fail, am I missing something?