# Hooks & Events ## Hooks Use hooks to transform masking value: - `preProcess` hook is called before the mask processing - `postProcess` hook is called after the mask processing, but before the input's value is set For example, you can use it to check for a maximum length of a masked string: ```js new MaskInput("input", { postProcess: (value: string) => value.slice(0, 5) }) ``` ## Events You can subscribe to `maska` event that fires after each mask processing. Event will contain `detail` property with a given structure: ### **Description** - `masked`: masked value - `unmasked`: unmasked value - `completed`: flag that current mask is completed ### **Types** ```typescript interface MaskaDetail { masked: string unmasked: string completed: boolean } ``` ```js const onMaska = (event: CustomEvent) => { console.log({ masked: event.detail.masked, unmasked: event.detail.unmasked, completed: event.detail.completed }) } ``` ## **Vanilla JS** ```js document.querySelector("input").addEventListener("maska", onMaska) ``` ## **Vue** ```vue ``` ## **Alpine** ```html ``` ## **Svelte** ```svelte ``` Alternatively, you can pass a callback function directly using the `onMaska` option: ### **Vanilla JS** ```js new MaskInput("input", { onMaska: (detail: MaskaDetail) => console.log(detail.completed) }) ``` ### **Vue** ```vue ``` ### **Alpine** ```html
``` ### **Svelte** ```svelte ```