A TypeScript library for serializing and formatting RDF and SPARQL, built for IDE integration.
Designed as the counterpart to @faubulous/mentor-rdf-parsers, this library provides RDF serialization and SPARQL formatting with first-class support for editor workflows such as document formatting, range formatting, comment preservation, and configurable output styles.
| Multi-Format Output | Serialize to N-Triples, N-Quads, Turtle, TriG, N3, and JSON-LD |
| SPARQL Formatting | Format queries and updates with keyword casing, alignment, and comment preservation |
| RDF 1.2 | Triple terms (<<( s p o )>>), reified triples, annotations, and language direction |
| Sorting Strategies | Alphabetical, by-type, semantic, and priority-based quad ordering |
| Comment Preservation | Token-based serialization keeps comments attached to their statements |
| Token Serialization | Serialize directly from parser tokens to preserve blank node IDs and source layout |
| Configurable Layout | Line width, predicate alignment, blank node style, object list wrapping, and more |
| IDE-Ready | Partial document serialization, range formatting, and VS Code integration examples |
npm install @faubulous/mentor-rdf-serializers
import { TurtleSerializer } from '@faubulous/mentor-rdf-serializers';
import DataFactory from '@rdfjs/data-model';
const serializer = new TurtleSerializer();
const quads = [
DataFactory.quad(
DataFactory.namedNode('http://example.org/subject'),
DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
DataFactory.namedNode('http://example.org/Class')
),
DataFactory.quad(
DataFactory.namedNode('http://example.org/subject'),
DataFactory.namedNode('http://example.org/name'),
DataFactory.literal('Example', 'en')
)
];
console.log(serializer.serialize(quads, {
prefixes: {
'ex': 'http://example.org/',
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
}
}));
PREFIX ex:
PREFIX rdf:
ex:subject a ex:Class ;
ex:name "Example"@en .
Detailed guides and API documentation are available in the docs folder:
| Guide | Description |
|---|---|
| Getting Started | Installation and first serialization |
| Architecture | Parser/serializer pipeline overview |
| Serializers | Format-specific serializer usage |
| Token Serialization | Serialize from parser tokens |
| SPARQL Formatting | Query and update formatting |
| Sorting | Quad ordering strategies |
| Options | Full configuration reference |
| RDF 1.2 | Triple terms, annotations, language direction |
| API Reference | Interfaces and types |
| VS Code Formatter | Editor integration example |
| Package | Description |
|---|---|
| @faubulous/mentor-rdf-parsers | RDF parsing library — the parser counterpart |
| @faubulous/mentor-vscode | RDF IDE and workbench for VS Code |
Contributions are welcome. Please feel free to open an issue or submit a pull request on GitHub.