Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
string-length
Advanced tools
Package description
The string-length npm package is used to get the real length of a string, taking into account Unicode characters and ansi escape codes that might be present in the string. It provides a more accurate count of visual symbols in a string, which can be different from the string's `.length` property due to such characters.
Counting characters in a basic string
This feature allows you to count the number of characters in a basic string, which is straightforward and similar to the native JavaScript `.length` property, but it also correctly handles Unicode characters that are represented by surrogate pairs in JavaScript.
"string-length": "^4.0.1"
Counting characters in a string with Unicode
This feature is particularly useful for strings containing Unicode characters, such as emojis or characters from non-Latin scripts, which may be represented by multiple code units in JavaScript. The `string-length` package accurately counts these as single characters.
"string-length": "^4.0.1"
Counting characters in a string with ansi escape codes
When dealing with strings that include ansi escape codes, such as those used for coloring terminal output, `string-length` can correctly count the visible characters, ignoring the escape codes that do not contribute to the visible length of the string.
"string-length": "^4.0.1"
The `string-width` package is similar to `string-length` in that it calculates the visual width of a string in the terminal, considering Unicode and ansi escape codes. It is useful for aligning output in the terminal or for determining how much visual space a string will take up.
While `strip-ansi` does not directly calculate string length, it is related in that it removes ansi escape codes from a string. This can be used in conjunction with the native `.length` property to determine the visual length of a string that contains such codes.
Readme
Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes
String#length
erroneously counts astral symbols as two characters.
npm install string-length
import stringLength from 'string-length';
'🐴'.length;
//=> 2
stringLength('🐴');
//=> 1
stringLength('\u001B[1municorn\u001B[22m');
//=> 7
Type: object
Type: boolean
Default: false
Whether ANSI escape codes should be counted. They are ignored by default.
FAQs
Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes
The npm package string-length receives a total of 20,780,220 weekly downloads. As such, string-length popularity was classified as popular.
We found that string-length demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.