npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rdfjs/serializer-rdfjs

v0.1.3

Published

RDF/JS JavaScript code serializer that implements the RDF/JS Sink interface

Downloads

246

Readme

@rdfjs/serializer-rdfjs

build status

npm version

RDF/JS JavaScript code serializer that implements the RDF/JS Sink interface. It serializes the given quads to a JavaScript module that exports a single function, like shown below. The created function will return an array of the re-created quads.

export default ({ factory }) => {
  return [
    factory.quad(
      factory.blankNode('foo'),
      factory.namedNode('http://example.com/bar'),
      factory.literal('baz')
    )
  ]
}

Usage

The package exports the serializer as a class, so an instance must be created before it can be used. The .import method, as defined in the RDF/JS specification, must be called to do the actual serialization. It expects a quad stream as argument. The method will return a stream that emits the JavaScript code as a string.

Example

This example shows how to create a serializer instance and how to feed it with a stream of quads. The code emitted by the serializer will be written to stdout.

import { Readable } from 'stream'
import rdf from '@rdfjs/data-model'
import Serializer from '@rdfjs/serializer-rdfjs'


const serializer = new Serializer()
const input = new Readable({
  objectMode: true,
  read: () => {
    input.push(rdf.quad(
      rdf.namedNode('http://example.org/sheldon-cooper'),
      rdf.namedNode('http://schema.org/givenName'),
      rdf.literal('Sheldon')))
    input.push(rdf.quad(
      rdf.namedNode('http://example.org/sheldon-cooper'),
      rdf.namedNode('http://schema.org/familyName'),
      rdf.literal('Cooper')))
    input.push(rdf.quad(
      rdf.namedNode('http://example.org/sheldon-cooper'),
      rdf.namedNode('http://schema.org/knows'),
      rdf.namedNode('http://example.org/amy-farrah-fowler')))
    input.push(null)
  }
})

const output = serializer.import(input)
output.pipe(process.stdout)

Target module type

By default, the serializer will produce an ECMAScript module. The optional argument module can be used to serialize it to CommonJS or TypeScript.

Example

import Serializer from '@rdfjs/serializer-rdfjs'
import quadStream from './quads'

// serialize to CommonJS by default
const serializer = new Serializer({
  module: 'commonjs'
})

// call to .import also accepts same options parameter
const typescriptStream = serializer.import(quadStream, {
  module: 'ts'
})

transform(quads)

The actual serializer code runs sync, and the RDF/JS Sink interface is just a wrapper. If your use case is very specific, with a low chance to use other formats, it can be used directly. The .transform method accepts quads provided as an object that implements the Symbol.iterator method. It returns the generated JavaScript code as a string.

Example

This example shows how to create a serializer instance and how to feed it with quads. The returned code will be written to the console.

import rdf from '@rdfjs/data-model'
import Serializer from '@rdfjs/serializer-rdfjs'

const serializer = new Serializer()
const code = serializer.transform([
  rdf.quad(
    rdf.namedNode('http://example.org/sheldon-cooper'),
    rdf.namedNode('http://schema.org/givenName'),
    rdf.literal('Sheldon')),
  rdf.quad(
    rdf.namedNode('http://example.org/sheldon-cooper'),
    rdf.namedNode('http://schema.org/familyName'),
    rdf.literal('Cooper')),
  rdf.quad(
    rdf.namedNode('http://example.org/sheldon-cooper'),
    rdf.namedNode('http://schema.org/knows'),
    rdf.namedNode('http://example.org/amy-farrah-fowler'))
])

console.log(code)