7.1.0 • Published 4 months ago

string-width v7.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 months ago

string-width

Get the visual width of a string - the number of columns required to display it

Some Unicode characters are fullwidth and use double the normal width. ANSI escape codes are stripped and doesn't affect the width.

Useful to be able to measure the actual width of command-line output.

Install

npm install string-width

Usage

import stringWidth from 'string-width';

stringWidth('a');
//=> 1

stringWidth('古');
//=> 2

stringWidth('\u001B[1m古\u001B[22m');
//=> 2

API

stringWidth(string, options?)

string

Type: string

The string to be counted.

options

Type: object

ambiguousIsNarrow

Type: boolean\ Default: true

Count ambiguous width characters as having narrow width (count of 1) instead of wide width (count of 2).

Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). If the context cannot be established reliably, they should be treated as narrow characters by default.

countAnsiEscapeCodes

Type: boolean\ Default: false

Whether ANSI escape codes should be counted.

Related

yargswrap-ansicliuiinquirertablewide-aligngaugewidest-lineboxenansi-alignoracli-truncatecli-table3stylelintgulp-clicli-uxcli-progresscuc-gaf@bidalgo/ui-kit@prisma/internals@prisma/sdk@huyhpham/rn-lineastro-no-undiciarchetype-librarybalena-cli@borderfreefinancial/elements-reactcomponennentteasy-select-rnvuedragdropuploadimagesreact-native-bluetooth2killi8n-react-native-fast-imagepipihomelazy-modules-testrn-send-sms@turbo/clispecify-importsbabel-specify-importscad-cli@icanpm/api-mastergew-nodejs-api-client@arisageha/react-lazyload@arisageha/react-lazyload-fix@oneplanetcrowd/developersfoshata-markdownrdclr-boilerplate@cashremit/cr-streamline-icons@ootsuho/menu@gongt/micro-build@almeidaa/msreact-native-template-rfbasewebpack-bundle-deltacloud-archive-s3airscanairscan-examplebb-chatreact-native-esc-pos-sahaabhikari-core@borisovart/atol-kkt-module@frxf/frxfbackend-storiesdeneme323112@evangodon/lr@texttree/demo-bsa-reference-rclwokyweki@ntt_app/react-native-custom-notification@msikma/stringwrap-cjkreact-native-custom-text-hwjames@sonammalhotra/lotide@smishra17/lotide@cheapthrills/lotidediscord-music-botsreact-native-covid-sdkweky-updatedeasycommands-betagql_din_modbitgetreact-native-thanh-toast-librarymutasi-bcamonochromishmy-patches-inquirersalut_gongjang_first_module@jttechnic/interpreter@thanhnguyen14797/react-native-thanh-toast-library@l1nyanm1ng/react-picture-viewer@jackub/inquirer@saeon/quick-formauto-extractcthpb-plugin-socialmango-timezone@iobroker-community-adapters/iobroker.device-watcher@olivervorasai/slidermysql-formatreact-native-printer-brothersrn-pdf-reader-offlineintuireq@newhorizon-tech/dd-npm-package-templatereact-native-shekhar-bridge-testcogoportutilsukor-remaster
7.1.0

4 months ago

7.0.0

7 months ago

6.1.0

1 year ago

6.0.0

1 year ago

5.1.2

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

4.2.3

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.2.2

3 years ago

4.2.1

3 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

8 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago