Skip to content

Commit

Permalink
feat(model): add a MAC address (PhysAddr) object
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Jun 16, 2017
1 parent c3638a6 commit 6a724e8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/model/PhysAddr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Represents a physical (MAC) address.
* @module PhysAddr
*/ /** */
export class PhysAddr {
/** the MAC address string */
public addr: string;

constructor(addr: string) {
this.addr = addr.toUpperCase().replace(/[^0-9A-F]/g, '');
}

/** displayable string */
public toString() {
const asArray = this.addr.split('');
if (asArray.length === 12) {
return asArray[0] + asArray[1] + ':' +
asArray[2] + asArray[3] + ':' +
asArray[4] + asArray[5] + ':' +
asArray[6] + asArray[7] + ':' +
asArray[8] + asArray[9] + ':' +
asArray[10] + asArray[11];
} else {
return this.addr;
}
}
}

0 comments on commit 6a724e8

Please sign in to comment.