* Takes a MAC address in various formats: * * - 00:00:00:00:00:00, * - 00-00-00-00-00-00, * - 0000.0000.0000 * * ... and returns it in the format 00:00:00:00:00:00. * * @param {string} mac * @return {string}
(mac)
| 457 | * @return {string} |
| 458 | */ |
| 459 | function normalize (mac) { |
| 460 | let m = CISCO_MAC_ADDRESS_RE.exec(mac) |
| 461 | if (m) { |
| 462 | const halfwords = m.slice(1) |
| 463 | mac = halfwords.map((halfword) => { |
| 464 | return zeroFill(4, halfword) |
| 465 | }).join('') |
| 466 | return chunk(mac, 2).join(':').toUpperCase() |
| 467 | } |
| 468 | |
| 469 | m = MAC_ADDRESS_RE.exec(mac) |
| 470 | if (m) { |
| 471 | const bytes = m.slice(1) |
| 472 | return bytes |
| 473 | .map(byte => zeroFill(2, byte)) |
| 474 | .join(':') |
| 475 | .toUpperCase() |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | function chunk (str, n) { |
| 480 | const arr = [] |
no test coverage detected