102
|
1 import { Store, Parser, Quad, Prefixes } from "n3";
|
|
2
|
|
3 export async function fetchAndParse(
|
|
4 url: string,
|
|
5 store?: Store
|
|
6 ): Promise<Store> {
|
|
7 const res = await fetch(url);
|
|
8 const body = await res.text();
|
|
9 return n3Graph(body, store);
|
|
10 }
|
95
|
11
|
102
|
12 export async function n3Graph(n3: string, store?: Store): Promise<Store> {
|
|
13 if (store === undefined) {
|
|
14 store = new Store();
|
|
15 }
|
|
16
|
|
17 const parser = new Parser({ format: "N3" });
|
|
18 return new Promise((res, rej) => {
|
|
19 parser.parse(n3, (error, quad: Quad, prefixes: Prefixes) => {
|
|
20 if (quad) {
|
|
21 store!.addQuad(quad);
|
|
22 } else {
|
|
23 res(store!);
|
|
24 }
|
95
|
25 });
|
102
|
26 });
|
95
|
27 }
|