string-length (5.0.1)

Published 2026-02-24 14:05:35 +00:00 by atheaadmin

Installation

registry=
npm install string-length@5.0.1
"string-length": "5.0.1"

About this package

string-length

Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes

String#length erroneously counts astral symbols as two characters.

Install

$ npm install string-length

Usage

import stringLength from 'string-length';

'🐴'.length;
//=> 2

stringLength('🐴');
//=> 1

stringLength('\u001B[1municorn\u001B[22m');
//=> 7

API

stringLength(string, options?)

options

Type: object

countAnsiEscapeCodes

Type: boolean
Default: false

Whether ANSI escape codes should be counted. They are ignored by default.


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Dependencies

Dependencies

ID Version
char-regex ^2.0.0
strip-ansi ^7.0.1

Development Dependencies

ID Version
ava ^3.15.0
tsd ^0.17.0
xo ^0.44.0

Keywords

unicode string length size count astral symbol surrogates codepoints ansi escape codes
Details
npm
2026-02-24 14:05:35 +00:00
0
Sindre Sorhus
MIT
latest
2.1 KiB
Assets (1)
Versions (2) View all
4.0.2 2026-02-24
5.0.1 2026-02-24