0.1.1 • Published 7 months ago

universal-mask v0.1.1

Weekly downloads
-
License
“MIT”
Repository
github
Last release
7 months ago

universal-mask

This is an npm package that provides functions to apply masks to CPF and CNPJ numbers, as well as allowing the application of masks to general values. It is useful for dynamic formatting.

Installation

To install this package, you can use npm. Open your terminal and run the following command:

npm i universal-mask
yarn add universal-mask

Usage

Here's how you can use this package:

const {     
    applyMask,
    formatDocumento,
    maskCPF,
    maskCNPJ
    } = require('../universal-mask');

// First, you pass the mask in the object {number-of-characters: mask}, then the value as a string
// Note that only numbers are allowed
// Build your mask: X becomes the value, and special characters remain the same
const maskedValueObj = applyMask({11:'xx.xxx.xxx-xx'}, '12345678901');
console.log(maskedValueObj); // Output: '12.345.678-90'

// Apply a mask to a number based on size
const maskedValue2ObjCPF = applyMask({11:'xx.xxx.xxx-xx', 14:'12.345.678/9012-34'}, '12345678901234');
console.log(maskedValue2ObjCPF); // Output: '12.345.678/9012-34'

const maskedValue2ObjCNPJ = applyMask({11:'xx.xxx.xxx-xx', 14:'12.345.678/9012-34'}, '12345678901234');
console.log(maskedValue2ObjCNPJ); // Output: '12.345.678/9012-34'

// Apply a mask to a CPF
const cpfMasked = maskCPF('12345678901');
console.log(cpfMasked); // Output: '123.456.789-01'

// Apply a mask to a CNPJ
const cnpjMasked = maskCNPJ('12345678901234');
console.log(cnpjMasked); // Output: '12.345.678/9012-34'

// Apply a mask to a CPF or CNPJ
const formattedCPFMasked = formatDocumento('12345678901');
console.log(formattedCPFMasked); // Output: '123.456.789-01'

const formattedCNPJMasked = formatDocumento('12345678901234');
console.log(formattedCNPJMasked); // Output: '12.345.678/9012-34'

Please note that the package assumes that the input numbers consist of only numeric digits, and CPF numbers should have 11 digits, while CNPJ numbers should have 14 digits.

Contribution

If you encounter issues or wish to contribute improvements, feel free to open an issue or send a pull request on the GitHub repository.

License

This package is distributed under the MIT license. Please refer to the LICENSE file for more details.

Author

Acknowledgments: We thank all the contributors who made this package possible.

0.1.1

7 months ago

0.1.0

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago