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

16 Versions

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

Copyright 2013 - present © cnpmjs.org | Home |