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-elements/formats-pretty

v0.6.7

Published

RDF/JS Sink Maps with serializers configured for pretty printing

Downloads

5,230

Readme

@rdfjs-elements/formats-pretty

Common RDF/JS parsers and serializers, the latter returning a nicely formatted output.

For basic usage see @rdfjs/formats-common

Serializers

| Format | Pretty or not | Implementation | | -- | -- | -- | | application/ld+json | 😀 | @rdfjs/serializer-jsonld-ext | | application/trig | 🤩 | @graphy/content.trig.writer | | text/n3 | 🤩 | @graphy/content.ttl.writer | | text/turtle | 🤩 | @graphy/content.ttl.writer | | application/n-triples | 😶 | @rdfjs/serializer-ntriples | | application/n-quads | 😶 | @rdfjs/serializer-ntriples | | application/rdf+xml | 😶 | @graphy/content.xml.scribe |

Individual serializer skins can also be created by importing from @rdfjs-elements/formats-pretty/serializers. This allows for initializing a sink preloaded with a given set of prefixes.

import prefixes from '@zazuko/prefixes'
import { TurtleSerializer } from '@rdfjs-elements/formats-pretty'

const { schema, dcterms, foaf } = prefixes

const sink = new TurtleSerializer({
  prefixes: { schema, dcterms, foaf, ex: 'http://example/org/' }
})

This sink can then be used to produce pretty-printed RDF

import rdf from '@rdfjs/data-model'
import { Readable } from 'readable-stream'
import getStream from 'get-stream'

// Example data
const data = [
  rdf.quad(rdf.namedNode('http://example/org/s1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Alice')),
  rdf.quad(rdf.namedNode('http://example/org/s1'), rdf.namedNode('http://xmlns.com/foaf/0.1/knows'), rdf.namedNode('http://example/org/o1')),
  rdf.quad(rdf.namedNode('http://example/org/o1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Bob'))
]

const stream = await sink.import(Readable.from(data))
console.log(await getStream(stream))

// Outputs:

// @prefix schema: <http://schema.org/> .
// @prefix dcterms: <http://purl.org/dc/terms/> .
// @prefix foaf: <http://xmlns.com/foaf/0.1/> .
// @prefix ex: <http://example/org/> .
//
//   ex:s1 schema:name "Alice" ;
//        foaf:knows ex:o1 .
//
//   ex:o1 schema:name "Bob" .

To get an output in n-triples, n-quads or n3 format the sink map interface can be used where media type must be specified:

import rdf from '@rdfjs/data-model'
import prefixes from '@zazuko/prefixes'
import formats from '@rdfjs-elements/formats-pretty'
import { Readable } from 'readable-stream'
import getStream from 'get-stream'

// Example data
const data = [
  rdf.quad(rdf.namedNode('http://example/org/s1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Alice')),
  rdf.quad(rdf.namedNode('http://example/org/s1'), rdf.namedNode('http://xmlns.com/foaf/0.1/knows'), rdf.namedNode('http://example/org/o1')),
  rdf.quad(rdf.namedNode('http://example/org/o1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Bob'))
]

const { schema, dcterms, foaf } = prefixes

const stream = formats.serialisers.import('application/n-triples', Readable.from(data), { schema, dcterms, foaf, ex:'http://example/org/' })

console.log(await getStream(stream))

Parsers

| Format | Implementation | | -- | -- | | application/ld+json | @rdfjs/parser-jsonld | | application/trig | @rdfjs/parser-n3 | | text/n3 | @rdfjs/parser-n3 | | text/turtle | @rdfjs/parser-n3 | | application/n-triples | @rdfjs/parser-n3 | | application/n-quads | @rdfjs/parser-n3 | | application/rdf+xml | rdfxml-streaming-parser |