@rdfjs/to-ntriples
v3.0.1
Published
Converts RDF/JS Terms, Quads and Datasets to N-Triple strings
Downloads
254,462
Readme
@rdfjs/to-ntriples
Converts RDF/JS Terms, Quads and Datasets to N-Triple strings.
Examples
import rdf from '@rdfjs/data-model'
import toNT from '@rdfjs/to-ntriples'
// convert a Term/Literal to a N-Triple string (output: "example"@en)
console.log(toNT(rdf.literal('example', 'en')))
// convert a Quad to a N-Triple string (output: _:b1 <http://example.org/predicate> "example" .)
console.log(toNT(rdf.quad(
rdf.blankNode(),
rdf.namedNode('http://example.org/predicate'),
rdf.literal('example')
)))
/*
convert an Array/Dataset to a N-Triple string
output:
_:b2 <http://example.org/predicate> "1" .
_:b3 <http://example.org/predicate> "2" .
Any object with Symbol.iterator is supported
*/
console.log(toNT([
rdf.quad(
rdf.blankNode(),
rdf.namedNode('http://example.org/predicate'),
rdf.literal('1')
),
rdf.quad(
rdf.blankNode(),
rdf.namedNode('http://example.org/predicate'),
rdf.literal('2')
)
]))