Skip to content

Instantly share code, notes, and snippets.

@abe33
Last active March 28, 2017 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abe33/e9d6e82488e18c30d233dc57048093f4 to your computer and use it in GitHub Desktop.
Save abe33/e9d6e82488e18c30d233dc57048093f4 to your computer and use it in GitHub Desktop.
const fs = require('fs');
module.exports = {
convertToJson: (filepath, options, callback) => {
callback && fs.readFile(filepath, (err, buf) => {
if (err) { callback(err) }
callback(null, String(buf).split("\n").map(line => {
const [glyph, ruby] = line.split(options.separator);
return { glyph, ruby };
}));
})
}
};
const fs = require('fs');
module.exports = {
convertToJson: (filepath, options) =>
String(fs.readFileSync(filepath)).split("\n").map(line => {
const [glyph, ruby] = line.split(options.separator);
return { glyph, ruby };
})
};
@edouard-lopez
Copy link

still get undefined result with the sync.

test("extractPronunciation()", t => {
  const filepath = "./src/codepoint-ruby.tsv";
  let data = [];
  data = dataminer.convertToJson(filepath, {
    headers: ["glyph", "ruby"],
    separator: "\t"
  });
  console.log(data);
});

@abe33
Copy link
Author

abe33 commented Mar 28, 2017

I think your issue might comes from something else, here's the output when running it into a console:

In that case p is an absolute path to the tsv file, not a relative one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment