# byte-length

> Get the real byte length of a string.

Latest version **1.0.2** (published 2017-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install byte-length
pnpm add byte-length
yarn add byte-length
bun add byte-length
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-10-17 |
| First published | 2015-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Dylan Piercey |
| Maintainers | dylanpiercey |
| Keywords | bytes, content-length, length, string |

## Links

- npm: https://www.npmjs.com/package/byte-length
- Repository: https://github.com/DylanPiercey/byte-length
- Issues: https://github.com/DylanPiercey/byte-length/issues
- npm.io page: https://npm.io/package/byte-length

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2017-10-17
- 1.0.1 — 2017-10-15
- 1.0.0 — 2017-10-15
- 0.1.1 — 2015-12-18
- 0.1.0 — 2015-10-03

## README

<h1 align="center">
  <!-- Logo -->
  <br/>
  Byte-Length
	<br/>

  <!-- Stability -->
  <a href="https://nodejs.org/api/documentation.html#documentation_stability_index">
    <img src="https://img.shields.io/badge/stability-stable-brightgreen.svg" alt="API Stability"/>
  </a>
  <!-- TypeScript -->
  <a href="http://typescriptlang.org">
    <img src="https://img.shields.io/badge/%3C%2F%3E-typescript-blue.svg" alt="TypeScript"/>
  </a>
  <!-- Prettier -->
  <a href="https://github.com/prettier/prettier">
    <img src="https://img.shields.io/badge/styled_with-prettier-ff69b4.svg" alt="Styled with prettier"/>
  </a>
  <!-- Travis build -->
  <a href="https://travis-ci.org/DylanPiercey/byte-length">
  <img src="https://img.shields.io/travis/DylanPiercey/byte-length.svg" alt="Build status"/>
  </a>
  <!-- Coveralls coverage -->
  <a href="https://coveralls.io/github/DylanPiercey/byte-length">
    <img src="https://img.shields.io/coveralls/DylanPiercey/byte-length.svg" alt="Test Coverage"/>
  </a>
  <!-- NPM version -->
  <a href="https://npmjs.org/package/byte-length">
    <img src="https://img.shields.io/npm/v/byte-length.svg" alt="NPM Version"/>
  </a>
  <!-- Downloads -->
  <a href="https://npmjs.org/package/byte-length">
    <img src="https://img.shields.io/npm/dm/byte-length.svg" alt="Downloads"/>
  </a>
  <!-- Size -->
  <a href="https://npmjs.org/package/byte-length">
    <img src="https://img.shields.io/badge/size-422b-green.svg" alt="Browser Bundle Size"/>
  </a>
</h1>

Calculate the real byte length of any string.

# Why
In node many will use `Buffer.byteLength`, however including the entire buffer shim in the browser just for getting the byte length of a string is not very conservative.

# Installation

```console
npm install byte-length
```

# Example

```javascript
import { byteLength } from "byte-length";

byteLength("hello"); //-> 5
byteLength("😀"); //-> 4
byteLength("ｆｕｌｌｗｉｄｔｈ　ｃｈａｒａｃｔｅｒｓ"); //-> 60
```

### Contributions

* Use `npm test` to run tests.

Please feel free to create a PR!

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