# string2compact

> Convert 'hostname:port' strings to BitTorrent's compact ip/host binary returned by Trackers

Latest version **2.0.2** (published 2026-05-25) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; has provenance.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2026-05-25 |
| First published | 2014-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=12.20.0 |
| Dependencies | 2 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 9 |
| Author | WebTorrent, LLC |
| Maintainers | feross, mafintosh, flet, watson, diegorbaquero, hicom150, jhiesey, webtorrent-bot, alxhotel |
| Keywords | binary, bittorrent, compact, convert, hostname, peer-to-peer, port, torrent, tracker, webtorrent |

## Links

- npm: https://www.npmjs.com/package/string2compact
- Repository: https://github.com/webtorrent/string2compact
- Homepage: https://github.com/webtorrent/string2compact#readme
- Issues: https://github.com/webtorrent/string2compact/issues
- npm.io page: https://npm.io/package/string2compact

## Dependencies (2)

- [ipaddr.js](https://npm.io/package/ipaddr.js.md) 2.0.1
- [addr-to-ip-port](https://npm.io/package/addr-to-ip-port.md) ^2.0.0

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2026-05-25
- 2.0.1 — 2023-01-25
- 2.0.0 — 2022-12-05
- 1.3.2 — 2021-08-04
- 1.3.0 — 2018-07-27
- 1.2.6 — 2018-07-27
- 1.2.5 — 2018-05-09
- 1.2.4 — 2018-05-09
- 1.2.3 — 2018-04-13
- 1.2.2 — 2015-05-05
- 1.2.1 — 2014-12-11
- 1.2.0 — 2014-11-26
- 1.1.2 — 2014-09-18
- 1.1.1 — 2014-05-19
- 1.1.0 — 2014-03-27
- … 1 more at https://npm.io/package/string2compact/versions

## README

# string2compact [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]

[ci-image]: https://github.com/webtorrent/string2compact/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/webtorrent/string2compact/actions/workflows/ci.yml
[npm-image]: https://img.shields.io/npm/v/string2compact.svg
[npm-url]: https://npmjs.org/package/string2compact
[downloads-image]: https://img.shields.io/npm/dm/string2compact.svg
[downloads-url]: https://npmjs.org/package/string2compact
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com

#### Convert 'hostname:port' strings to BitTorrent's compact ip/host binary returned by Trackers

This module is the opposite of [compact2string](https://npmjs.org/package/compact2string). It works in the browser with [browserify](http://browserify.org/). It is used by [WebTorrent](http://webtorrent.io), and more specifically, the [bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker) and [bittorrent-dht](https://github.com/webtorrent/bittorrent-dht) modules.

### install

```
npm install string2compact
```

### usage

#### single string2compact

```js
var string2compact = require('string2compact')
var compact = string2compact('10.10.10.5:65408')
console.log(compact) // new Buffer('0A0A0A05FF80', 'hex')
```

#### tranform multiple into one buffer

```js
var compacts = string2compact([ '10.10.10.5:128', '100.56.58.99:28525' ])
console.log(compacts) // new Buffer('0A0A0A05008064383a636f6d', 'hex')
```

### license

MIT. Copyright (c) [Feross Aboukhadijeh](https://feross.org) and [WebTorrent, LLC](https://webtorrent.io).

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