util-mask
v1.0.2
Published
A library with treatment for several masks.
Downloads
32
Maintainers
Readme
Use mask
A library with treatment for several masks.
Installation
npm install util-mask --save
Available functions
- onlyNumberMask(number: string)
- onlyLetterMask(letter: string)
- onlySpecialCharacterMask(char: string)
- cpfMask(cpf: string)
- unCpfMask(cpf: string)
- isValidCpfMask(cpf: string)
- rgMask(rg: string)
- unRgMask(rg: string)
- cnpjMask(cnpj: string)
- unCnpjMask(cnpj: string)
- cpfCnpjMask(value: string)
- phoneMask(phone: string)
- unPhoneMask(phone: string)
- cepMask(cep: string)
- unCepMask(cep: string)
- dateUsBrMask(date: string)
- dateBrUsMask(date: string)
- decimalNumberMask(number: string)
- capitalizeFirstLetterMask(text: string)
- currencyBRLMask(value: string)
- creditCardDateMask(value: string)
Use
Import the necessary functions from the package:
// Example
import { onlyNumber, onlyLetterMask } from 'util-mask';
Using the masks:
Only Number Mask
console.log(onlyNumberMask('abc12345abc678909abc')); // Output: 123456789
Only Letter Mask
console.log(onlyLetterMask('abc123!@#')); // Output: abc
Only Special Character Mask
console.log(onlySpecialCharacterMask('123!@#abc')); // Output: !@#
Cpf Mask
console.log(cpfMask('12345678909')); // Output: 123.456.789-09
Un Cpf Mask
console.log(unCpfMask('123.456.789-09')); // Output: 12345678909
Is Valid CPF Mask
console.log(isValidCpfMask('123.456.789-09')); // Output: true || false
Rg Mask
console.log(rgMask('112223334')); // Output: 11.222.333-4
Un Rg Mask
console.log(unRgMask('11.222.333-4')); // Output: 112223334
Cnpj Mask
console.log(cnpjMask('11222333444455')); // Output: 11.222.333/4444-55
Un Cnpj Mask
console.log(unCnpjMask('11.222.333/4444-55')); // Output: 11222333444455
Cpf Cnpj Mask
console.log(cpfCnpjMask('11122233344')); // Output: 111.222.333-44
Cpf Cnpj Mask
console.log(cpfCnpjMask('11222333444455')); // Output: 11.222.333/4444-55
Phone Mask
console.log(phoneMask('11222223333')); // Output: (11) 22222-3333
Un Phone Mask
console.log(unPhoneMask('(11) 22222-3333')); // Output: 11222223333
Cep Mask
console.log(cepMask('11111222')); // Output: 11111-222
Un Cep Mask
console.log(unCepMask('11111-222')); // Output: 11111222
Date Us Br Mask
console.log(dateUsBrMask('1111-11-11')); // Output: 11/11/2020
Date Br Us Mask
console.log(dateBrUsMask('11/11/2020')); // Output: 2020-11-11
Decimal Number Mask
console.log(decimalNumberMask('1,1,1,1,1,1,1,')); // Output: 1.1111.11
Capitalize First Letter Mask
console.log(capitalizeFirstLetterMask('test test test')); // Output: Test Test Test
Currency BRL Mask
console.log(currencyBrlMask('111222')); // Output: R$ 111.222,00
Credit Card Date Mask
console.log(creditCardDateMask('1120')); // Output: 11/20