Innovenergy_trunk/frontend/node_modules/truncate-utf8-bytes
Kim 085d7c68ba adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
..
lib adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
.gitmodules adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
.npmignore adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
.travis.yml adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
AUTHORS adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
README.md adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
browser.js adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
index.js adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
package.json adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00
test.js adding untracked frontend and typescript files 2023-02-21 07:27:20 +01:00

README.md

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.