utf8-byte-length ![build status](https://camo.githubusercontent.com/d72dd3a7afbcbe094e4a1ad2dd1de642d46b23e55d2fffa3d96664129752cd33/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f706172736861702f757466382d627974652d6c656e6774682e7376673f6272616e63683d6d6173746572)
Get the utf8 byte length of a string, taking into account multi-byte characters and surrogate pairs.
By default, this module defers to Buffer.byteLength
. A browser implementation is also provided that doesn't use Buffer.byteLength
minimize build size.
Example
var getLength = require("utf8-byte-length")
console.log(truncate("a☃", 2)) // a = 1 byte, ☃ = 3 bytes
// -> 4
API
var getLength = require("utf8-byte-length")
When using browserify or webpack, this automatically resolves to an implementation that does not use Buffer.byteLength
.
getLength(string)
Returns the byte length of string
. Throws an error if string
is not a string.