LarpixClient/electron/node_modules/truncate-utf8-bytes
olcxja cca8b02fea
Some checks failed
Android Build / publish (push) Successful in 33s
Linux Build / publish (push) Failing after 25s
Update gitignore (sorry)
2026-05-10 14:02:17 +02:00
..
lib Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
.gitmodules Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
.npmignore Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
.travis.yml Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
AUTHORS Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
browser.js Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
index.js Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
package.json Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
README.md Update gitignore (sorry) 2026-05-10 14:02:17 +02:00
test.js Update gitignore (sorry) 2026-05-10 14:02:17 +02:00

truncate-utf8-bytes build status

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

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.