string-width

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

v9.0.0
MIT
hop.js robot avatar

v9.0.0

9.0.0
8.3.0
8.2.2
8.2.1
8.2.0
8.1.1
8.1.0
8.0.0
7.2.0
7.1.0
7.0.0
6.1.0
6.0.0
5.1.2
5.1.1
5.1.0
5.0.1
5.0.0
4.2.3
4.2.2
4.2.1
4.2.0
4.1.0
4.0.0
3.1.0
3.0.0
2.1.1
2.1.0
2.0.0
1.0.2
1.0.1
1.0.0
Download
Install
Files
<!-- hop.js - Package: string-width  Version: 9.0.0 -->
<script 
	type="text/javascript" 
	src="https://cdn.hopjs.net/npm/string-width@9.0.0/index.js" 
	crossorigin="anonymous" 
	referrerpolicy="no-referrer">
</script>
<!-- End of package -->

        
Copy the code below and paste it into your HTML file.
The package version has been scanned for malware

Readme

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 do not 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.

Package Info
v9.0.0

No known vulnerabilities
0 Low 0 Medium 0 High 0 Critical
504 stars   0 open issues   one year since last commit

Include string-width into your own domain?
Try bunny.net

NPM Statistics

2.9B weekly downloads +26%
22.9B yearly downloads +152%

Dependencies

string-width depends on 2 packages:

  • strip-ansi ~ ^7.2.0
  • get-east-asian-width ~ ^1.7.0

Tags

  string, character, unicode, width, visual, column, columns, fullwidth, full-width, wcwidth, wcswidth, full, ansi, escape, codes, cli, command-line, terminal, console, cjk, chinese, japanese, korean, fixed-width, east-asian-width      

What is HopJS?

hop.js is a privacy-first CDN service powered by bunny.net, designed to offer a free, industry-leading performance with zero logging.

An unhandled error has occurred. Reload 🗙