string-length

  • Version 5.0.1
  • Published
  • 4.63 kB
  • 2 dependencies
  • MIT license

Install

npm i string-length
yarn add string-length
pnpm add string-length

Overview

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

Index

Functions

function stringLength

stringLength: (string: string, options?: Options) => number;
  • Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi).

    String#length erroneously counts [astral symbols](https://web.archive.org/web/20150721114550/http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html) as two characters.

    Example 1

    import stringLength from 'string-length';
    '🐴'.length;
    //=> 2
    stringLength('🐴');
    //=> 1
    stringLength('\u001B[1municorn\u001B[22m');
    //=> 7

Interfaces

interface Options

interface Options {}

    property countAnsiEscapeCodes

    readonly countAnsiEscapeCodes?: boolean;
    • Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted. They are ignored by default.

      false

    Package Files (1)

    Dependencies (2)

    Dev Dependencies (3)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/string-length.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/string-length)
    • HTML
      <a href="https://www.jsdocs.io/package/string-length"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>