createTypeEnum<
T
>(enumList
):WritableWithDefaultOptions
<T
>
Build an enum normalizer
• T
the enum type
• enumList: T
[]
list of enum values to check
the enum normalizer
testToNormalizeValue<
T
>(filter
): (value
) => typeofINVALID_VALUE
|T
Check if a value respects a provided type guard.
• T
The type that the filter function validates.
• filter
A function that takes a value and returns a boolean indicating whether the value is of type T.
Function
A function that takes a value and returns the value if it passes the filter,
otherwise returns INVALID_VALUE
.
• value: any
typeof INVALID_VALUE
| T
const
typeArray:WritableWithDefaultOptions
<any
[]>
A writable object with default options for handling arrays.
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.
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.
const
typeFunction:WritableWithDefaultOptions
<(...args
) =>any
>
A writable object that holds a function type with default options.
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
.
const
typeNumber:WritableWithDefaultOptions
<number
>
A writable object with default options for handling numbers.
typeNumberInRangeFactory(
min
,max
,options
):WritableWithDefaultOptions
<number
>
Factory function for creating a type constraint for numbers within a specified range.
• min: number
The minimum value.
• max: number
The maximum value.
• options: TypeNumberInRangeOptions
= {}
Additional options to customize the behavior.
WritableWithDefaultOptions
<number
>
A type guard function that returns the clamp value or INVALID_VALUE depending on the provided options.
Options for specifying the behavior of number range validation.
optional
strict:boolean
If true
, the range checking will be strict, excluding the minimum and maximum values. Default is false
.
optional
useClamp:boolean
If true
, values outside the range will be clamped to the minimum or maximum. Default is true
.
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.