-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
46 lines (36 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import blankNode from './lib/blankNode.js'
import dataset from './lib/dataset.js'
import defaultGraph from './lib/defaultGraph.js'
import literal from './lib/literal.js'
import namedNode from './lib/namedNode.js'
import quad from './lib/quad.js'
import variable from './lib/variable.js'
function toNT (term, { nested } = {}) {
if (!term) {
return null
}
if (term.termType === 'BlankNode') {
return blankNode(term)
}
if (term.termType === 'DefaultGraph') {
return defaultGraph()
}
if (term.termType === 'Literal') {
return literal(term)
}
if (term.termType === 'NamedNode') {
return namedNode(term)
}
// legacy quad support without .termType
if (term.termType === 'Quad' || (term.subject && term.predicate && term.object && term.graph)) {
return quad(term, { nested, toNT })
}
if (term.termType === 'Variable') {
return variable(term)
}
if (term[Symbol.iterator]) {
return dataset(term, toNT)
}
throw new Error(`unknown termType ${term.termType}`)
}
export default toNT