resolveMask
testedResolve a (possibly dynamic) mask to a concrete MaskExpression.
Signature
export function resolveMask(mask: Mask, state: ElementState): MaskExpression{ ... }Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
mask | Mask | — | — |
state | ElementState | — | — |
Returns
MaskExpressionRelated Types
ElementState
The DOM-free editable state the masking engine operates on: a value plus its
selection. Structurally compatible with @robonen/platform's InputState.
interface ElementState| Property | Type | Default | Description |
|---|---|---|---|
valuereadonly | string | — | — |
selectionreadonly | SelectionRange | — | — |
MaskPreprocessorParams
Input to a MaskPreprocessor.
interface MaskPreprocessorParams| Property | Type | Default | Description |
|---|---|---|---|
elementStatereadonly | ElementState | — | — |
datareadonly | string | — | — |
MaskPreprocessorResult
Output of a MaskPreprocessor.
interface MaskPreprocessorResult| Property | Type | Default | Description |
|---|---|---|---|
elementStatereadonly | ElementState | — | — |
data?readonly | string | — | — |
MaskOptions
A full mask configuration.
interface MaskOptions| Property | Type | Default | Description |
|---|---|---|---|
maskreadonly | Mask | — | The mask pattern (or a function of state). |
preprocessors?readonly | readonly MaskPreprocessor[] | — | Normalizers run before conforming. |
postprocessors?readonly | readonly MaskPostprocessor[] | — | Finishers run after conforming. |
overwriteMode?readonly | OverwriteMode | 'shift' | Insert vs overwrite behavior. |
ResolvedMaskOptions
MaskOptions after defaults are applied (internal).
interface ResolvedMaskOptions| Property | Type | Default | Description |
|---|---|---|---|
maskreadonly | Mask | — | — |
preprocessorsreadonly | readonly MaskPreprocessor[] | — | — |
postprocessorsreadonly | readonly MaskPostprocessor[] | — | — |
overwriteModereadonly | OverwriteMode | — | — |
SelectionRange
A selection range as [from, to]. A collapsed caret has from === to.
export type SelectionRange = readonly [from: number, to: number];MaskExpression
A concrete mask pattern: either a single RegExp validating the whole
value, or an array of slots where a string is a fixed (auto-inserted)
character and a RegExp validates exactly one character.
export type MaskExpression = ReadonlyArray<RegExp | string> | RegExp;Mask
A mask: a concrete MaskExpression or a function deriving one from the
current ElementState (a dynamic mask).
export type Mask = MaskExpression | ((state: ElementState) => MaskExpression);MaskAction
The user gesture a preprocessor is reacting to.
export type MaskAction = 'deleteBackward' | 'deleteForward' | 'insert' | 'validation';OverwriteMode
How newly typed characters interact with the text under a collapsed caret:
- shift — insert, pushing existing characters right (default);
- replace — overwrite the following characters;
- a function resolving the mode per ElementState.
export type OverwriteMode = 'replace' | 'shift' | ((state: ElementState) => 'replace' | 'shift');MaskPreprocessor
Runs before the mask conforms a value — normalizes the upcoming state/data.
export type MaskPreprocessor = (params: MaskPreprocessorParams, action: MaskAction) => MaskPreprocessorResult;MaskPostprocessor
Runs after the mask conforms a value — applies finishing touches (separators, padding, clamping). Receives the conformed state and the pre-change state.
export type MaskPostprocessor = (state: ElementState, initialState: ElementState) => ElementState;MaskOptionInput
The friendly authoring union accepted at every public boundary: a full
MaskOptions, a bare Mask, or a template string
(compiled via maskFromTemplate, e.g. '+1 (###) ###-####').
export type MaskOptionInput = Mask | string | MaskOptions;