utf8-byte-length
Get utf8 byte length of string
Last updated 4 years ago by parshap .
WTFPL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install utf8-byte-length 
SYNC missed versions from official npm registry.

utf8-byte-length build status

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.

Current Tags

  • 1.0.4                                ...           latest (4 years ago)

5 Versions

  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 666
This Week 4,993
This Month 29,975
Last Day 1,479
Last Week 8,683
Last Month 27,471
Dependencies (0)
None
Dev Dependencies (1)

Copyright 2014 - 2016 © taobao.org |