Registry / serialization / rdfa-streaming-parser

rdfa-streaming-parser

JSON →
library3.0.2jsnpmunverified

The `rdfa-streaming-parser` package provides a high-performance, lightweight, and 100% spec-compliant streaming parser for RDFa 1.1 data. It is currently at version 3.0.2. This library is designed to emit RDFJS-compliant quads as soon as possible, enabling the efficient parsing of documents larger than available memory. Its streaming nature leverages Node.js Transform streams, allowing for direct piping of input sources like file streams. It also implements the RDFJS Sink interface for alternative stream processing. Key differentiators include its strict adherence to the RDFa 1.1 specification, its low memory footprint due to streaming, and its compatibility with the RDFJS ecosystem for data representation. The release cadence appears stable, with major version 3 indicating significant updates from previous iterations.

npm install rdfa-streaming-parser
INSTALL
IMPORT
SIG · RDFA-STREAMING-PAR
R
rdfa-streaming-parser
serializationjavascriptv3.0.2
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.

RdfaParser
import { RdfaParser } from 'rdfa-streaming-parser';
import RdfaParser from 'rdfa-streaming-parser';
RdfaParser is a named export. While CommonJS require is still supported, native ESM import is preferred in modern applications.
RdfaParser
const { RdfaParser } = require('rdfa-streaming-parser');
const RdfaParser = require('rdfa-streaming-parser');
For CommonJS, RdfaParser is a named export. Directly requiring the package gives the module object, not the class constructor.
RdfaParser
import type { RdfaParser } from 'rdfa-streaming-parser';
For type-only imports in TypeScript, using `import type` is recommended for explicit intent and cleaner bundles.

This quickstart demonstrates how to parse an RDFa document from a file stream using `RdfaParser`, log the extracted RDFJS quads, and gracefully handle completion or errors. A temporary HTML file is created and then cleaned up.

import { RdfaParser } from 'rdfa-streaming-parser'; import * as fs from 'fs'; // Node.js built-in module async function parseRdfaFile(filePath: string, baseIri: string, contentType: string) { const myParser = new RdfaParser({ baseIRI: baseIri, contentType: contentType }); console.log(`Parsing RDFa from ${filePath}...`); return new Promise<void>((resolve, reject) => { fs.createReadStream(filePath) .pipe(myParser) .on('data', (quad) => { console.log(`Parsed quad: ${quad.subject.value} ${quad.predicate.value} ${quad.object.value} .`); }) .on('error', (error) => { console.error('An error occurred during parsing:', error); reject(error); }) .on('end', () => { console.log('All triples were parsed successfully!'); resolve(); }); }); } // Example usage: const dummyHtmlContent = `<!DOCTYPE html> <html> <head prefix="foaf: http://xmlns.com/foaf/0.1/"> <title>Example Document</title> <link rel="foaf:primaryTopic foaf:maker" href="https://www.rubensworks.net/#me" /> </head> <body> <h1>Hello RDFa</h1> <p>This is an <span property="foaf:name">RDFa Example</span>.</p> </body> </html>`; const tempFilePath = 'temp_rdfa_doc.html'; fs.writeFileSync(tempFilePath, dummyHtmlContent); parseRdfaFile(tempFilePath, 'https://example.org/doc#', 'text/html') .finally(() => { fs.unlinkSync(tempFilePath); // Clean up the temporary file });
Debug
Known issues
breakingMajor version 3 introduces changes that might require updates to existing codebases, especially regarding how errors are handled or specific configuration options are interpreted. Users upgrading from v1 or v2 should consult the official changelog or release notes for precise breaking changes.
fix
Review the official changelog for `rdfa-streaming-parser` between your current version and `3.x` and update your code accordingly. Pay close attention to error handling and constructor options.
affects: >=3.0.0
gotchaThe `RdfaParser` often requires a `baseIRI` and/or `contentType` option in its constructor for accurate parsing. Omitting these can lead to incorrect IRI resolution for relative paths or misinterpretation of the RDFa profile.
fix
Always provide at least a `baseIRI` (e.g., `https://example.com/`) and/or `contentType` (e.g., `'text/html'`) when initializing `RdfaParser` to ensure proper parsing context.
affects: >=1.0.0
gotchaWhile the library explicitly supports CommonJS `require`, modern Node.js development, especially when integrating with other ESM-first libraries, generally prefers native ES Modules `import` syntax for consistency and better tooling support.
fix
Consider migrating CommonJS `require('rdfa-streaming-parser').RdfaParser` statements to `import { RdfaParser } from 'rdfa-streaming-parser';` for alignment with current JavaScript best practices.
affects: >=1.0.0
gotchaThe parser emits RDFJS-compliant quads. Ensure that any downstream application components consuming these quads are compatible with the RDFJS data model specification, particularly concerning `DataFactory` implementations and term representations.
fix
Verify compatibility with the RDFJS specification for any RDF processing libraries you are using. If needed, you can pass a custom `dataFactory` to the `RdfaParser` constructor to ensure consistency.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: RdfaParser is not a constructor
Attempting to invoke the module's default export as a constructor when `RdfaParser` is a named export, or incorrectly requiring the module.
fix
For CommonJS, use `const { RdfaParser } = require('rdfa-streaming-parser');` or `const RdfaParser = require('rdfa-streaming-parser').RdfaParser;`. For ESM, use `import { RdfaParser } from 'rdfa-streaming-parser';`.
Error: Missing base IRI and content type.
The `RdfaParser` was initialized without sufficient context (like a `baseIRI` or `contentType`) to correctly resolve relative IRIs or understand the RDFa profile of the input.
fix
Provide a `baseIRI` and/or `contentType` (e.g., `'text/html'`) in the `RdfaParser` constructor options. Example: `new RdfaParser({ baseIRI: 'https://example.com/', contentType: 'text/html' });`.
SyntaxError: Cannot use import statement outside a module
Attempting to use ES Module `import` syntax in a file that is treated as a CommonJS module (e.g., a `.js` file without `"type": "module"` in `package.json`, or a `.cjs` file).
fix
Either configure your project to use ES Modules (by adding `"type": "module"` to `package.json` and using `.js` files, or renaming to `.mjs`), or use CommonJS `require` syntax: `const { RdfaParser } = require('rdfa-streaming-parser');`.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies
@rdfjs/data-modelrequiredDefault DataFactory for constructing RDF terms and quads if no custom one is provided.
fsoptionalUsed in common examples for reading files as streams, a Node.js built-in module.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
rdfa-streaming-parser — npm install rdfa-streaming-parser · libregistry