-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathn3.ts
More file actions
21 lines (20 loc) · 710 Bytes
/
n3.ts
File metadata and controls
21 lines (20 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import NamedNode = require("@rdfjs/data-model/lib/named-node");
import BlankNode = require("@rdfjs/data-model/lib/blank-node");
import Literal = require("@rdfjs/data-model/lib/literal");
export function serializeTerm(term: NamedNode | BlankNode | Literal): string {
if (term instanceof NamedNode) {
return `<${term.value}>`;
} else if (term instanceof BlankNode) {
return `_:${term.value}`;
} else if (term instanceof Literal) {
if (term.language) {
return `"${term.value}"`;
} else if (term.datatype) {
return `"${term.value}"^^${term.datatype}`;
} else {
return `"${term.value}"`;
}
} else {
throw new Error(`Term ${term} is of unexpected type`);
}
}