comparison src/graph_queries.ts @ 53:601a604c097a

new module with getStringValue
author drewp@bigasterisk.com
date Mon, 13 Jan 2020 00:06:36 -0800
parents
children 0c188ed3bcd8
comparison
equal deleted inserted replaced
52:490f569bb0c9 53:601a604c097a
1 import { N3Store, NamedNode } from "n3";
2
3 export function getStringValue(
4 store: N3Store | undefined,
5 subj: NamedNode,
6 pred: NamedNode,
7 defaultValue: string = ""
8 ): string {
9 if (store === undefined) {
10 // this is so you can use the function before you have a graph
11 return "...";
12 }
13 const objs = store.getObjects(subj, pred, null);
14 if (objs.length == 0) {
15 return defaultValue;
16 }
17 return objs[0].value;
18 }