Maskito

repository·main·Indexed 23 days ago

https://github.com/taiga-family/maskito

A collection of TypeScript libraries for creating input masks that ensure users provide data in predefined formats. It features a zero-dependency, framework-agnostic core (@maskito/core) and provides specialized integrations for Angular, React, React Native, and Vue. Additional packages include @maskito/kit for ready-to-use masks and @maskito/phone for phone number masking. Maskito supports keyboard and pointer interactions, browser autofill, SSR, Shadow DOM, and works with HTMLInputElement, HTMLTextAreaElement, and contenteditable elements.

Tokens
10.5K
Snippets
27
Records
75
Agent score
81%

What's inside Maskito

  1. Overview of @maskito/kit

    main
    The @maskito/kit package is an optional, framework-agnostic extension for Maskito. It provides a collection of ready-to-use masks that include configurable parameters, allowing you to implement common input masking patterns without writing custom logic from scratch.
  2. Key features and supported interactions in Maskito

    main

    Maskito is designed to be robust and handle a wide variety of user interactions with text fields, including:

    • Keyboard interactions: Basic typing and deleting.
    • Pointer/Mouse interactions: Pasting and dropping text.
    • Browser/Mobile features: Browser autofill and predictive text from mobile native keyboards.
    • Environment support: Works with Server Side Rendering (SSR) and Shadow DOM.
    • Element compatibility: Can be used with HTMLInputElement, HTMLTextAreaElement, or [contenteditable] elements.

    The core package is zero-dependency and framework-agnostic, making it suitable for vanilla JavaScript projects.

  3. Understand the structure of the preprocessor argument

    main

    When implementing a Maskito preprocessor, the first argument provided to the processor function is an object representing the state of the input element before any changes are applied, combined with the new data being processed.

    This object contains:

    • elementState: The current state of the input element, including its value and the current selection (a tuple of [from, to]).
    • data: The new characters being inserted or modified. This string may be empty if the user action is a deletion or if the input is being validated.
    type firstArgDemo = {
      // current input's element state BEFORE any changes are applied
      elementState: {
        value: string;
        selection: [from: number, to: number];
      };
      // new typed characters which is going to be inserted to the element
      data: string; // can be empty string if it is deletion or validation
    };