### imask

``
Need help reading this?

### InputMask

Listens to element events and controls changes between element and Masked

new InputMask(el: (MaskElement | HTMLInputElement | HTMLTextAreaElement), opts: Object)
Parameters
el `((MaskElement | HTMLInputElement | HTMLTextAreaElement))`
opts `(Object)`
Instance Members
▸ el

View element

el

Type: MaskElement

▸ masked

Internal Masked model

masked

Type: Masked<any>

▸ mask

Read or update mask

mask

Type: Mask

Returns
`Mask`
▸ value

Raw value

value

Type: string

Returns
`string`
▸ unmaskedValue

Unmasked value

unmaskedValue

Type: string

Returns
`string`
▸ typedValue

Typed unmasked value

typedValue

Type: any

Returns
`any`
▸ _bindEvents()

Starts listening to element events

_bindEvents()
▸ _unbindEvents()

Stops listening to element events

_unbindEvents()
▸ _fireEvent(ev, args)

Fires custom event

_fireEvent(ev: string, args: ...any)
Parameters
ev `(string)`
args `(...any)`
▸ selectionStart

Current selection start

selectionStart

Type: number

Returns
`number`
▸ cursorPos

Current cursor position

cursorPos

Type: number

Returns
`number`
▸ _saveSelection()

Stores current selection

_saveSelection()
▸ updateValue()

Syncronizes model value from view

updateValue()
▸ updateControl()

Syncronizes view from model value, fires change events

updateControl()
▸ updateOptions(opts)

Updates options with deep equal check, recreates @{link Masked} model if mask type changes

updateOptions(opts: {})
Parameters
opts `({})`
▸ updateCursor(cursorPos)

Updates cursor

updateCursor(cursorPos: number)
Parameters
cursorPos `(number)`
▸ _fireChangeEvents()

Fires custom events

_fireChangeEvents()
▸ alignCursor()

Aligns cursor to nearest available position

alignCursor()
▸ alignCursorFriendly()

Aligns cursor only if selection is empty

alignCursorFriendly()
▸ on(ev, handler)

Adds listener on custom event

on(ev: string, handler: Function): this
Parameters
ev `(string)`
handler `(Function)`
Returns
`this`
▸ off(ev, handler)

Removes custom event listener

off(ev: string, handler: Function): this
Parameters
ev `(string)`
handler `(Function)`
Returns
`this`
▸ _onInput(e)

Handles view input event

_onInput(e: InputEvent): void
Parameters
e `(InputEvent)`
Returns
`void`
▸ _onChange()

Handles view change event and commits model value

_onChange()
▸ _onDrop(ev)

Handles view drop event, prevents by default

_onDrop(ev: Event)
Parameters
ev `(Event)`
▸ _onFocus(ev)

Restore last selection on focus

_onFocus(ev: Event)
Parameters
ev `(Event)`
▸ _onClick(ev)

Restore last selection on focus

_onClick(ev: Event)
Parameters
ev `(Event)`
▸ destroy()

Unbind view events and removes element reference

destroy()

### isString

Checks if value is string

isString(str: any): boolean
Parameters
str `(any)`
Returns
`boolean`

### DIRECTION

Direction

DIRECTION
Properties
NONE `(string)`
LEFT `(string)`
FORCE_LEFT `(string)`
RIGHT `(string)`
FORCE_RIGHT `(string)`

### Direction

Direction

Direction

Type: string

### indexInDirection

Returns next char index in direction

indexInDirection(pos: number, direction: Direction): number
Parameters
pos `(number)`
direction `(Direction)`
Returns
`number`

### posInDirection

Returns next char position in direction

posInDirection(pos: number, direction: Direction): number
Parameters
pos `(number)`
direction `(Direction)`
Returns
`number`

### forceDirection

forceDirection(direction: Direction): Direction
Parameters
direction `(Direction)`
Returns
`Direction`

### escapeRegExp

Escapes regular expression control chars

escapeRegExp(str: string): string
Parameters
str `(string)`
Returns
`string`

### Selection

Selection range

Selection

Type: {start: number, end: number}

Properties
start `(number)`
end `(number)`

### ChangeDetails

Provides details of changing model value

new ChangeDetails(details: Object?)
Parameters
details `(Object?)`

Name | Description
--- | ---
details.inserted `string?` | Inserted symbols
details.skip `boolean?` | Can skip chars
details.removeCount `number?` | Removed symbols count
details.tailShift `number?` | Additional offset if any changes occurred before tail

Instance Members
▸ inserted

Inserted symbols

inserted

Type: string

▸ skip

Can skip chars

skip

Type: boolean

▸ tailShift

Additional offset if any changes occurred before tail

tailShift

Type: number

▸ rawInserted

Raw inserted is used by dynamic mask

rawInserted

Type: string

▸ aggregate(details)

Aggregate changes

aggregate(details: ChangeDetails): ChangeDetails
Parameters
details `(ChangeDetails)`
Returns
`ChangeDetails`: `this`
▸ offset

Total offset considering all changes

offset

Type: number

Returns
`number`

### ActionDetails

Provides details of changing input

new ActionDetails(value: string, cursorPos: number, oldValue: string, oldSelection: Selection)
Parameters
value `(string)`
cursorPos `(number)`
oldValue `(string)`
oldSelection `(Selection)`
Instance Members
▸ value

Current input value

value

Type: string

▸ cursorPos

Current cursor position

cursorPos

Type: number

▸ oldValue

Old input value

oldValue

Type: string

▸ oldSelection

Old selection

oldSelection

Type: Selection

▸ startChangePos

Start changing position

startChangePos

Type: number

Returns
`number`
▸ insertedCount

Inserted symbols count

insertedCount

Type: number

Returns
`number`
▸ inserted

Inserted symbols

inserted

Type: string

Returns
`string`
▸ removedCount

Removed symbols count

removedCount

Type: number

Returns
`number`
▸ removed

Removed symbols

removed

Type: string

Returns
`string`
▸ head

Unchanged head symbols

head

Type: string

Returns
`string`
▸ tail

Unchanged tail symbols

tail

Type: string

Returns
`string`
▸ removeDirection

Remove direction

removeDirection

Type: Direction

Returns
`Direction`

### MaskedDate

Date mask

new MaskedDate(opts: Object)

Extends MaskedPattern

Parameters
opts `(Object)`
Instance Members
▸ pattern

Pattern mask for date according to MaskedDate#format

pattern

Type: string

▸ min

Start date

min

Type: Date?

▸ max

End date

max

Type: Date?

▸ autofix
autofix

Type: (boolean | `"pad"`)

▸ _update(opts)
_update(opts: any)
Parameters
opts `(any)`
▸ doValidate(args)
doValidate(args: ...any): boolean
Parameters
args `(...any)`
Returns
`boolean`
▸ isDateExist(str)

Checks if date is exists

isDateExist(str: string): boolean
Parameters
str `(string)`
Returns
`boolean`
▸ date

Parsed Date

date

Type: Date?

Returns
`Date?`
▸ typedValue
typedValue

Type: Date?

Returns
`Date?`
▸ maskEquals(mask)
maskEquals(mask: any): boolean
Parameters
mask `(any)`
Returns
`boolean`

### MaskedPattern

Pattern mask

new MaskedPattern(opts: Object)

Extends Masked

Parameters
opts `(Object = `{}`)`

Name | Description
--- | ---
opts.blocks `Object` |
opts.definitions `Object` |
opts.placeholderChar `string` |
opts.lazy `boolean` |

Instance Members
▸ blocks
blocks

Type: {}

▸ definitions
definitions

Type: Definitions

▸ placeholderChar

Single char for empty input

placeholderChar

Type: string

▸ lazy

Show placeholder only when needed

lazy

Type: boolean

▸ _update(opts)
_update(opts: Object)
Parameters
opts `(Object = `{}`)`
▸ _rebuildMask()
_rebuildMask()
▸ state
state

Type: MaskedPatternState

Returns
`MaskedPatternState`
▸ reset()
reset()
▸ isComplete
isComplete

Type: boolean

Returns
`boolean`
▸ isFilled
isFilled

Type: boolean

Returns
`boolean`
▸ doCommit()
doCommit()
▸ unmaskedValue
unmaskedValue

Type: string

Returns
`string`
▸ value
value

Type: string

Returns
`string`
▸ appendTail(tail)
appendTail(tail: (string | String | TailDetails)): ChangeDetails
Parameters
tail `((string | String | TailDetails))`
Returns
`ChangeDetails`
▸ _appendEager()
_appendEager(): ChangeDetails
Returns
`ChangeDetails`
▸ _appendCharRaw(ch, flags)
_appendCharRaw(ch: string, flags: AppendFlags): ChangeDetails
Parameters
ch `(string)`
flags `(AppendFlags = `{}`)`
Returns
`ChangeDetails`
▸ extractTail(fromPos, toPos)
extractTail(fromPos: number, toPos: number): ChunksTailDetails
Parameters
fromPos `(number = `0`)`
toPos `(number = `this.value.length`)`
Returns
`ChunksTailDetails`
▸ extractInput(fromPos, toPos, flags)
extractInput(fromPos: number, toPos: number, flags: ExtractFlags): string
Parameters
fromPos `(number = `0`)`
toPos `(number = `this.value.length`)`
flags `(ExtractFlags = `{}`)`
Returns
`string`
▸ _appendPlaceholder(toBlockIndex)

Appends placeholder depending on laziness

_appendPlaceholder(toBlockIndex: number?): ChangeDetails
Parameters
toBlockIndex `(number?)`
Returns
`ChangeDetails`
▸ _mapPosToBlock(pos)

Finds block in pos

_mapPosToBlock(pos: number): BlockPosData?
Parameters
pos `(number)`
Returns
`BlockPosData?`
▸ _blockStartPos(blockIndex)
_blockStartPos(blockIndex: number): number
Parameters
blockIndex `(number)`
Returns
`number`
▸ _forEachBlocksInRange(fromPos, toPos, fn)
_forEachBlocksInRange(fromPos: number, toPos: number, fn: function (block: PatternBlock, blockIndex: number, fromPos: number, toPos: number): void)
Parameters
fromPos `(number)`
toPos `(number = `this.value.length`)`
fn `(function (block: PatternBlock, blockIndex: number, fromPos: number, toPos: number): void)`
▸ remove(fromPos, toPos)
remove(fromPos: number, toPos: number): ChangeDetails
Parameters
fromPos `(number = `0`)`
toPos `(number = `this.value.length`)`
Returns
`ChangeDetails`
▸ nearestInputPos(cursorPos, direction)
nearestInputPos(cursorPos: number, direction: Direction): number
Parameters
cursorPos `(number)`
direction `(Direction = `DIRECTION.NONE`)`
Returns
`number`
▸ maskedBlock(name)

Get block by name

maskedBlock(name: string): PatternBlock?
Parameters
name `(string)`
Returns
`PatternBlock?`
▸ maskedBlocks(name)

Get all blocks by name

maskedBlocks(name: string): Array<PatternBlock>
Parameters
name `(string)`
Returns
`Array<PatternBlock>`

### Mask

Supported mask type

Mask

Type: (string | String | RegExp | Class<Number> | Class<Date> | Array<any> | $PropertyType<Masked<any>, `"validate"`> | Masked<any> | Class<Masked<any>>)

### AppendFlags

Append flags

AppendFlags

Type: {input: boolean?, tail: boolean?, raw: boolean?, _beforeTailState: any?}

Properties
input `(boolean?)`
tail `(boolean?)`
raw `(boolean?)`
_beforeTailState `(any?)`

### ExtractFlags

Extract flags

ExtractFlags

Type: {raw: boolean?}

Properties
raw `(boolean?)`

### Masked

Provides common masking stuff

new Masked(opts: {})
Parameters
opts `({})`
Instance Members
▸ mask
mask

Type: Mask

▸ parent
parent

Type: Masked<any>?

▸ prepare

Transforms value before mask processing

prepare

Type: function (string, Masked<MaskType>, AppendFlags): (string | [string, ChangeDetails])

▸ validate

Validates if value is acceptable

validate

Type: function (string, Masked<MaskType>, AppendFlags): boolean

▸ commit

Does additional processing in the end of editing

commit

Type: function (string, Masked<MaskType>): void

▸ format

Format typed value to string

format

Type: function (any, Masked<MaskType>): string

▸ parse

Parse strgin to get typed value

parse

Type: function (string, Masked<MaskType>): any

▸ overwrite

Enable characters overwriting

overwrite

Type: (boolean? | `"shift"`)

▸ eager
eager

Type: boolean

▸ isInitialized
isInitialized

Type: boolean

▸ updateOptions(opts)

Sets and applies new options

updateOptions(opts: {})
Parameters
opts `({})`
▸ _update(opts)

Sets new options

_update(opts: {})
Parameters
opts `({})`
▸ state

Mask state

state

Type: any

Returns
`any`
▸ reset()

Resets value

reset()
▸ value
value

Type: string

Returns
`string`
▸ resolve(value)

Resolve new value

resolve(value: string): string
Parameters
value `(string)`
Returns
`string`
▸ unmaskedValue
unmaskedValue

Type: string

Returns
`string`
▸ typedValue
typedValue

Type: any

Returns
`any`
▸ rawInputValue

Value that includes raw user input

rawInputValue

Type: string

Returns
`string`
▸ isComplete
isComplete

Type: boolean

Returns
`boolean`
▸ isFilled
isFilled

Type: boolean

Returns
`boolean`
▸ nearestInputPos(cursorPos, direction?)

Finds nearest input position in direction

nearestInputPos(cursorPos: number, direction: Direction?): number
Parameters
cursorPos `(number)`
direction `(Direction?)`
Returns
`number`
▸ extractInput(fromPos, toPos, flags?)

Extracts value in range considering flags

extractInput(fromPos: number, toPos: number, flags: ExtractFlags?): string
Parameters
fromPos `(number = `0`)`
toPos `(number = `this.value.length`)`
flags `(ExtractFlags?)`
Returns
`string`
▸ extractTail(fromPos, toPos)

Extracts tail in range

extractTail(fromPos: number, toPos: number): TailDetails
Parameters
fromPos `(number = `0`)`
toPos `(number = `this.value.length`)`
Returns
`TailDetails`
▸ appendTail(tail)

Appends tail

appendTail(tail: (string | String | TailDetails)): ChangeDetails
Parameters
tail `((string | String | TailDetails))`
Returns
`ChangeDetails`
▸ _appendCharRaw(ch, flags)

Appends char

_appendCharRaw(ch: string, flags: AppendFlags): ChangeDetails
Parameters
ch `(string)`
flags `(AppendFlags = `{}`)`
Returns
`ChangeDetails`
▸ _appendChar(ch, flags, checkTail?)

Appends char

_appendChar(ch: string, flags: AppendFlags, checkTail: TailDetails?): ChangeDetails
Parameters
ch `(string)`
flags `(AppendFlags = `{}`)`
checkTail `(TailDetails?)`
Returns
`ChangeDetails`
▸ _appendPlaceholder()

Appends optional placeholder at end

_appendPlaceholder(): ChangeDetails
Returns
`ChangeDetails`
▸ _appendEager()

Appends optional eager placeholder at end

_appendEager(): ChangeDetails
Returns
`ChangeDetails`
▸ append(str, flags?, tail?)

Appends symbols considering flags

append(str: string, flags: AppendFlags?, tail: (string | String | TailDetails)?): ChangeDetails
Parameters
str `(string)`
flags `(AppendFlags?)`
tail `((string | String | TailDetails)?)`
Returns
`ChangeDetails`
▸ remove(fromPos, toPos)
remove(fromPos: number, toPos: number): ChangeDetails
Parameters
fromPos `(number = `0`)`
toPos `(number = `this.value.length`)`
Returns
`ChangeDetails`
▸ withValueRefresh(fn)

Calls function and reapplies current value

withValueRefresh(fn: function (): T): T
Parameters
fn `(function (): T)`
Returns
`T`
▸ runIsolated(fn)
runIsolated(fn: function (masked: any): T): T
Parameters
fn `(function (masked: any): T)`
Returns
`T`
▸ doPrepare(str, flags)

Prepares string before mask processing

doPrepare(str: string, flags: AppendFlags): (string | [string, ChangeDetails])
Parameters
str `(string)`
flags `(AppendFlags = `{}`)`
Returns
`(string | [string, ChangeDetails])`
▸ doValidate(flags)

Validates if value is acceptable

doValidate(flags: AppendFlags): boolean
Parameters
flags `(AppendFlags)`
Returns
`boolean`
▸ doCommit()

Does additional processing in the end of editing

doCommit()
▸ doFormat(value)
doFormat(value: any): string
Parameters
value `(any)`
Returns
`string`
▸ doParse(str)
doParse(str: string): string
Parameters
str `(string)`
Returns
`string`
▸ splice(start, deleteCount, inserted, removeDirection, flags)
splice(start: number, deleteCount: number, inserted: string, removeDirection: Direction, flags: AppendFlags): ChangeDetails
Parameters
start `(number)`
deleteCount `(number)`
inserted `(string)`
removeDirection `(Direction)`
flags `(AppendFlags = `{input:true}`)`
Returns
`ChangeDetails`

### PatternInputDefinitionOptions

PatternInputDefinitionOptions

Type: {parent: $PropertyType<PatternInputDefinition, `"parent"`>, mask: Mask, isOptional: $PropertyType<PatternInputDefinition, `"isOptional"`>, lazy: $PropertyType<PatternInputDefinition, `"lazy"`>, eager: $PropertyType<PatternInputDefinition, `"eager"`>, placeholderChar: $PropertyType<PatternInputDefinition, `"placeholderChar"`>}

Properties
parent `($PropertyType<PatternInputDefinition, `"parent"`>)`
mask `(Mask)`
isOptional `($PropertyType<PatternInputDefinition, `"isOptional"`>)`
lazy `($PropertyType<PatternInputDefinition, `"lazy"`>)`
eager `($PropertyType<PatternInputDefinition, `"eager"`>)`
placeholderChar `($PropertyType<PatternInputDefinition, `"placeholderChar"`>)`

### PatternInputDefinition

new PatternInputDefinition(opts: PatternInputDefinitionOptions)
Parameters
opts `(PatternInputDefinitionOptions)`
Instance Members
▸ masked
masked

Type: Masked<any>

▸ parent
parent

Type: Masked<any>

▸ isOptional
isOptional

Type: boolean

▸ isFilled
isFilled

Type: boolean

▸ lazy
lazy

Type: $PropertyType<MaskedPattern, `"lazy"`>

▸ eager
eager

Type: $PropertyType<Masked<string>, `"eager"`>

▸ placeholderChar
placeholderChar

Type: $PropertyType<MaskedPattern, `"placeholderChar"`>

### PatternFixedDefinitionOptions

PatternFixedDefinitionOptions

Type: {char: $PropertyType<PatternFixedDefinition, `"char"`>, isUnmasking: $PropertyType<PatternFixedDefinition, `"isUnmasking"`>?}

Properties
char `($PropertyType<PatternFixedDefinition, `"char"`>)`
isUnmasking `($PropertyType<PatternFixedDefinition, `"isUnmasking"`>?)`

### _value

_value

Type: string

### char

char

Type: string

### isUnmasking

isUnmasking

Type: boolean?

### eager

eager

Type: boolean

### _isRawInput

_isRawInput

Type: boolean?

### isFixed

isFixed

Type: boolean

### blockIndex

blockIndex

Type: number?

### ContinuousTailDetails

Provides details of continuous extracted tail

new ContinuousTailDetails(value: string, from: number, stop: number?)
Parameters
value `(string = `''`)`
from `(number = `0`)`
stop `(number?)`
Instance Members
▸ value

Tail value as string

value

Type: string

▸ from

Tail start position

from

Type: number

▸ stop

Start position

stop

Type: number?

### MaskedRegExp

Masking by RegExp

new MaskedRegExp()

Extends Masked

Instance Members
▸ _update(opts)
_update(opts: Object)
Parameters
opts `(Object)`

### MaskedRange

Pattern which accepts ranges

new MaskedRange()

Extends MaskedPattern

Instance Members
▸ maxLength

Optionally sets max length of pattern. Used when pattern length is longer then `to` param length. Pads zeros at start in this case.

maxLength

Type: number

▸ from

Min bound

from

Type: number

▸ to

Max bound

to

Type: number

▸ autofix
autofix

Type: (boolean | `"pad"`)

▸ _update(opts)
_update(opts: any)
Parameters
opts `(any)`
▸ isComplete
isComplete

Type: boolean

Returns
`boolean`
▸ doPrepare(ch, flags)
doPrepare(ch: string, flags: AppendFlags): (string | [string, ChangeDetails])
Parameters
ch `(string)`
flags `(AppendFlags = `{}`)`
Returns
`(string | [string, ChangeDetails])`
▸ doValidate(args)
doValidate(args: ...any): boolean
Parameters
args `(...any)`
Returns
`boolean`

### maskedClass

Get Masked class by mask type

maskedClass(mask: Mask): Class<Masked<any>>
Parameters
mask `(Mask)`
Returns
`Class<Masked<any>>`

### createMask

Creates new Masked depending on mask type

createMask(opts: ({mask: Mask} | Masked<any>)): Masked<any>
Parameters
opts `(({mask: Mask} | Masked<any>))`
Returns
`Masked<any>`

### MaskElement

Generic element API to use with mask

MaskElement
Instance Members
▸ _unsafeSelectionStart
_unsafeSelectionStart

Type: number

▸ _unsafeSelectionEnd
_unsafeSelectionEnd

Type: number

▸ value
value

Type: string

▸ selectionStart

Safely returns selection start

selectionStart

Type: number

Returns
`number`
▸ selectionEnd

Safely returns selection end

selectionEnd

Type: number

Returns
`number`
▸ select(start, end)

Safely sets element selection

select(start: number, end: number)
Parameters
start `(number)`
end `(number)`
▸ _unsafeSelect(start, end)

Should be overriden in subclasses

_unsafeSelect(start: number, end: number): void
Parameters
start `(number)`
end `(number)`
Returns
`void`
▸ isActive

Should be overriden in subclasses

isActive

Type: boolean

Returns
`boolean`
▸ bindEvents(handlers)

Should be overriden in subclasses

bindEvents(handlers: {})
Parameters
handlers `({})`
▸ unbindEvents()

Should be overriden in subclasses

unbindEvents(): void
Returns
`void`

### HTMLMaskElement

Bridge between HTMLElement and Masked

new HTMLMaskElement(input: (HTMLInputElement | HTMLTextAreaElement))

Extends MaskElement

Parameters
input `((HTMLInputElement | HTMLTextAreaElement))`
Static Members
▸ EVENTS_MAP

Mapping between HTMLElement events and mask internal events

EVENTS_MAP

Type: {}

Instance Members
▸ input

HTMLElement to use mask on

input

Type: (HTMLTextAreaElement | HTMLInputElement)

▸ rootElement
rootElement

Type: HTMLDocument

Returns
`HTMLDocument`
▸ isActive

Is element in focus

isActive

Type: boolean

Returns
`boolean`
▸ _unsafeSelectionStart

Returns HTMLElement selection start

_unsafeSelectionStart

Type: number

Returns
`number`
▸ _unsafeSelectionEnd

Returns HTMLElement selection end

_unsafeSelectionEnd

Type: number

Returns
`number`
▸ _unsafeSelect(start, end)

Sets HTMLElement selection

_unsafeSelect(start: number, end: number)
Parameters
start `(number)`
end `(number)`
▸ value

HTMLElement value

value

Type: string

Returns
`string`
▸ bindEvents(handlers)

Binds HTMLElement events to mask internal events

bindEvents(handlers: {})
Parameters
handlers `({})`
▸ unbindEvents()

Unbinds HTMLElement events to mask internal events

unbindEvents()
▸ _toggleEventHandler(event, handler?)
_toggleEventHandler(event: string, handler: Function?): void
Parameters
event `(string)`
handler `(Function?)`
Returns
`void`

### _unsafeSelectionStart

Returns HTMLElement selection start

_unsafeSelectionStart

Type: number

Returns
`number`

### _unsafeSelectionEnd

Returns HTMLElement selection end

_unsafeSelectionEnd

Type: number

Returns
`number`

### _unsafeSelect

Sets HTMLElement selection

_unsafeSelect(start: number, end: number)
Parameters
start `(number)`
end `(number)`

### value

HTMLElement value

value

Type: string

Returns
`string`

### IMask

Applies mask on element.

new IMask(el: (HTMLInputElement | HTMLTextAreaElement | MaskElement), opts: Object): InputMask
Parameters
el `((HTMLInputElement | HTMLTextAreaElement | MaskElement))` Element to apply mask
opts `(Object = `{}`)` Custom mask options
Returns
`InputMask`: