compareCodePointsfunctionno test imports itfunction compareCodePoints(a: string, b: string): numberTwo strings in the order of their code points (JavaScript's < orders UTF-16 units, which differs above U+FFFF).
The RDF writers (commons 0012-ontology FR-006, FR-007): N-Triples and N-Quads, Turtle in one canonical form, and JSON-LD in its expanded form. Each writes the same bytes for the same statements whatever the order they were stated in, so a generated file changes only where a fact does. There is no reader: what these write is read by RDF tools, and commons' own facts are TypeScript.
import { en, named, parseIri } from "./rdf-term.ts";
import { nTriples } from "./rdf-write.ts";
const s = parseIri("https://example.org/a");
const p = parseIri("http://www.w3.org/2000/01/rdf-schema#label");
if (s.kind === "ok" && p.kind === "ok") {
nTriples([{ subject: named(s.value), predicate: named(p.value), object: en("a") }]);
// '<https://example.org/a> <http://www.w3.org/2000/01/rdf-schema#label> "a"@en .\n'
}compareCodePointsfunctionno test imports itfunction compareCodePoints(a: string, b: string): numberTwo strings in the order of their code points (JavaScript's < orders UTF-16 units, which differs above U+FFFF).
nTriplesfunctionfunction nTriples(triples: readonly Triple[]): stringTriples as N-Triples: each once, one a line, the lines in the order of their code points.
nQuadsfunctionfunction nQuads(quads: readonly Quad[]): stringQuads as N-Quads: each once, one a line (a triple of the default graph has no fourth term), in the order of their code points.
TurtleDocumenttypeno test imports ittype TurtleDocument = {
readonly comments?: readonly string[];
readonly prefixes: readonly Namespace[];
readonly triples: readonly Triple[];
};What a Turtle document is made of: comment lines for its head, the prefixes it may use, and its triples.
turtlefunctionfunction turtle(doc: TurtleDocument): stringTriples as Turtle in its canonical form: the comment lines, then the prefixes sorted by name, then the subjects in the order of their N-Triples terms, each with its rdf:type first as a and its other predicates by IRI, each predicate's objects in the order of their N-Triples terms, one blank line between subjects. An IRI is a prefixed name where a prefix's IRI starts it and the rest is a plain local name (the longest such prefix), and a whole IRI otherwise; an integer or a boolean of canonical form is written bare.
jsonLdfunctionfunction jsonLd(triples: readonly Triple[]): stringTriples as JSON-LD in its expanded form: one node object for each subject, in the order of their N-Triples terms, with its @id, its @type (the IRIs of its rdf:types, sorted) and then each other predicate by IRI, its values in the order of their N-Triples terms.