# truncate-utf8-bytes

> Truncate string to given length in bytes

Latest version **1.0.2** (published 2016-09-29) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install truncate-utf8-bytes
pnpm add truncate-utf8-bytes
yarn add truncate-utf8-bytes
bun add truncate-utf8-bytes
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-09-29 |
| First published | 2015-11-06 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | separate (@types/truncate-utf8-bytes) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Carl Xiong |
| Maintainers | carltonf, parshap |
| Keywords | truncate, utf8 |

## Links

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

## Dependencies (1)

- [utf8-byte-length](https://npm.io/package/utf8-byte-length.md) ^1.0.1

## 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) — 2016-09-29
- 1.0.1 — 2015-11-06
- 1.0.0 — 2015-11-06

## README

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

Truncate a string to the given length in bytes. Correctly handles
multi-byte characters and surrogate pairs.

A browser implementation that doesn't use `Buffer.byteLength` is
provided to minimize build size.

## Example

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

## API

### `var truncate = require("truncate-utf8-bytes")`

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

### `truncate(string, length)`

Returns `string` truncated to at most `length` bytes in length.

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