Skip to content

Latest commit

 

History

History
43 lines (36 loc) · 1.28 KB

README.md

File metadata and controls

43 lines (36 loc) · 1.28 KB

@rdfjs/to-ntriples

build status npm version

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')
  )
]))