Socket
Socket
Sign inDemoInstall

utf8-byte-length

Package Overview
Dependencies
0
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    utf8-byte-length

Get utf8 byte length of string


Version published
Weekly downloads
1.8M
decreased by-1.49%
Maintainers
2
Install size
5.69 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 29 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc