import { Validator } from "./Validator" ; import * as bigInt from "big-integer" ; /**
 * A base 16 (hexadecimal) representation of a 16 bit value.
 *
 * It consists of four (base 16) number. ie FFFF
 *
 * It is used to represents the components of an IPv6 address
 */ export class Hexadecatet { private readonly value : number ; /**
     * A convenience method for constructing an instance of  Hexadecatet from a four (base 16) number
     * representation of a 16bit value.
     *
     *  param { string } rawValue returns { Hexadecatet } an instance of  Hexadecatet static fromString ( rawValue ) { return new Hexadecatet ( rawValue ) ; } ; /**
     * A convenience method for constructing an instance of  Hexadecatet from a decimal number representation
     * of a 16 bit value
     *
     *  param { number } rawValue returns { Hexadecatet } an instance of  Hexadecatet static fromNumber ( rawValue ) { return new Hexadecatet ( rawValue ) ; } ; /**
     * Constructor for creating an instance of  Hexadecatet param { string | number } givenValue constructor ( givenValue ) { let hexadecatetValue ; if ( typeof givenValue === 'string' ) { hexadecatetValue = parseInt ( givenValue , 16 ) ; } else { hexadecatetValue = parseInt ( String ( givenValue ) , 16 ) ; } let [ isValid , message ] = Validator . isValidIPv6Hexadecatet ( bigInt ( hexadecatetValue ) ) ; if ( ! isValid ) { throw Error ( message . filter ( msg => { return msg !== '' ; } ) . toString ( ) ) ; } this . value = hexadecatetValue ; } returns { number } public getValue ( ) { return this . value ; } returns { string } public toString ( ) { return this . value . toString ( 16 ) ; } }