@rdfjs/wrapper
    Preparing search index...

    Interface ITermFromValueMapping<T>

    Represents the function signature of a mapping from some value to a term.

    Used by this library where lambdas are accepted for translating arbitrary values chosen by the user to terms.

    • This library includes an assortment of opinionated mappings from values to terms that adhere to this interface. They are located in the following namespaces:
    • While the above mappings can be used anywhere a mapping from value to term is needed, users can also write their own as plain lambdas.
    • No restrictions are imposed on the type or content of the value parameter accepted by these mapping functions except for the understanding that they return terms that represent the value in some way that is meaningful for the user in some circumstances.

    It is expected that in most cases the easiest way to convert between RDF terms and native values is by referencing one of the existing mapping functions like LiteralFrom.double:

    class Person extends TermWrapper {
    set age(value: number) {
    RequiredAs.object(this, "age", LiteralFrom.double) // 3rd param is the mapping
    }
    }

    Mapping can also be expressed as a lambda (function expression or arrow function expression):

    class Person extends TermWrapper {
    set age(value: number) {
    RequiredAs.object(this, "age", (value, factory) => factory.literal(value.toString(), factory.namedNode(XSD.double))) // 3rd param is the mapping
    }
    }
    function term(value: string, factory: DataFactory): Term {
    return factory.literal(value)
    }
    function term(value, factory) {
    return factory.literal(value)
    }

    Authoring mappings as typed TypeScript constants helps by compile-time checking that a lambda adheres to the interface.

    const termValue: ITermFromValueMapping<string> = (value, factory) => factory.literal(value)
    

    Type Parameters

    • T

      The type of value accepted.