Socket
Socket
Sign inDemoInstall

@rdfjs/formats

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rdfjs/formats

Bundle of RDF/JS parsers and serializers


Version published
Weekly downloads
8.1K
decreased by-0.69%
Maintainers
1
Weekly downloads
 
Created
Source

@rdfjs/formats

build status npm version

This module bundles parsers and serializers for the most common RDF formats. Instances of SinkMap are used to handle different media types.

Usage

The formats object has a parsers and serializers property. Each is an instance of SinkMap with the most common RDF media types as key. The formats object is exported as default and can be imported like this:

import formats from '@rdfjs/formats'

Pretty-Print Serializers

The default bundle of serializers is optimized for streaming. The pretty-print formats bundle can be used if a more human-readable output is required. It can be imported like this:

Factory

A factory that takes care of parsers and serializers. An additional .formats object will be attached to the environment. That object is compatible with the data structure of @rdfjs/formats-common. The .formats object has an additional .import() function to import other format bundles. The following code shows how to import the @rdfjs/formats-common bundle:

import formats from '@rdfjs/formats/pretty.js'

Example

The following example uses the parser for the media type text/turtle to parse the given string. The quads emitted by the data event are written to the console:

import formats from '@rdfjs/formats'
import { Readable } from 'readable-stream'

const input = Readable.from([`
  PREFIX s: <http://schema.org/>

  [] a s:Person;
    s:jobTitle "Professor";
    s:name "Jane Doe";
    s:telephone "(425) 123-4567";
    s:url <http://www.janedoe.com>.
`])

const output = formats.parsers.import('text/turtle', input)

output.on('data', quad => {
  console.log(`quad: ${quad.subject.value} - ${quad.predicate.value} - ${quad.object.value}`)
})

output.on('prefix', (prefix, ns) => {
  console.log(`prefix: ${prefix} ${ns.value}`)
})

Keywords

FAQs

Package last updated on 18 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc