Socket
Socket
Sign inDemoInstall

@krutoo/input-mask

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @krutoo/input-mask

One more input mask library


Version published
Weekly downloads
241
decreased by-41.22%
Maintainers
1
Install size
58.4 kB
Created
Weekly downloads
 

Readme

Source

One more input mask library

JavaScript lib for making static masked inputs

Features

  • only static masks (fixed number of characters)
  • working with pure DOM inputs
  • able to make solutions for React/Vue/Angular based on this library

Usage

Installing:

npm install --save @krutoo/input-mask

Usage:

import { InputMask } from '@krutoo/input-mask/dist/dom';

const input = document.querySelector('input#phone');

const inputMask = InputMask(input, {
  mask: '___-____-____',
  placeholder: '_',
  pattern: /\d/,

  onChange: ({ value, cleanValue, ready }) => {
    // value is string with masked value
    // cleanValue is string only writable characters
    // ready is boolean which shows that the mask is completely filled
  },
});

// returns actual state of input
const { value, cleanValue, ready } = inputMask.getData();

// sets value manually
inputMask.setValue('00000000000');

// disables masking on element
inputMask.disable();

Advanced usage

This package also contains parts for build your own solution to provide input masking.

There is a several functions:

  • createReducer: returns reducer which takes input state and change action and returns the new state
  • defineChanges: takes current state and next state and returns change action

To Do

  • ✅ Create helper to use with vanilla js (no frameworks)
  • ✅ Divide react solution on react and vanilla js solutions
  • Add able to use middleware methods to prepare value before mask applying
  • Add examples of usage in React, React Native, Vue, Angular, Svelte...

Keywords

FAQs

Last updated on 08 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc