annotate src/graph_queries.ts @ 78:ea9c9db282d6

automate 'external' list, get all local code to appear in lib.bundle.js
author drewp@bigasterisk.com
date Tue, 11 Feb 2020 22:55:24 -0800
parents 601a604c097a
children 0c188ed3bcd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
1 import { N3Store, NamedNode } from "n3";
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
2
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
3 export function getStringValue(
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
4 store: N3Store | undefined,
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
5 subj: NamedNode,
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
6 pred: NamedNode,
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
7 defaultValue: string = ""
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
8 ): string {
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
9 if (store === undefined) {
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
10 // this is so you can use the function before you have a graph
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
11 return "...";
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
12 }
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
13 const objs = store.getObjects(subj, pred, null);
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
14 if (objs.length == 0) {
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
15 return defaultValue;
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
16 }
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
17 return objs[0].value;
601a604c097a new module with getStringValue
drewp@bigasterisk.com
parents:
diff changeset
18 }