UNPKG

tty-strings

Version:

Tools for working with strings displayed in the terminal

48 lines 2.09 kB
/** * Slice a string by character index. Behaves like the native `String.slice()`, except that indexes refer * to grapheme clusters within the string. Negative index values specify a position measured from the * character length of the string. * * @remarks * Input string may contain ANSI escape sequences. Style and hyperlink sequences that apply to the * sliced portion of the string will be preserved, while all other types of control sequences will be * ignored and will not be included in the output slice. * * @example * ```ts * import { sliceChars } from 'tty-strings'; * * const slice = sliceChars('🙈🙉🙊', 0, 2); // '🙈🙉' * ``` * * @param string - Input string to slice. * @param beginIndex - Character index (defaults to `0`) at which to begin the slice. * @param endIndex - Character index before which to end the slice. * @returns The sliced string. */ export declare const sliceChars: (string: string, beginIndex?: number, endIndex?: number) => string; /** * Slice a string by column index. Behaves like the native `String.slice()`, except that indexes account * for the visual width of each character. Negative index values specify a position measured from the * visual width of the string. * * @remarks * Input string may contain ANSI escape sequences. Style and hyperlink sequences that apply to the * sliced portion of the string will be preserved, while all other types of control sequences will be * ignored and will not be included in the output slice. * * @example * ```ts * import { sliceColumns } from 'tty-strings'; * * // '🙈', '🙉', and '🙊' are all full width characters * const slice = sliceColumns('🙈🙉🙊', 0, 2); // '🙈' * ``` * * @param string - Input string to slice. * @param beginIndex - Column index (defaults to `0`) at which to begin the slice. * @param endIndex - Column index before which to end the slice. * @returns The sliced string. */ export declare const sliceColumns: (string: string, beginIndex?: number, endIndex?: number) => string; //# sourceMappingURL=sliceString.d.ts.map