brazilian-values icon indicating copy to clipboard operation
brazilian-values copied to clipboard

Prettify masked values [HELP NEEDED] [FEATURE REQUEST]

Open RichardsonWTR opened this issue 3 years ago • 0 comments

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 = '*' })

RichardsonWTR avatar Jul 13 '21 20:07 RichardsonWTR