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

string-length Build Status

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

String#length errornously counts astral symbols as two characters.

Install

$ npm install string-length

Usage

const stringLength = require('string-length');

'????'.length;
//=> 2

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

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

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 (4 years ago)

6 Versions

  • 5.0.1                                ...           4 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           5 years ago
  • 3.1.0                                ...           6 years ago
  • 1.0.1                                ...           10 years ago
  • 2.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org