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

microdata-rdf-streaming-parser

v2.0.1

Published

A fast and lightweight streaming Microdata to RDF parser

Downloads

36,044

Readme

Microdata to RDF Streaming Parser

Build status Coverage Status npm version

A fast and lightweight streaming and 100% spec-compliant Microdata to RDF parser, with RDFJS representations of RDF terms, quads and triples.

The streaming nature allows triples to be emitted as soon as possible, and documents larger than memory to be parsed.

Installation

$ npm install microdata-rdf-streaming-parser

or

$ yarn add microdata-rdf-streaming-parser

This package also works out-of-the-box in browsers via tools such as webpack and browserify.

Require

import {MicrodataRdfParser} from "microdata-rdf-streaming-parser";

or

const MicrodataRdfParser = require("microdata-rdf-streaming-parser").MicrodataRdfParser;

Usage

MicrodataRdfParser is a Node Transform stream that takes in chunks of Microdata to RDF data, and outputs RDFJS-compliant quads.

It can be used to pipe streams to, or you can write strings into the parser directly.

Configuration

Optionally, the following parameters can be set in the MicrodataRdfParser constructor:

  • dataFactory: A custom RDFJS DataFactory to construct terms and triples. (Default: require('@rdfjs/data-model'))
  • baseIRI: An initial default base IRI. (Default: '')
  • defaultGraph: The default graph for constructing quads. (Default: defaultGraph())
  • htmlParseListener: An optional listener for the internal HTML parse events, should implement IHtmlParseListener (Default: null)
  • xmlMode: If the parser should assume strict X(HT)ML documents. (Default: false)
  • vocabRegistry: A vocabulary registry to define specific behaviour for given URI prefixes. (Default: contents of http://www.w3.org/ns/md)
new RdfaParser({
  dataFactory: require('@rdfjs/data-model'),
  baseIRI: 'http://example.org/',
  defaultGraph: namedNode('http://example.org/graph'),
  htmlParseListener: new MyHtmlListener(),
  xmlMode: true,
  vocabRegistry: {
    "http://schema.org/": {
      "properties": {
        "additionalType": {"subPropertyOf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}
      }
    },
    "http://microformats.org/profile/hcard": {}
  },
});

How it works

This tool makes use of the highly performant htmlparser2 library for parsing HTML in a streaming way. It listens to tag-events, and maintains the required tag metadata in a stack-based datastructure, which can then be emitted as triples as soon as possible.

Our algorithm closely resembles the suggested algorithm for transforming Microdata to RDF, with a few changes to make it work in a streaming way.

If you want to make use of a different HTML/XML parser, you can create a regular instance of MicrodataRdfParser, and just call the following methods yourself directly:

  • onTagOpen(name: string, attributes: {[s: string]: string})
  • onText(data: string)
  • onTagClose()

Specification Compliance

This parser passes all tests from the Microdata to RDF test suite.

License

This software is written by Ruben Taelman.

This code is released under the MIT license.