VitorLuizC / brazilian-values

🇧🇷 Funções de formatação, conversão e validação para valores, documentos e outras unidades usadas no Brasil. Como CEP, CNPJ, CPF, BRL (R$), datas, números etc.
MIT License
537 stars 38 forks source link

Prettify masked values [HELP NEEDED] [FEATURE REQUEST] #50

Open RichardsonWTR opened 3 years ago

RichardsonWTR commented 3 years ago

The problem

By default the non numeric characters are removed from the string.
I need to pretty print masked phones and CEPs. How can I do it?

Possible solution

Example of possible implementation

formatToCEP('15998030')
//=> '15998-030'

formatToCEP('****8030', { masked: true })
//=> '****8-030'

formatToPhone('11971626799') 
//=> '(11) 9 7162-6799'

formatToPhone('*******6799', { masked: true })
//=> '(**) * ****-6799'

The new method signature could be as follows:

formatToCEP(value, { masked = false, mask_digit = '*' })
formatToPhone(value, { masked  = false, mask_digit = '*' })