import { Validator } from "./Validator" ; import bigInt = require ( "big-integer" ) ; /**
 * A binary representation of a 8 bit value.
 *
 * {@see https://en.wikipedia.org/wiki/Octet_(computing)} for more information on Octets
 *
 * An octet is used in the textual representation of an  IPv4 number, where the IP number value is divided
 * into 4 octets
  export class Octet { private readonly value : number ; param { string } rawValue returns { Octet } static fromString ( rawValue ) { return new Octet ( rawValue ) ; } ; param { number } rawValue returns { Octet } static fromNumber ( rawValue ) { return new Octet ( rawValue ) ; } ; param { string | number } givenValue constructor ( givenValue ) { let octetValue ; if ( typeof givenValue === 'string' ) { octetValue = parseInt ( givenValue ) ; } else { octetValue = givenValue ; } let [ isValid , message ] = Validator . isValidIPv4Octet ( bigInt ( octetValue ) ) ; if ( ! isValid ) { throw Error ( message . filter ( msg => { return msg !== '' ; } ) . toString ( ) ) ; } this . value = octetValue ; } returns { number } public getValue ( ) { return this . value ; } returns { string } public toString ( ) { return this . value . toString ( 10 ) ; } }