prc b6c02717e6 Upload complete no-internet building environment. | il y a 1 an | |
---|---|---|
.. | ||
lib | il y a 1 an | |
.gitmodules | il y a 1 an | |
.npmignore | il y a 1 an | |
.travis.yml | il y a 1 an | |
AUTHORS | il y a 1 an | |
README.md | il y a 1 an | |
browser.js | il y a 1 an | |
index.js | il y a 1 an | |
package.json | il y a 1 an | |
test.js | il y a 1 an |
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.
var truncate = require("truncate-utf8-bytes")
var str = "a☃" // a = 1 byte, ☃ = 3 bytes
console.log(truncate(str, 2))
// -> "a"
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.