All files parseRdf.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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      2x 2x     2x       17x 19x   15x         3x   1x   1x                  
import { Dataset } from "@rdfjs/types";
import { JsonLdDocument } from "jsonld";
import { ParserOptions } from "n3";
import { createDatasetFromSerializedInput } from "o-dataset-pack";
import { createLdoDataset, createLdoDatasetFactory } from "./createLdoDataset";
import { LdoDataset } from "./LdoDataset";
 
export async function parseRdf(
  data: string | JsonLdDocument | Dataset,
  parserOptions?: ParserOptions
): Promise<LdoDataset> {
  const ldoDatasetFactory = createLdoDatasetFactory();
  if (typeof data === "string") {
    // Input data is serialized
    return await createDatasetFromSerializedInput(
      ldoDatasetFactory,
      data,
      parserOptions
    );
  } else if (typeof (data as Dataset).add === "function") {
    // Input data is a dataset
    return createLdoDataset(data as Dataset);
  } else {
    return await createDatasetFromSerializedInput(
      ldoDatasetFactory,
      JSON.stringify(data),
      {
        format: "application/json-ld",
      }
    );
  }
}