string-length
Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes
Last updated 3 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install string-length 
SYNC missed versions from official npm registry.

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.

Related


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.

Current Tags

  • 5.0.1                                ...           latest (3 years ago)

14 Versions

  • 6.0.0                                ...           2 years ago
  • 5.0.1                                ...           3 years ago
  • 5.0.0                                ...           4 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.0.0                                ...           7 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           10 years ago
  • 0.1.2                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (3)

Copyright 2013 - present © cnpmjs.org | Home |