|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | # string-length
|
|---|
| 2 |
|
|---|
| 3 | > Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi)
|
|---|
| 4 |
|
|---|
| 5 | `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.
|
|---|
| 6 |
|
|---|
| 7 | ## Install
|
|---|
| 8 |
|
|---|
| 9 | ```
|
|---|
| 10 | $ npm install string-length
|
|---|
| 11 | ```
|
|---|
| 12 |
|
|---|
| 13 | ## Usage
|
|---|
| 14 |
|
|---|
| 15 | ```js
|
|---|
| 16 | const stringLength = require('string-length');
|
|---|
| 17 |
|
|---|
| 18 | '🐴'.length;
|
|---|
| 19 | //=> 2
|
|---|
| 20 |
|
|---|
| 21 | stringLength('🐴');
|
|---|
| 22 | //=> 1
|
|---|
| 23 |
|
|---|
| 24 | stringLength('\u001B[1municorn\u001B[22m');
|
|---|
| 25 | //=> 7
|
|---|
| 26 | ```
|
|---|
| 27 |
|
|---|
| 28 | ## Related
|
|---|
| 29 |
|
|---|
| 30 | - [string-length-cli](https://github.com/LitoMore/string-length-cli) - CLI for this module
|
|---|
| 31 | - [string-width](https://github.com/sindresorhus/string-width) - Get visual width of a string
|
|---|
| 32 |
|
|---|
| 33 | ---
|
|---|
| 34 |
|
|---|
| 35 | <div align="center">
|
|---|
| 36 | <b>
|
|---|
| 37 | <a href="https://tidelift.com/subscription/pkg/npm-string-length?utm_source=npm-string-length&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|---|
| 38 | </b>
|
|---|
| 39 | <br>
|
|---|
| 40 | <sub>
|
|---|
| 41 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|---|
| 42 | </sub>
|
|---|
| 43 | </div>
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.