You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

byte-length

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

byte-length

Get the real byte length of a string.


Version published
Weekly downloads
127K
increased by13.8%
Maintainers
1
Created
Weekly downloads
 

Readme

Source


Byte-Length
API Stability TypeScript Styled with prettier Build status Test Coverage NPM Version Downloads Browser Bundle Size

Calculate the real byte length of any string.

Why

In node many will use Buffer.byteLength, however including the entire buffer shim in the browser just for getting the byte length of a string is not very conservative.

Installation

npm install byte-length

Example

import { byteLength } from "byte-length";

byteLength("hello"); //-> 5
byteLength("😀"); //-> 4
byteLength("fullwidth characters"); //-> 60

Contributions

  • Use npm test to run tests.

Please feel free to create a PR!

Keywords

FAQs

Package last updated on 17 Oct 2017

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc