prc b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
..
lib b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
.gitmodules b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
.npmignore b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
.travis.yml b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
AUTHORS b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
README.md b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
browser.js b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
index.js b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
package.json b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás
test.js b6c02717e6 Upload complete no-internet building environment. há 1 ano atrás

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.