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

    Module boolean

    Boolean shape types and operations.

    Defines the shape describing the truth values a resource may carry and provides the boolean factory stating it, mapping the JSON boolean type to the XSD 1.0 boolean datatype. The kind closes the domain to two values; an enumeration closes it further to one, so that a member may stand as the tag telling the alternatives of a union apart.

    XSD Datatype ¹ Factory Description Range
    boolean boolean binary-valued logic {true, false}

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

    Compatibility

    JSON XSD JavaScript
    true, false {true, false, 1, 0} ¹ true, false

    ¹ Canonical form: true, false

    Defining boolean shapes

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

    const flag = boolean(); // either truth value
    const settled = boolean({ in: true }); // the single admitted value
    const paid = boolean(true); // the same, stated as a bare value
    Note

    An enumeration also narrows the value the shape describes: settled admits true, not both truth values. The domain holds two values, so the constraint states the single admitted one: a list would degenerate, admitting either the whole domain or nothing at all.

    Using in resource shapes

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

    const Product = resource({
    available: required(boolean()),
    featured: optional(boolean())
    });

    Tagging the alternatives of a union

    import { boolean } from '@metreeca/blue/boolean';
    import { date } from '@metreeca/blue/string';
    import { required, resource } from '@metreeca/blue/resource';
    import { union } from '@metreeca/blue/union';

    const Payment = union(
    resource({ settled: required(boolean(false)), due: required(date()) }),
    resource({ settled: required(boolean(true)), paid: required(date()) })
    );

    A stored value states one truth value, singling out the alternative it belongs to, and the type of the value the union describes is narrowed by the tag exactly as the shape is.

    Type Aliases

    BooleanShape

    Describes a truth value.

    BooleanConstraints

    Constraints accepted by the boolean shape factory.

    Functions

    boolean

    Creates a boolean shape.