### Install @maskito/core and @maskito/react Source: https://github.com/taiga-family/maskito/blob/main/projects/react/README.md Use npm to install the core Maskito library along with the React integration package. This is the initial setup step for using Maskito in a React project. ```bash npm i @maskito/{core,react} ``` -------------------------------- ### Install @maskito/core and @maskito/vue Source: https://github.com/taiga-family/maskito/blob/main/projects/vue/README.md Install the core Maskito library along with the Vue-specific package using npm. This is the initial setup step for using Maskito directives in your Vue project. ```bash npm i @maskito/{core,vue} ``` -------------------------------- ### Install @maskito/core and @maskito/kit Source: https://github.com/taiga-family/maskito/blob/main/projects/kit/README.md Install the core Maskito library along with the kit package, which contains pre-built masks. This command installs both packages using npm. ```bash npm i @maskito/{core,kit} ``` -------------------------------- ### Install Maskito for React Source: https://github.com/taiga-family/maskito/blob/main/projects/demo/src/pages/frameworks/react/react-doc.template.html Install the necessary Maskito libraries for React integration. This is the first step before using Maskito in your React application. ```bash npm install @maskito/core @maskito/react ``` -------------------------------- ### Install @maskito/core Source: https://github.com/taiga-family/maskito/blob/main/projects/core/README.md Install the core Maskito package using npm. This package is framework-agnostic and can be used standalone. ```bash npm i @maskito/core ``` -------------------------------- ### Install @maskito/phone Package Source: https://github.com/taiga-family/maskito/blob/main/projects/phone/README.md Install the @maskito/core and @maskito/phone packages using npm. These are required for phone masking functionality. ```bash npm i @maskito/{core,phone} ``` -------------------------------- ### Install @maskito/angular Source: https://github.com/taiga-family/maskito/blob/main/projects/angular/README.md Installs the core Maskito library along with the Angular-specific package. Use this command to add Maskito to your Angular project. ```bash npm i @maskito/{core,angular} ``` -------------------------------- ### Custom Element Predicate for Maskito Source: https://github.com/taiga-family/maskito/blob/main/projects/demo/src/pages/frameworks/react/react-doc.template.html Shows how to provide a custom `elementPredicate` function to `useMaskito` when the input element is not directly accessible, for example, when using UI kit components. ```tsx import React from 'react'; import { useMaskito } from '@maskito/react'; import { createNumberMask } from 'maskito'; function MyComponent() { const maskito = useMaskito(createNumberMask(), { elementPredicate: (host) => host.querySelector('.my-custom-input'), }); return (
{/* ... other elements ... */} {/* ... other elements ... */}
); } ``` -------------------------------- ### Vue Basic Usage with Number Mask Source: https://github.com/taiga-family/maskito/blob/main/projects/demo/src/pages/frameworks/vue/examples/use-maskito-basic-usage.md Integrates Maskito into a Vue.js application to format an input field as a number with a custom thousand separator. Ensure `@maskito/vue` and `@maskito/kit` are installed. ```typescript import {createApp} from 'vue'; import {maskitoNumber} from '@maskito/kit'; import {maskito} from '@maskito/vue'; createApp({ template: '', directives: {maskito}, data: () => ({ value: '123_456', options: maskitoNumber({ thousandSeparator: '_', }), }), }).mount('#vue'); ``` -------------------------------- ### Handle Leading Zeros in Number Input Source: https://github.com/taiga-family/maskito/blob/main/projects/demo/src/pages/documentation/processors/examples/postprocessor-in-action.md This postprocessor prevents multiple leading zeros, ensuring the input starts with a single '0' if necessary. It adjusts the cursor position accordingly. ```typescript import { Maskito } from '@maskito/core'; const numberInput = new Maskito(element, { mask: /^\d+(,\d*)?$/, postprocessors: [ ({value, selection}, initialElementState) => { const [from, to] = selection; const noRepeatedLeadingZeroesValue = value.replace(/^0+/, '0'); const removedCharacters = value.length - noRepeatedLeadingZeroesValue.length; return { value: noRepeatedLeadingZeroesValue, // User types "000000" => 0| selection: [Math.max(from - removedCharacters, 0), Math.max(to - removedCharacters, 0)], }; }, ], }); ``` -------------------------------- ### Pattern Mask for HH:MM Time Format Source: https://github.com/taiga-family/maskito/blob/main/projects/demo/src/pages/documentation/mask-expression/mask-expression.template.html Define a fixed-size time format using a pattern array. Fixed characters like ':' are automatically managed and cannot be erased. This example ensures only digits are accepted and limits the input length. ```typescript mask: ['H', 'H', ':', 'M', 'M'] ``` -------------------------------- ### Incorrect Usage of maskitoParseNumber Source: https://github.com/taiga-family/maskito/blob/main/projects/demo/src/pages/kit/number/helpers/parse-number-invalid-usage.md Shows examples of how maskitoParseNumber might produce unexpected results when parsing strings that do not conform to expected number formats, especially with prefixes. ```typescript maskitoParseNumber('-42'); // -42 ✅ maskitoParseNumber('> -42'); // 42 ❌ maskitoParseNumber('> -42', {prefix: '> '}); // -42 ✅ ``` -------------------------------- ### Vue Custom Nested Input with Maskito Source: https://github.com/taiga-family/maskito/blob/main/projects/demo/src/pages/frameworks/vue/examples/query-nested-input.md Applies Maskito number masking to a nested input element within a custom Vue component. Ensure `@maskito/vue` and `@maskito/kit` are installed. The `elementPredicate` option is crucial for targeting the correct input. ```typescript import {createApp} from 'vue'; import {maskitoNumber} from '@maskito/kit'; import {maskito} from '@maskito/vue'; createApp({ template: '', directives: {maskito}, data: () => ({ value: '123456', options: { ...maskitoNumber(), elementPredicate: (host) => host.querySelector('input')!, }, }), }).mount('#vue'); ``` -------------------------------- ### ElementState Interface Definition Source: https://github.com/taiga-family/maskito/blob/main/projects/demo/src/pages/documentation/element-state/examples/element-state-demo.md Defines the structure for the value and selection range of a masked input or textarea. The 'value' property holds the masked string, and 'selection' is a tuple representing the start and end indices of the selected text. ```typescript interface ElementState { // the value of a masked or