rdf-string
Version:
Convenience functions for creating and serializing RDF terms and quads
72 lines (71 loc) • 3 kB
TypeScript
import * as RDF from "@rdfjs/types";
/**
* Utility methods for converting between string-based RDF representations and RDFJS objects.
*
* RDF Terms are represented as follows:
* * Blank nodes: '_:myBlankNode'
* * Variables: '?myVariable'
* * Literals: '"myString"', '"myLanguageString"@en-us', '"myLanguageString"@en-us--ltr', '"3"^^xsd:number'
* * URIs: 'http://example.org'
*
* Quads/triples are represented as hashes with 'subject', 'predicate', 'object' and 'graph' (optional)
* as keys, and string-based RDF terms as values.
*/
/**
* Convert an RDFJS term to a string-based representation.
* @param {RDF.Term} term An RDFJS term.
* @return {string} A string-based term representation.
*/
export declare function termToString<T extends RDF.Term | undefined | null>(term: T): T extends RDF.Term ? string : undefined;
/**
* Get the string value of a literal.
* @param {string} literalValue An RDF literal enclosed by '"'.
* @return {string} The literal value inside the '"'.
*/
export declare function getLiteralValue(literalValue: string): string;
/**
* Get the datatype of the given literal.
* @param {string} literalValue An RDF literal.
* @return {string} The datatype of the literal.
*/
export declare function getLiteralType(literalValue: string): string;
/**
* Get the language of the given literal.
* @param {string} literalValue An RDF literal.
* @return {string} The language of the literal.
*/
export declare function getLiteralLanguage(literalValue: string): string;
/**
* Get the direction of the given literal.
* @param {string} literalValue An RDF literal.
* @return {string} The direction of the literal.
*/
export declare function getLiteralDirection(literalValue: string): 'ltr' | 'rtl' | '';
/**
* Transform a string-based RDF term to an RDFJS term.
* @param {string} value A string-based RDF-term.
* @param {RDF.DataFactory} dataFactory An optional datafactory to create terms with.
* @return {RDF.Term} An RDF-JS term.
*/
export declare function stringToTerm(value: string | undefined, dataFactory?: RDF.DataFactory<RDF.BaseQuad>): RDF.Term;
/**
* Convert an RDFJS quad to a string-based quad representation.
* @param {Quad} q An RDFJS quad.
* @return {IStringQuad} A hash with string-based quad terms.
* @template Q The type of quad, defaults to RDF.Quad.
*/
export declare function quadToStringQuad<Q extends RDF.BaseQuad = RDF.Quad>(q: Q): IStringQuad;
/**
* Convert a string-based quad representation to an RDFJS quad.
* @param {IStringQuad} stringQuad A hash with string-based quad terms.
* @param {RDF.DataFactory} dataFactory An optional datafactory to create terms with.
* @return {Q} An RDFJS quad.
* @template Q The type of quad, defaults to RDF.Quad.
*/
export declare function stringQuadToQuad<Q extends RDF.BaseQuad = RDF.Quad>(stringQuad: IStringQuad, dataFactory?: RDF.DataFactory<Q>): Q;
export interface IStringQuad {
subject: string;
predicate: string;
object: string;
graph?: string;
}