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

    Module string

    Textual shape model and factories.

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

    Warning

    Factories check structural integrity of constraints but not their logical consistency: contradictory constraints like minLength > maxLength won't be rejected.

    XSD Datatype ¹ Factory Description Format
    string string Unicode character sequence
    string email RFC 5321 email address
    string url RFC 3986 absolute URL
    anyURI uri RFC 3986 absolute URI
    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]
    dateTimeStamp timestamp ³ ISO 8601 timestamp YYYY-MM-DDThh:mm:ss.sssZ
    duration duration ISO 8601 duration [-]PnYnMnDTnHnMnS

    ¹ XSD 1.1 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)

    Compatibility

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

    Defining String Shapes

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

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

    Specialised String Factories

    Predefined factories for common string formats:

    import { email, url, uri, date, time, instant, timestamp, duration } from '@metreeca/blue';

    const contact = email(); // RFC 5321 email address
    const homepage = url(); // RFC 3986 absolute URL
    const identifier = uri(); // RFC 3986 absolute URI
    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 { resource, required, optional, string, email, date } from '@metreeca/blue';

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

    Interfaces

    StringShape

    Shape definition for textual values.

    StringConstraints

    Constraints for the string shape factory.

    TextualConstraints

    Constraints for textual shape factories.

    Guards

    isStringShape

    Checks whether a value is a StringShape.

    isStringConstraints

    Checks whether a value is a valid StringConstraints object.

    isTextualConstraints

    Checks whether a value is a valid TextualConstraints object.

    Factories

    string

    Creates a string shape.

    email

    Creates a shape for email address values.

    url

    Creates a shape for absolute URL reference values.

    uri

    Creates a shape for absolute URI reference 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 ISO 8601 timestamp values with millisecond precision (YYYY-MM-DDThh:mm:ss.sssZ).

    duration

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