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

@zazuko/formats-lazy

v1.0.1

Published

Parsers and serializers for common RDF formats, loaded lazily

Downloads

1,229

Readme

@zazuko/formats-lazy

GitHub Workflow Status npm

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

Every sink is loaded lazily when it is first used, making this package the best choice for web application. The laziness is transparent to the consuming code because streams are already lazy by definition.

Usage

Recommended usage

Install @rdfjs/environment and create an environment with the factories you need, including FormatsFactory. Then, import the lazy formats.

import Environment from '@rdfjs/environment/Environment.js'
import FormatsFactory from '@rdfjs/environment/Formats.js'
import lazyFormats from '@zazuko/formats-lazy'

export const $rdf = new Environment([FormatsFactory])

$rdf.formats.import(lazyFormats)

Simple usage

Use an existing environment, such as rdf-ext

import $rdf from 'rdf-ext'
import lazyFormats from '@zazuko/formats-lazy'

$rdf.formats.import(lazyFormats)

Direct usage

The formats object has a parsers and serializers property. Each of it is an instance of SinkMap with the most common RDF media types as key.

import formats from '@zazuko/formats-lazy'
import { Readable } from '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}`)
})

Making a sink lazy

Any parser or serializer can be wrapped to be lazy loaded.

Assuming you have a @example/bin-parser package which export a class BinaryParser

import formats from '@zazuko/formats-lazy'
import { lazySink } from '@zazuko/formats-lazy/LazySink.js'

export const LazyBinaryParser = lazySink(
  async () => (await import('@example/bin-parser')).BinaryParser
)

formats.parsers.set('application/octet-stream+rdf', new LazyBinaryParser())

The constructed class LazyBinaryParser can be used just like any other parser and acts as a wrapper to BinaryParser. In TypeScript, it will preserve the constructor and import signatures. If for any reason the real parser instance needs to be accessed, call async load() method.