UNPKG

sssom-js

Version:

Simple Standard for Sharing Ontology Mappings (SSOM) JavaScript library

32 lines (27 loc) 894 B
import fs from "fs" import { parseTSV } from "./parsetsv.js" import { parseJSON } from "./parsejson.js" export const inputFormats = ["csv","tsv","json"] export const parseSSSOM = async (input, options = {}) => { // get or guess input format let from = options.from if (!from) { if (typeof input === "string" && input.split(".").length > 1) { from = input.split(".").pop() } from ||= "tsv" } if (options.curie && typeof options.curie === "string") { // TODO: make sure its a JSON object of strings options.curie = JSON.parse(fs.readFileSync(options.curie)) } if (from === "tsv") { return parseTSV(input, options) } else if (from === "csv") { return parseTSV(input, { ...options, delimiter: "," }) } else if (from === "json") { return parseJSON(input, options) } else { throw new Error(`Unsupported input format ${from}`) } }