Nova-Client/Solar/Launcher/node_modules/truncate-utf8-bytes
2023-03-19 19:32:58 +00:00
..
lib !! 2023-03-19 19:32:58 +00:00
.gitmodules !! 2023-03-19 19:32:58 +00:00
.npmignore !! 2023-03-19 19:32:58 +00:00
.travis.yml !! 2023-03-19 19:32:58 +00:00
AUTHORS !! 2023-03-19 19:32:58 +00:00
browser.js !! 2023-03-19 19:32:58 +00:00
index.js !! 2023-03-19 19:32:58 +00:00
package.json !! 2023-03-19 19:32:58 +00:00
README.md !! 2023-03-19 19:32:58 +00:00
test.js !! 2023-03-19 19:32:58 +00: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.