# macaddr

> MAC address parsing and manipulation

Latest version **0.1.1** (published 2021-11-02) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install macaddr
pnpm add macaddr
yarn add macaddr
bun add macaddr
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-11-02 |
| First published | 2017-08-10 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Joyent |
| Maintainers | todd.whiteman, kusor, wyatt, michael.hicks, bahamat, chudley, tchameroy, dbuell, pfmooney, melloc |
| Keywords | mac, macaddr |

## Links

- npm: https://www.npmjs.com/package/macaddr
- Repository: https://github.com/joyent/node-macaddr
- Homepage: https://github.com/joyent/node-macaddr#readme
- Issues: https://github.com/joyent/node-macaddr/issues
- npm.io page: https://npm.io/package/macaddr

## Dependencies (2)

- [jsprim](https://npm.io/package/jsprim.md) ^1.4.0
- [assert-plus](https://npm.io/package/assert-plus.md) ^1.0.0

## Recent versions

- 0.1.1 (latest) — 2021-11-02
- 0.0.1 — 2017-08-14
- 0.0.0 — 2017-08-10

## README

# macaddr

macaddr is a library for parsing and manipulating MAC addresses in JavaScript.

# Installation

    npm install macaddr

# API

## `parse(input)`

Parses a string representing and returns a `MAC` object representing the
address. A MAC address may be in any of the following forms:

- `01:02:03:04:05:06`
- `01-02-03-04-05-06`
- `010203040506`

When using `:` or `-` as a separator, the leading zero in an octet can be
dropped. For example:

- `1:2:3:4:5:6`
- `1-2-3-4-5-6`

If `parse(input)` is called with a number, it is interpreted as a 48-bit
integer representing the MAC address.

## `MAC`

### `MAC#toString([opts])`

Returns the string representation of the MAC address. An optional options
object allows for controlling the output, and takes the following fields:

- `zeroPad` (default: `true`), whether to pad octets that could print as a
  single character with a `0`.
- `separator` (default: `':'`), separator between octets.
- `octetFormatter` (default: (none)), a function that takes the integer
  octet as the argument and returns the formatted octet. If `zeroPad` is
  true, pad up to two characters.

### `MAC#toLong()`

Returns the 48-bit integer representation of the MAC address.

### `MAC#compare(other)`

Compares the MAC address to another `MAC` object, to determine if they
represent the same value. If the other MAC address has a larger 48-bit
representation, this method returns `-1`. If it has a smaller 48-bit
representation, then it returns `1`. If the two addresses are equivalent,
then the result is `0`.

# License

This Source Code Form is subject to the terms of the Mozilla Public License, v.
2.0.  For the full license text see LICENSE, or http://mozilla.org/MPL/2.0/.

Copyright (c) 2017, Joyent, Inc.

---
_Source: https://npm.io/package/macaddr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
