@rdfjs/wrapper
    Preparing search index...

    Interface ITermAsValueMapping<T>

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

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

    • This library includes an assortment of opinionated mappings from terms to values that adhere to this interface. They are located in the following namespaces:
    • While the above mappings can be used anywhere a mapping from term to value is needed, users can also write their own as plain lambdas.
    • The parameter passed to mapping functions of this type is an abstraction introduced in this library instead of a Term. This is so the term serving as context for conversion also carries
      • a reference to the DatasetCore that contains the term, which can be used to extract further information, as well as
      • a DataFactory that can be used to create terms.
    • No restrictions are imposed on the type or content of values returned from these mapping functions except for the understanding that they represent the term 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 LiteralAs.number:

    class Person extends TermWrapper {
    get age(): number {
    return RequiredFrom.subjectPredicate(this. "age", LiteralAs.number) // 2nd param is the mapping
    }
    }

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

    class Person extends TermWrapper {
    get age(): number {
    return RequiredFrom.subjectPredicate(this. "age", term => Number(term.value)) // 2nd param is the mapping
    }
    }
    function termValue(term: TermWrapper): string {
    return term.value
    }
    function termValue(term) {
    return term.value
    }

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

    const termValue: ITermAsValueMapping<string> = term => term.value
    

    Type Parameters

    • T

      The type of value returned.