Mercurial > code > home > repos > streamed-graph
view src/layout/fetchAndParse.ts @ 143:5adf79d4a9f4
release v0.11.0
author | drewp@bigasterisk.com |
---|---|
date | Mon, 08 May 2023 13:29:48 -0700 |
parents | 2468f2227d22 |
children |
line wrap: on
line source
import { Store, Parser, Quad, Prefixes } from "n3"; export async function fetchAndParse( url: string, store?: Store ): Promise<Store> { const res = await fetch(url); const body = await res.text(); return n3Graph(body, store); } export async function n3Graph(n3: string, store?: Store): Promise<Store> { if (store === undefined) { store = new Store(); } const parser = new Parser({ format: "TriG" }); await new Promise((res, rej) => { parser.parse(n3, (error, quad: Quad, prefixes: Prefixes) => { if (error) rej(error); if (quad) { store!.addQuad(quad); } else { res(undefined); } }); }); return store; }