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

    Module string

    Textual shape and factories.

    Defines shapes and factories for validating textual values, mapping the JSON string type to XSD 1.0 string datatypes.

    Factories validate constraint consistency at construction time: contradictory constraints like minLength > maxLength throw a RangeError.

    XSD Datatype ¹ Factory Description Format
    string string Unicode character sequence
    string text Single-line plain text
    string markdown Markdown formatted text
    string email RFC 5321 email address
    string phone ITU-T E.164 telephone number
    string iri RFC 3987 IRI reference
    string url RFC 3986 hierarchical URL
    string tag BCP 47 language tag
    gYear year ² ISO 8601 year YYYY[Z/±hh:mm]
    date date ISO 8601 date YYYY-MM-DD[Z/±hh:mm]
    time time ISO 8601 time hh:mm:ss[.sss][Z/±hh:mm]
    dateTime instant ISO 8601 date+time YYYY-MM-DDThh:mm:ss[.sss][TZ]
    dateTime timestamp ³ ISO 8601 UTC timestamp YYYY-MM-DDThh:mm:ss.sssZ
    duration duration ISO 8601 duration [-]PnYnMnDTnHnMnS

    ¹ XSD 1.0 datatypes are referenced by RDF 1.1 and JSON-LD 1.1 as normative

    ² XSD 1.1 Part 2 § D.3.4 permits optional timezone indicators for gYear as a deviation from ISO 8601

    ³ Requires exactly 3 fractional second digits (millisecond precision) and UTC timezone (Z only); typed as xsd:dateTime rather than the more specific xsd:dateTimeStamp for compatibility with SPARQL temporal functions, which are defined over xsd:dateTime

    Compatibility

    JSON XSD JavaScript
    UTF-8 encoded Unicode (XML 1.0 Char) UTF-16 encoded (compatible)

    Defining String Shapes

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

    const value = string(); // unconstrained string
    const name = string({ model: "name", minLength: 1, maxLength: 100 }); // length-constrained
    const code = string({ model: "ABC-1234", pattern: /^[A-Z]{3}-\d{4}$/ });// pattern-constrained
    const status = string({ in: ["active", "inactive"] }); // enumeration-constrained

    The model is a retrieval placeholder matched by JSON type alone: its value is immaterial and need not be legal for the shape's constraints, so an unspecified one defaults to the empty string regardless of any pattern.

    Specialised String Factories

    Predefined factories for common string formats:

    import {
    text, markdown, email, iri, url, tag, date, time, instant, timestamp, duration
    } from '@metreeca/blue/string';

    const label = text(); // single-line plain text
    const body = markdown(); // Markdown formatted text
    const contact = email(); // RFC 5321 email address
    const identifier = iri(); // RFC 3987 IRI reference
    const link = url(); // RFC 3986 hierarchical URL
    const language = tag(); // BCP 47 language tag
    const birthday = date(); // ISO 8601 date (YYYY-MM-DD)
    const start = time(); // ISO 8601 time (hh:mm:ss)
    const created = instant(); // ISO 8601 datetime
    const modified = timestamp(); // ISO 8601 timestamp (millisecond precision, UTC)
    const validity = duration(); // ISO 8601 duration

    Using in Resource Shapes

    import { required, optional } from '@metreeca/blue/value';
    import { resource } from '@metreeca/blue/resource';
    import { string, email, date } from '@metreeca/blue/string';

    const Person = resource({
    name: required(string({ model: "name", minLength: 1 })),
    email: optional(email()),
    birthDate: optional(date())
    });

    Interfaces

    StringShape

    Shape definition for textual values.

    StringConstraints

    Constraints for the string shape factory.

    StringLengthConstraints

    Length bounds for textual shape factories.

    StringValueConstraints

    Value constraints for textual shape factories.

    Functions

    string

    Creates a string shape.

    text

    Creates a shape for single-line plain text values.

    markdown

    Creates a shape for Markdown text values.

    email

    Creates a shape for email address values.

    phone

    Creates a shape for telephone number values.

    iri

    Creates a shape for Internationalized Resource Identifier values.

    url

    Creates a shape for hierarchical URL values.

    tag

    Creates a shape for language tag values.

    year

    Creates a shape for ISO 8601 year values (YYYY).

    date

    Creates a shape for ISO 8601 calendar date values (YYYY-MM-DD).

    time

    Creates a shape for ISO 8601 time of day values (hh:mm:ss).

    instant

    Creates a shape for ISO 8601 date and time values (YYYY-MM-DDThh:mm:ss).

    timestamp

    Creates a shape for UTC timestamp values with millisecond precision (YYYY-MM-DDThh:mm:ss.sssZ).

    duration

    Creates a shape for ISO 8601 duration values (PnYnMnDTnHnMnS).