{"id":14867,"library":"rdfa-streaming-parser","title":"RDFa Streaming Parser","description":"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.","status":"active","version":"3.0.2","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/rubensworks/rdfa-streaming-parser.js","tags":["javascript","rdfa","linked data","semantic web","rdf","rdfjs","streaming","asynchronous","typescript"],"install":[{"cmd":"npm install rdfa-streaming-parser","lang":"bash","label":"npm"},{"cmd":"yarn add rdfa-streaming-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add rdfa-streaming-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Default DataFactory for constructing RDF terms and quads if no custom one is provided.","package":"@rdfjs/data-model","optional":false},{"reason":"Used in common examples for reading files as streams, a Node.js built-in module.","package":"fs","optional":true}],"imports":[{"note":"RdfaParser is a named export. While CommonJS require is still supported, native ESM import is preferred in modern applications.","wrong":"import RdfaParser from 'rdfa-streaming-parser';","symbol":"RdfaParser","correct":"import { RdfaParser } from 'rdfa-streaming-parser';"},{"note":"For CommonJS, RdfaParser is a named export. Directly requiring the package gives the module object, not the class constructor.","wrong":"const RdfaParser = require('rdfa-streaming-parser');","symbol":"RdfaParser","correct":"const { RdfaParser } = require('rdfa-streaming-parser');"},{"note":"For type-only imports in TypeScript, using `import type` is recommended for explicit intent and cleaner bundles.","symbol":"RdfaParser","correct":"import type { RdfaParser } from 'rdfa-streaming-parser';"}],"quickstart":{"code":"import { RdfaParser } from 'rdfa-streaming-parser';\nimport * as fs from 'fs'; // Node.js built-in module\n\nasync function parseRdfaFile(filePath: string, baseIri: string, contentType: string) {\n  const myParser = new RdfaParser({ baseIRI: baseIri, contentType: contentType });\n\n  console.log(`Parsing RDFa from ${filePath}...`);\n\n  return new Promise<void>((resolve, reject) => {\n    fs.createReadStream(filePath)\n      .pipe(myParser)\n      .on('data', (quad) => {\n        console.log(`Parsed quad: ${quad.subject.value} ${quad.predicate.value} ${quad.object.value} .`);\n      })\n      .on('error', (error) => {\n        console.error('An error occurred during parsing:', error);\n        reject(error);\n      })\n      .on('end', () => {\n        console.log('All triples were parsed successfully!');\n        resolve();\n      });\n  });\n}\n\n// Example usage:\nconst dummyHtmlContent = `<!DOCTYPE html>\n<html>\n<head prefix=\"foaf: http://xmlns.com/foaf/0.1/\">\n  <title>Example Document</title>\n  <link rel=\"foaf:primaryTopic foaf:maker\" href=\"https://www.rubensworks.net/#me\" />\n</head>\n<body>\n  <h1>Hello RDFa</h1>\n  <p>This is an <span property=\"foaf:name\">RDFa Example</span>.</p>\n</body>\n</html>`;\n\nconst tempFilePath = 'temp_rdfa_doc.html';\nfs.writeFileSync(tempFilePath, dummyHtmlContent);\n\nparseRdfaFile(tempFilePath, 'https://example.org/doc#', 'text/html')\n  .finally(() => {\n    fs.unlinkSync(tempFilePath); // Clean up the temporary file\n  });","lang":"typescript","description":"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."},"warnings":[{"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.","message":"Major 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider migrating CommonJS `require('rdfa-streaming-parser').RdfaParser` statements to `import { RdfaParser } from 'rdfa-streaming-parser';` for alignment with current JavaScript best practices.","message":"While 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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';`.","cause":"Attempting to invoke the module's default export as a constructor when `RdfaParser` is a named export, or incorrectly requiring the module.","error":"TypeError: RdfaParser is not a constructor"},{"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' });`.","cause":"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.","error":"Error: Missing base IRI and content type."},{"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');`.","cause":"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).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}