diff --git a/src/core/formatter.ts b/src/core/formatter.ts index 50c2203..85ace3f 100644 --- a/src/core/formatter.ts +++ b/src/core/formatter.ts @@ -1,4 +1,4 @@ -export default { +const formatter = { formatString: function(num: number, kind: string) : string { return num.toString(getBase(kind || "bin")); }, @@ -31,4 +31,8 @@ function getBase(kind:string) : number { } throw new Error("Unsupported kind: " + kind); -} \ No newline at end of file +} + +export default formatter; +const emBin = formatter.emBin; +export {emBin}; \ No newline at end of file diff --git a/src/networking/models.ts b/src/networking/models.ts index f58bb53..646efad 100644 --- a/src/networking/models.ts +++ b/src/networking/models.ts @@ -1,3 +1,5 @@ +import {emBin} from "../core/formatter"; + export type OctetNumber = 1 | 2 | 3 | 4; export type NetworkClass = 'a' | 'b' | 'c' | 'd' | 'e'; @@ -33,6 +35,11 @@ export class IpAddress { return `${this.firstByte}.${this.secondByte}.${this.thirdByte}.${this.fourthByte}`; } + toBinaryString() { + + return `${emBin(this.firstByte)}).${emBin(this.secondByte)}.${emBin(this.thirdByte)}.${emBin(this.fourthByte)}`; + } + clone(): IpAddress { return new IpAddress(this.firstByte, this.secondByte, this.thirdByte, this.fourthByte); }