File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,25 +4,15 @@ import { sanitizeToDigits } from "../_internals/sanitize-to-digits/sanitize-to-d
44export type FormatCnpjOptions = Pick < FormatParams , "pad" > & { version ?: 1 | 2 } ;
55
66const sanitize = (
7- value : string | number ,
8- version ?: FormatCnpjOptions [ "version" ] ,
7+ value : string | number ,
8+ version ?: FormatCnpjOptions [ "version" ] ,
99) => {
10- if ( version === 2 ) {
11- const allowedChars = "0123456789ABCDFGHIJKLMNPQRSVWXYZ" ;
12- const enhancedValue = value . toString ( ) ;
13-
14- let result = "" ;
15-
16- for ( let i = 0 ; i < enhancedValue . length ; i ++ ) {
17- if ( allowedChars . includes ( enhancedValue [ i ] . toUpperCase ( ) ) ) {
18- result += enhancedValue [ i ] . toUpperCase ( ) ;
19- }
20- }
21-
22- return result ;
23- }
10+ if ( version === 2 ) {
11+ const enhancedValue = value . toString ( ) ;
12+ return enhancedValue . replace ( / [ ^ A - Z a - z 0 - 9 ] / g, '' ) . toUpperCase ( ) ;
13+ }
2414
25- return sanitizeToDigits ( value ) ;
15+ return sanitizeToDigits ( value ) ;
2616} ;
2717
2818/**
You can’t perform that action at this time.
0 commit comments