Skip to content

attributes

Implements typechecking instance attributes.

function attributes.Attribute(
name: string,
check: t.check<T>,
default: T?
): Attribute<T>

Creates a new Attribute object with the name, an optional typecheckr, and an optional default value.

The name of the attribute.

An optional t.check function to validate the type of the attribute’s value.

An optional default value for the attribute if it’s not set or invalid.

A new Attribute object.`


function attributes.AttributeGroup(
prefix: string,
check: t.check<T>,
pattern: string?
): AttributeGroup<T>

Creates a new AttributeGroup object with the name, an optional typechecker, and an optional pattern.

The common prefix for all attributes in this group (e.g., “Property”, “Dismounts”).

An optional t.check function to validate the type of each attribute’s value within this group.

An optional string pattern to extract a unique key from the attribute name. Defaults to ^{prefix}_(%w+), which captures word characters after the prefix and an underscore.

A new AttributeGroup object.`