headless

API writables

createTypeEnum

function

createTypeEnum<T>(enumList): WritableWithDefaultOptions<T>

Build an enum normalizer

Type Parameters

T

the enum type

Parameters

enumList: T[]

list of enum values to check

Returns

WritableWithDefaultOptions<T>

the enum normalizer


testToNormalizeValue

function

testToNormalizeValue<T>(filter): (value) => typeof INVALID_VALUE | T

Check if a value respects a provided type guard.

Type Parameters

T

The type that the filter function validates.

Parameters

filter

A function that takes a value and returns a boolean indicating whether the value is of type T.

Returns

Function

A function that takes a value and returns the value if it passes the filter, otherwise returns INVALID_VALUE.

Parameters

value: any

Returns

typeof INVALID_VALUE | T


typeArray

constant

const typeArray: WritableWithDefaultOptions<any[]>

A writable object with default options for handling arrays.


typeBoolean

constant

const typeBoolean: WritableWithDefaultOptions<boolean>

A writable object with default options for boolean values.

This object provides a normalized way to handle boolean values using the WritableWithDefaultOptions interface. The normalizeValue function ensures that the value is properly validated and normalized as a boolean.


typeBooleanOrNull

constant

const typeBooleanOrNull: WritableWithDefaultOptions<boolean | null>

A writable with default options that normalizes its value to a boolean or null.

This writable uses a normalization function that allows null values and ensures the value is a boolean.


typeFunction

constant

const typeFunction: WritableWithDefaultOptions<(...args) => any>

A writable object that holds a function type with default options.


typeHTMLElementOrNull

constant

const typeHTMLElementOrNull: WritableWithDefaultOptions<HTMLElement | null>

A writable object with default options for handling values of type HTMLElement or null.

This object provides:

  • normalizeValue: A function to normalize the value, ensuring it is either an HTMLElement or null.
  • equal: A function to compare two values for equality using Object.is.

typeNumber

constant

const typeNumber: WritableWithDefaultOptions<number>

A writable object with default options for handling numbers.


typeNumberInRangeFactory

function

typeNumberInRangeFactory(min, max, options): WritableWithDefaultOptions<number>

Factory function for creating a type constraint for numbers within a specified range.

Parameters

min: number

The minimum value.

max: number

The maximum value.

options: TypeNumberInRangeOptions = {}

Additional options to customize the behavior.

Returns

WritableWithDefaultOptions<number>

A type guard function that returns the clamp value or INVALID_VALUE depending on the provided options.


TypeNumberInRangeOptions

interface

Options for specifying the behavior of number range validation.

Properties
strict?

optional strict: boolean

If true, the range checking will be strict, excluding the minimum and maximum values. Default is false.


useClamp?

optional useClamp: boolean

If true, values outside the range will be clamped to the minimum or maximum. Default is true.


typeString

constant

const typeString: WritableWithDefaultOptions<string>

A writable object with default options for string values.

This object provides a normalized value for strings using the testToNormalizeValue function with the isString validator.