Registry / serialization / microdata-rdf-streaming-parser

microdata-rdf-streaming-parser

JSON →
library3.0.0jsnpmunverified

microdata-rdf-streaming-parser is a JavaScript library designed for efficiently parsing HTML documents containing Microdata annotations and transforming them into RDFJS-compliant quads. Currently at version 3.0.0, the library prioritizes a streaming approach, allowing it to process documents larger than available memory and emit RDF triples as soon as possible, rather than waiting for the entire document to be loaded. It is 100% spec-compliant with the W3C Microdata to RDF transformation algorithm and integrates seamlessly with the RDFJS ecosystem for its data model representations. While a specific release cadence is not outlined, major version updates, like the current v3, typically introduce significant architectural changes, such as a shift towards ESM-first patterns. Its key differentiators include its robust streaming capability powered by `htmlparser2`, strict adherence to the Microdata to RDF specification, and its lightweight footprint, making it suitable for both Node.js environments and browser-based applications via bundlers.

npm install microdata-rdf-streaming-parser
INSTALL
IMPORT
SIG · MICRODATA-RDF-STRE
M
microdata-rdf-streaming-parser
serializationjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MicrodataRdfParser
import { MicrodataRdfParser } from 'microdata-rdf-streaming-parser';
const MicrodataRdfParser = require('microdata-rdf-streaming-parser').MicrodataRdfParser;
Preferred ESM import for modern Node.js and bundler environments. The CommonJS require syntax is also supported as shown in the package's README, but ESM is generally recommended for new projects.
IHtmlParseListener
import type { IHtmlParseListener } from 'microdata-rdf-streaming-parser';
TypeScript type import for implementing custom listeners for internal HTML parsing events, useful for advanced use cases or debugging.
MicrodataRdfParserOptions
import type { MicrodataRdfParserOptions } from 'microdata-rdf-streaming-parser';
TypeScript type import for configuring the parser's constructor options, such as `dataFactory`, `baseIRI`, and `defaultGraph`.

Demonstrates how to initialize the `MicrodataRdfParser` with custom options, feed it an HTML string via a readable stream, and log the resulting RDFJS quads as they are emitted in a streaming fashion.

import { MicrodataRdfParser } from 'microdata-rdf-streaming-parser'; import { Readable } from 'stream'; // It's recommended to explicitly import RDFJS data model factories for clarity and version control import { createDataFactory, createDefaultGraph, createNamedNode } from '@rdfjs/data-model'; async function parseMicrodataStream(htmlString: string) { const dataFactory = createDataFactory(); const defaultGraph = createDefaultGraph(); const baseIRI = createNamedNode('http://example.org/document'); const parser = new MicrodataRdfParser({ dataFactory, baseIRI: baseIRI.value, // Pass the string value of the NamedNode defaultGraph, xmlMode: false, // Set to true if parsing strict XHTML documents }); const htmlStream = Readable.from([htmlString]); console.log('Starting Microdata parsing...'); let quadCount = 0; try { await new Promise<void>((resolve, reject) => { htmlStream .pipe(parser) .on('data', (quad) => { // Log each emitted quad. Subject, predicate, object, and graph are RDFJS Term objects. console.log(` Quad: ${quad.subject.value} ${quad.predicate.value} ${quad.object.value} ${quad.graph.value}`); quadCount++; }) .on('end', () => { console.log(`Microdata parsing finished. Emitted ${quadCount} quads.`); resolve(); }) .on('error', (err) => { console.error('Error during parsing:', err); reject(err); }); }); } catch (error) { console.error("An unexpected error occurred:", error); } } const microdataHtml = ` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Microdata Example</title> </head> <body> <div itemscope itemtype="http://schema.org/Person"> <h1 itemprop="name">John Doe</h1> <p>Title: <span itemprop="jobTitle">Professor</span></p> <p>Works at: <span itemprop="worksFor" itemscope itemtype="http://schema.org/Organization"><span itemprop="name">University of Example</span></span></p> <p>Email: <a href="mailto:john.doe@example.com" itemprop="email">john.doe@example.com</a></p> </div> <div itemscope itemtype="http://schema.org/Article"> <h2 itemprop="headline">My Awesome Article</h2> <span itemprop="author" itemscope itemtype="http://schema.org/Person"> By <span itemprop="name">Jane Smith</span> </span> <p itemprop="articleBody">This is the body of the article.</p> </div> </body> </html> `; parseMicrodataStream(microdataHtml).catch(console.error);
Debug
Known issues
breakingMajor version 3.0.0 likely introduces breaking changes, particularly a shift towards an ESM-first architecture. This can affect how the `MicrodataRdfParser` class is exported and imported, potentially breaking existing CommonJS setups.
fix
Review the official documentation for any v3 migration guide. Update import statements to use ESM `import { MicrodataRdfParser } from 'microdata-rdf-streaming-parser';` for modern Node.js and bundler environments. If using CommonJS, explicit `require` access (e.g., `require('pkg').Symbol`) might be needed, or consider migrating to ESM.
affects: >=3.0.0
gotchaThe `baseIRI` option is critical for correctly resolving relative URIs within the Microdata document. Failing to provide a meaningful or correct `baseIRI` can lead to malformed or unresolvable RDF terms in the output.
fix
Always provide a `baseIRI` option in the `MicrodataRdfParser` constructor that represents the absolute URL of the HTML document being parsed. This ensures correct URI resolution for Microdata properties.
affects: >=1.0.0
gotchaThe parser uses an `RDFJS DataFactory` to construct RDF terms and quads. If your application relies on a specific version or implementation of RDFJS primitives, you must explicitly set the `dataFactory` option to avoid potential compatibility issues with the default factory, which might be a different or older RDFJS implementation.
fix
If using a particular RDFJS implementation, pass its `DataFactory` instance to the `dataFactory` option (e.g., `dataFactory: myCustomDataFactory`). Ensure your RDFJS dependency aligns with the library's expectations.
affects: >=1.0.0
gotchaAs a streaming parser based on Node.js `Transform` streams, proper error handling on both the input stream and the parser instance is essential. Unhandled stream errors can cause application crashes or silently lead to incomplete parsing results.
fix
Always attach an `'error'` listener to both your input `Readable` stream and the `MicrodataRdfParser` instance (e.g., `.on('error', console.error)`) to catch and gracefully handle any parsing or stream-related exceptions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , microdata_rdf_streaming_parser_1.MicrodataRdfParser) is not a constructor
This error typically occurs when attempting to use a CommonJS `require()` pattern with an ESM-only export, or due to a bundler misconfiguration when trying to import the `MicrodataRdfParser` class.
fix
Ensure you are using the correct `import` statement for your environment. For modern Node.js and bundlers, use `import { MicrodataRdfParser } from 'microdata-rdf-streaming-parser';`. If explicitly targeting CommonJS, ensure the package supports it with `const { MicrodataRdfParser } = require('microdata-rdf-streaming-parser');`.
Error: Cannot pipe a non-readable stream to a writable stream.
The source being piped into the `MicrodataRdfParser` is not a valid Node.js `Readable` stream, or it has already been consumed or closed.
fix
Verify that the stream you are piping into `MicrodataRdfParser` is a valid `Readable` stream and is still open. When parsing a string, use `Readable.from([yourString])` to wrap it in a readable stream.
RangeError: Maximum call stack size exceeded
While designed for streaming, extremely deeply nested HTML structures or feeding very large HTML documents as a single, massive chunk might still stress the underlying HTML parser's recursive logic or internal stack.
fix
Ensure HTML input is processed in reasonably sized chunks for optimal streaming performance, though for most valid documents, the streaming nature of `htmlparser2` should mitigate this. For unusually deep or complex documents, consider breaking them into smaller, more manageable pieces before feeding them to the parser, if possible.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
@rdfjs/data-modelrequiredDefault DataFactory for constructing RDF terms and quads. Users may need to manage its version or provide a custom factory.
htmlparser2requiredUnderlying high-performance HTML parser for streaming HTML document processing.
Agent activity
2 hits · last 30 days
node
2
Resources
microdata-rdf-streaming-parser — npm install microdata-rdf-streaming-parser · libregistry