(str: string): number Returns the count of graphemes in a string, the individually rendered characters.
str
stringreturns
number 17 declarations
(str: string): number Returns the count of graphemes in a string, the individually rendered characters.
strstringnumber (str: string): string Removes leading and trailing spaces from each line of a string.
strstringstring (source: string, ensured: string): string Adds the substring ensured to the end of the source string if it's not already present.
sourcestringensuredstringstring (source: string, ensured: string): string Adds the substring ensured to the start of the source string if it's not already present.
sourcestringensuredstringstring (value: string): string Escapes a string for use inside a single-quoted JS string literal.
Uses a single-pass regex replacement to escape backslashes, single quotes, newlines, carriage returns, and Unicode line/paragraph separators.
valuestringstring (a: string, b: string): number Calculates the Levenshtein distance between two strings. Useful for typo detection and fuzzy matching.
afirst string
stringbsecond string
stringnumber the edit distance between the strings
(str: string, target_width: number, align?: "left" | "right"): string Pad a string to a target display width (accounting for wide characters).
strstringtarget_widthnumberalign"left" | "right"'left'string (count: number | null | undefined, suffix?: string): string Returns a plural suffix based on a count.
countnumber | null | undefinedsuffixstring's'string (str: string): number Calculate the display width of a string in terminal columns.
- Strips ANSI escape codes (they have 0 width)
- Emojis and other wide characters take 2 columns
- Tab characters take 4 columns
- Newlines and other control characters take 0 columns
- Uses Intl.Segmenter to properly handle grapheme clusters (e.g., family emoji "๐จโ๐ฉโ๐งโ๐ฆ")
strstringnumber (content: string): boolean Check if content appears to be binary.
Checks for null bytes in the first 8KB of content.
contentcontent to check
stringboolean true if content appears to be binary
(value: unknown): string Stringifies a value like JSON.stringify but with some corner cases handled better.
valueunknownstring (source: string, stripped: string): string Removes characters inclusive of stripped.
sourcestringstrippedstringstring (str: string): string Strips ANSI escape sequences from a string.
strstringstring (source: string, stripped: string): string Removes characters inclusive of stripped.
sourcestringstrippedstringstring (source: string, stripped: string): string Removes characters inclusive of stripped.
sourcestringstrippedstringstring (source: string, stripped: string): string Removes characters inclusive of stripped.
sourcestringstrippedstringstring (str: string, maxLength: number, suffix?: string): string Truncates a string to a maximum length, adding a suffix if needed that defaults to ....
strstringmaxLengthnumbersuffixstring'...'string