chuwanghui 6d115466a5 electron库 | 6 years ago | |
---|---|---|
.. | ||
lib | 6 years ago | |
.gitmodules | 6 years ago | |
.npmignore | 6 years ago | |
.travis.yml | 6 years ago | |
AUTHORS | 6 years ago | |
README.md | 6 years ago | |
browser.js | 6 years ago | |
index.js | 6 years ago | |
package.json | 6 years ago | |
test.js | 6 years ago |
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.