npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

check-mask-inputs

v1.0.7

Published

Check Mask Inputs It is a library for validating and formatting numeric input data some pre-made formats and providing a customized format.

Downloads

14

Readme

CHECK-MASK-INPUTS

CheckMaskInput is a library for validating and masking user input in various formats, such as CPF, CNPJ, phone numbers, birth dates, and zip codes. It allows you to check if an input value is valid and to mask it with a specified format.

Installation:

Installation can be done using npm or yarn. run the following command: NPM:

npm install check-mask-input

YARN:

yarn add check-mask-input

Import:


import { CheckMaskInput } from 'check-mask-input';

or

const { CheckMaskInput } = require('check-mask-input');

INPUT FORMAT FORM

works on any controlled component

    // React
    const [cpf, setCPF] = useState('')
    function handleCPFChange(e: React.ChangeEvent<HTMLInputElement>) {
        const value = e.target.value
        const format = CheckMaskInput.cpf(value).getValue()
        setCPF(format);
    }
    function submitExampleFunction() {
        const checkCPF = CheckMaskInput.cpf(cpf)
        if(!checkCPF.isValid()){
            return 'is Invalid CPF'
        }
        // send to form
        checkCPF.getValue()
        setCPF(format);
    }
    <input
        placeholder="000.000.000-00"
        value={cpf}
        onChange={handleCPFChange}
        className={styles.search}
        maxLength={14}
    />
    <button onClick={() => submitExampleFunction()}>Submit</button>

Usage:

import { CheckMaskInput } from 'check-mask-input';


const CNPJ = CheckMaskInput.cnpj("75114595000105")
console.log('CNPJ', CNPJ.getValue()) //75.114.595/0001-05
console.log('CNPJ', CNPJ.isValid())// Output: true
const PHONE =  CheckMaskInput.phone("1112223333")
console.log('PHONE', PHONE.getValue()) //Output: (111)222-3333
console.log('PHONE', PHONE.isValid())// Output: true
const PHONE_BR =  CheckMaskInput.phoneBR("21996173825")
console.log('PHONE BR', PHONE_BR.getValue()) // Output: (21)99617-3825
console.log('PHONE BR', PHONE_BR.isValid()) // Output: true
const BIRTH = CheckMaskInput.birth("19960107")
console.log('BIRTH', BIRTH.getValue()) // Output: 1996-01-07
console.log('BIRTH', BIRTH.isValid()) // Output: true
const BIRTH_BR = CheckMaskInput.birthBR("07011996")
console.log('BIRTH BR', BIRTH_BR.getValue()) // Output: 07/01/1996
console.log('BIRTH BR', BIRTH_BR.isValid()) // Output: true
const CPF = CheckMaskInput.cpf("14347813058")
console.log('CPF', CPF.getValue()) // Output: 143.478.130-58
console.log('CPF', CPF.isValid()) // Output: true
const CUSTOM = CheckMaskInput.custom("0000000000", "999.99.99.99.9", () => {return true}) //<==== in the custom format you need to define a callback to validate your custom format, since we have no way of knowing which format you expect to receive.
console.log('CUSTOM', CUSTOM.getValue()) // Output: 000.00.00.00.0
console.log('CUSTOM', CUSTOM.isValid()) // Output: true

;(async () => {
    const CEP = CheckMaskInput.cep("22763153") // "22041011" | 22041011
    console.log('CEP', CEP.getValue()) // Output: 22041-011
    console.log('CEP', await CEP.isValid()) // Output: true
    console.log('CEP', CEP.extraData) /* Output: {
                                            cep: '05010-000',
                                            uf: 'SP',
                                            localidade: 'São Paulo',
                                            bairro: 'Perdizes',
                                            logradouro: 'Rua Caiubi'
                                        }*/
})()

Supported Methods

| Feature | Status | | ------------- | ------------- | | cpf | ✅ | | cnpj | ✅ | | phone | ✅ | | phoneBR | ✅ | | birth | ✅ | | birthBR | ✅ | | async cep (using cep-promise) | ✅ | | custom | ✅ |