const formatter = { formatString : function ( num , kind ) : string { return num . toString ( getBase ( kind || "bin" ) ) ; } , padLeft : function ( str , length , symbol ) : string { var sb = Array . prototype . slice . call ( str ) , symbol = symbol || "0" ; if ( length == null ) { return str ; } while ( length > sb . length ) { sb . unshift ( symbol ) ; } return sb . join ( '' ) ; } , bin ( number ) { return this . formatString ( number , 'bin' ) ; } , emBin ( number ) { return this . padLeft ( this . bin ( number ) , 8 , '0' ) ; } , splitByMasks ( ipAddrBin , mask1 , mask2 ) { var res = [ ] ; var tmp = [ ] ; var mask = 0 ; var b = mask1 ; ipAddrBin . split ( '' ) . forEach ( ch => { tmp . push ( ch ) ; if ( ch === "." ) { return ; } mask ++ ; if ( mask == b ) { b = mask2 ; res . push ( tmp . join ( '' ) ) ; tmp = [ ] ; } } ) ; if ( tmp . length > 0 ) res . push ( tmp . join ( '' ) ) ; return { vpc : res [ 0 ] , subnet : res [ 1 ] , hosts : res [ 2 ] } ; } } ; function getBase ( kind ) { switch ( kind ) { case 'bin' : return 2 ; case 'hex' : return 16 ; case 'dec' : return 10 ; } throw new Error ( "Unsupported kind: " + kind ) ; } const emBin = formatter . emBin . bind ( formatter ) ; const padLeft = formatter . padLeft . bind ( formatter ) ; export { emBin , padLeft } ; export default formatter ;