@metreeca/blue - v0.12.0
    Preparing search index...

    Module dictionary

    Dictionary shape types and operations.

    Defines the shape describing localised text, stated once per language, together with its constraint types, and provides the dictionary factory stating them, mapping JSON-LD language maps to RDF 1.1 language-tagged strings. A property whose value varies by language takes one member rather than one per language.

    Important

    Contradictory constraints are rejected as the shape is built, so a shape that exists admits at least one value: stating minLength above maxLength throws a TraceError.

    How many strings a tag carries is fixed by uniqueLang: a unique-tagged shape gives every tag a single string, and any other gives every tag an array. A member ranging over a dictionary carries the map whole, never in an array, whatever cardinality it states.

    The tag-keyed map is the form a value is stored and submitted in. A localised member additionally coalesces under language negotiation when retrieved, at the same per-tag arity: the value may be retrieved as the negotiated content alone, and filtered by a plain string operand matched against it under ordinary textual semantics. Submission never coalesces: it accepts the tag-keyed form alone.

    Compatibility

    JSON JSON-LD RDF 1.1
    tag-keyed string map @language-container language map language-tagged string literals

    Defining language-tagged shapes

    Values are tag-keyed maps; the und tag carries content of undetermined language (a proper name, say), and the zxx tag content with no language at all (identifiers, codes, formulae):

    import { dictionary } from '@metreeca/blue/dictionary';

    const label = dictionary({ uniqueLang: true }); // a single string per tag
    const keywords = dictionary(); // an array of strings per tag
    const name = dictionary({ minLength: 1, maxLength: 200 });// length-constrained
    const abstract = dictionary({ languageIn: ["en", "it"] });// language-restricted

    Using in resource shapes

    import { multiple, optional, required, resource } from '@metreeca/blue/resource';
    import { dictionary } from '@metreeca/blue/dictionary';

    const Article = resource({
    title: required(dictionary({ uniqueLang: true, minLength: 1 })),
    abstract: optional(dictionary({ uniqueLang: true })),
    keywords: multiple(dictionary({ languageIn: ["en", "fr", "de"] }))
    });

    A member carries one map whatever cardinality it states, so keywords above reads as a single map of string arrays and never as an array of maps.

    Type Aliases

    DictionaryShape

    Describes a localised textual value.

    DictionaryConstraints

    Constraints accepted by the dictionary shape factory.

    Functions

    dictionary

    Creates a dictionary shape.