# utf8-byte-length

> Get utf8 byte length of string

Latest version **1.0.5** (published 2024-05-14) · (WTFPL OR MIT) license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2024-05-14 |
| First published | 2015-11-06 |
| Weekly downloads | 0 |
| License | (WTFPL OR MIT) |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Carl Xiong |
| Maintainers | parshap, carltonf |
| Keywords | utf8 |

## Links

- npm: https://www.npmjs.com/package/utf8-byte-length
- Repository: https://github.com/parshap/utf8-byte-length
- Homepage: https://github.com/parshap/utf8-byte-length#readme
- Issues: https://github.com/parshap/utf8-byte-length/issues
- npm.io page: https://npm.io/package/utf8-byte-length

## Recent versions

- 1.0.5 (latest) — 2024-05-14
- 1.0.4 — 2016-09-29
- 1.0.3 — 2015-11-06
- 1.0.2 — 2015-11-06
- 1.0.1 — 2015-11-06
- 1.0.0 — 2015-11-06

## README

# utf8-byte-length [![build status](https://secure.travis-ci.org/parshap/utf8-byte-length.svg?branch=master)](http://travis-ci.org/parshap/utf8-byte-length)

Get the utf8 byte length of a string, taking into account multi-byte
characters and surrogate pairs.

By default, this module defers to `Buffer.byteLength`. A browser
implementation is also provided that doesn't use `Buffer.byteLength`
minimize build size.

## Example

```js
var getLength = require("utf8-byte-length")
console.log(truncate("a☃", 2)) // a = 1 byte, ☃ = 3 bytes
// -> 4
```

## API

### `var getLength = require("utf8-byte-length")`

*When using browserify or webpack*, this automatically resolves to an
implementation that does not use `Buffer.byteLength`.

### `getLength(string)`

Returns the byte length of `string`. Throws an error if `string` is not
a string.

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