Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including rdf-translator with all npm packages installed. Try it out:

var rdfTranslator = require("rdf-translator")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

rdf-translator v2.0.0

Convert between rdf formats

rdf-translator Build Status

Convert between rdf formats

It is a javascript connector for the rdf-translator APIs using Promises.

Install

npm install --save rdf-translator

Usage

  • From a string.
var rdfTranslator = require('rdf-translator');
var str = `
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
           xmlns:foaf="http://xmlns.com/foaf/0.1/">
   <foaf:Person rdf:about="http://dbpedia.org/page/Spider-Man">
     <foaf:name>Peter Parker</foaf:name>
     <foaf:mbox rdf:resource="mailto:peter.parker@dailybugle.com"/>
   </foaf:Person>
  </rdf:RDF>
`

rdfTranslator(str, 'xml', 'n3')
  .then(data => {
    console.log(data);
    \\ <http://dbpedia.org/page/Spider-Man> <http://xmlns.com/foaf/0.1/name> "Peter Parker" .
    \\ <http://dbpedia.org/page/Spider-Man> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
    \\ <http://dbpedia.org/page/Spider-Man> <http://xmlns.com/foaf/0.1/mbox> <mailto:peter.parker@dailybugle.com> .
  }).catch(err => {
    console.error(err);
  });

In alternative, with traditional callbacks:

rdfTranslator(str, 'xml', 'n3', function(err, data) {
    if (err) return console.error(err);
    console.log(data);
});
  • From a URI
var rdfTranslator = require('rdf-translator');

let uri = 'https://raw.githubusercontent.com/DOREMUS-ANR/doremus-ontology/master/doremus.ttl';
rdfTranslator(uri, 'n3', 'json-ld')
  .then( data => {
    var json == JSON.parse(data);
    // your code here
  });

API

rdfTranslator(str, source, target, [callback])

str

Type: string

Input string (i.e. in xml-rdf or turtle format) -or- URI of the file to convert.

source

Type: string

Format of the input string.

target

Type: string

Format of the desired output string.

callback(err, data)

Type: function

Callback function.

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free