tty-strings
Version: 
Tools for working with strings displayed in the terminal
24 lines • 976 B
TypeScript
/**
 * A generator function that splits a string into measured graphemes. Does not handle ANSI escape codes,
 * so make sure to remove them from input strings before calling this function.
 *
 * @remarks
 * This function is an implementation of UAX #29 grapheme cluster boundary splitting:
 * {@link https://www.unicode.org/reports/tr29/tr29-21.html#Grapheme_Cluster_Boundaries}
 *
 * @example
 * ```js
 * import { charWidths } from 'tty-strings';
 *
 * // Basic latin characters
 * const chars = [...charWidths('abc')]; // [['a', 1], ['b', 1], ['c', 1]]
 *
 * // Full width emoji characters
 * const emojis = [...charWidths('🙈🙉🙊')]; // [['🙈', 2], ['🙉', 2], ['🙊', 2]]
 * ```
 *
 * @param string - Input string to split.
 * @returns A generator that yields a tuple with each grapheme and its width in the input string.
 */
export default function charWidths(string: string): Generator<readonly [string, number], void>;
//# sourceMappingURL=charWidths.d.ts.map