string-length
- Version 6.0.0
- Published
- 4.25 kB
- 1 dependency
- 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
Type Aliases
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;//=> 2stringLength('🐴');//=> 1stringLength('\u001B[1municorn\u001B[22m');//=> 7
Type Aliases
type Options
type Options = { /** Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted. They are ignored by default.
@default false */ readonly countAnsiEscapeCodes?: boolean;};
Package Files (1)
Dependencies (1)
Dev Dependencies (3)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto 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>
- Updated .
Package analyzed in 2440 ms. - Missing or incorrect documentation? Open an issue for this package.