# check-mask-inputs

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

Latest version **1.0.7** (published 2023-05-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install check-mask-inputs
pnpm add check-mask-inputs
yarn add check-mask-inputs
bun add check-mask-inputs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2023-05-07 |
| First published | 2023-04-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jonathan Abas |
| Maintainers | jonathan.abas |
| Keywords | mask, cpf, cep, check, isvalid, cnpj, phone, birth, react, nodeJS, maskinputs |

## Links

- npm: https://www.npmjs.com/package/check-mask-inputs
- Repository: https://github.com/JonhnyDev/check-mask-inputs
- Homepage: https://github.com/JonhnyDev/check-mask-inputs#readme
- Issues: https://github.com/JonhnyDev/check-mask-inputs/issues
- npm.io page: https://npm.io/package/check-mask-inputs

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.4.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.7 (latest) — 2023-05-07
- 1.0.6 — 2023-05-01
- 1.0.5 — 2023-05-01
- 1.0.4 — 2023-05-01
- 1.0.3 — 2023-05-01
- 1.0.2 — 2023-04-30
- 1.0.1 — 2023-04-30
- 1.0.0 — 2023-04-30

## 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:

```bash
npm install check-mask-input
```

YARN:

```bash
yarn add check-mask-input
```

## Import:
```js

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

or

const { CheckMaskInput } = require('check-mask-input');
```
# INPUT FORMAT FORM
# works on any controlled component
```js
    // 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:
```js
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  | ✅  |

---
_Source: https://npm.io/package/check-mask-inputs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
