Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Feb 27, 2024 via pnpm
Package summary
Share
0
issues
1
license
5
MIT
Package created
16 Jul 2015
Version published
23 Sep 2021
Maintainers
1
Total deps
5
Direct deps
3
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
5 Packages, Including:
ansi-regex@5.0.1
emoji-regex@8.0.0
is-fullwidth-code-point@3.0.0
string-width@4.2.3
strip-ansi@6.0.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

3
All Dependencies CSV
β“˜ This is a list of string-width 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
emoji-regex8.0.06.51 kBMIT
prod
is-fullwidth-code-point3.0.02.12 kBMIT
prod
strip-ansi6.0.11.99 kBMIT
prod

Visualizations

Frequently Asked Questions

What does string-width do?

The string-width npm package provides an effective solution for calculating the visual width of a string, or simply put, the number of columns necessary to display it. This is incredibly useful when dealing with Unicode characters, including fullwidth characters, and command-line output. ANSI escape codes, typically invisible and discounting towards the string's visual length, are automatically stripped off.

How do you use string-width?

Utilizing string-width in your JavaScript project is as easy as installing the package via npm by running npm install string-width, and then importing and calling the function in your code. Here are some code examples:

// Importing the module
import stringWidth from 'string-width';

// Calculating the visual width of a single character
console.log(stringWidth('a')); // Output: 1

// The visual width of a fullwidth character is 2
console.log(stringWidth('叀')); // Output: 2

Moreover, string-width allows toggling of certain features via the options parameter:

// Importing the module
import stringWidth from 'string-width';

// Example of using options
console.log(stringWidth('\u001B[1m叀\u001B[22m', {countAnsiEscapeCodes: true}));  // Output: 2

In the options object, the ambiguousIsNarrow option allows you to count ambiguous width characters as narrow or wide, and the countAnsiEscapeCodes option lets you include ANSI escape codes in the width calculation.

Where are the string-width docs?

For a comprehensive look at the string-width API and the different options available, please refer to the string-width package page on GitHub. It provides an exhaustive explanation on how to use the module along with the data types, default settings, and other details. For use cases outside of Node.js applications, there is also a command-line interface version available named string-width-cli.