File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
tools/integer-base-converter Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -46,16 +46,16 @@ export function convertBase(
46
46
let decValue = cleanedValue
47
47
. split ( '' )
48
48
. reverse ( )
49
- . reduce ( ( carry : number , digit : string , index : number ) => {
49
+ . reduce ( ( carry : bigint , digit : string , index : number ) => {
50
50
if ( ! fromRange . includes ( digit ) ) {
51
51
throw new Error ( `Invalid digit "${ digit } " for base ${ finalFromBase } .` ) ;
52
52
}
53
- return ( carry += fromRange . indexOf ( digit ) * finalFromBase ** index ) ;
54
- } , 0 ) ;
53
+ return ( carry += BigInt ( fromRange . indexOf ( digit ) ) * BigInt ( finalFromBase ) ** BigInt ( index ) ) ;
54
+ } , 0n ) ;
55
55
let newValue = '' ;
56
56
while ( decValue > 0 ) {
57
- newValue = toRange [ decValue % toBase ] + newValue ;
58
- decValue = ( decValue - ( decValue % toBase ) ) / toBase ;
57
+ newValue = toRange [ Number ( decValue % BigInt ( toBase ) ) ] + newValue ;
58
+ decValue = ( decValue - ( decValue % BigInt ( toBase ) ) ) / BigInt ( toBase ) ;
59
59
}
60
60
return newValue || '0' ;
61
61
}
Original file line number Diff line number Diff line change @@ -26,9 +26,9 @@ export function parseAsCIDR(form: string) {
26
26
return ( ipMatch as IPSubnetwork ) . toString ( ) ;
27
27
}
28
28
if ( ipMatch instanceof IPMask ) {
29
- return ( ipMatch as IPMask ) . convertToSubnet ( ) ?. toString ( ) ;
29
+ return ( ipMatch as IPMask ) . convertToSubnet ( ) ?. toString ( ) || '' ;
30
30
}
31
- return ( ipMatch . convertToMasks ( ) || [ ] ) [ 0 ] ?. convertToSubnet ( ) ?. toString ( ) ;
31
+ return ( ipMatch . convertToMasks ( ) || [ ] ) [ 0 ] ?. convertToSubnet ( ) ?. toString ( ) || '' ;
32
32
}
33
33
34
34
export function getSubnets ( cidr : string ) {
You can’t perform that action at this time.
0 commit comments