JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 222943
  • Score
    100M100P100Q230704F
  • License MIT

Get the real byte length of a string.

Package Exports

  • byte-length

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (byte-length) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


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!