-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(model): add a MAC address (PhysAddr) object
- Loading branch information
Benjamin Reed
committed
Jun 16, 2017
1 parent
c3638a6
commit 6a724e8
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |