string-length
Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes
Last updated 8 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm 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

Current Tags

  • 7.0.1                                ...           latest (10 months ago)

16 Versions

  • 7.0.1                                ...           10 months ago
  • 7.0.0                                ...           10 months ago
  • 6.0.0                                ...           3 years ago
  • 5.0.1                                ...           5 years ago
  • 5.0.0                                ...           5 years ago
  • 4.0.2                                ...           6 years ago
  • 4.0.1                                ...           7 years ago
  • 4.0.0                                ...           7 years ago
  • 3.1.0                                ...           8 years ago
  • 3.0.0                                ...           8 years ago
  • 2.0.0                                ...           9 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           12 years ago
  • 0.1.2                                ...           13 years ago
  • 0.1.1                                ...           13 years ago
  • 0.1.0                                ...           13 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE