MCPcopy
hub / github.com/feross/spoof / normalize

Function normalize

index.js:459–477  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

457 * @return {string}
458 */
459function 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
479function chunk (str, n) {
480 const arr = []

Callers 4

findInterfacesDarwinFunction · 0.70
findInterfacesLinuxFunction · 0.70
findInterfacesWin32Function · 0.70
getInterfaceMACFunction · 0.70

Calls 1

chunkFunction · 0.85

Tested by

no test coverage detected