@sendbird/uikit-react
Version:
Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.
21 lines (20 loc) • 1.14 kB
TypeScript
/**
* Truncate `filename` to fit within `maxChars` by inserting `...` near the
* middle while preserving the file extension. If the filename already fits,
* returns it unchanged. If the extension alone exceeds the budget, the
* extension is dropped and the head is truncated.
*
* The utility operates on Unicode code points (after NFC normalization), so
* Hangul syllables stay intact even when the input is decomposed jamo (as
* macOS produces), and surrogate pairs (emoji, supplementary CJK) are never
* split. The caller is responsible for picking a `maxChars` that fits the
* rendered container.
*
* Examples:
* truncateMiddleKeepExtension('File-name-is-too-long.pdf', 14) -> 'File...ong.pdf'
* truncateMiddleKeepExtension('short.pdf', 14) -> 'short.pdf'
* truncateMiddleKeepExtension('noextension', 14) -> 'noextension'
* truncateMiddleKeepExtension('verylong.tar.gz', 10) -> 've...tar.gz'
* truncateMiddleKeepExtension('long', 3) -> '...'
*/
export declare function truncateMiddleKeepExtension(filename: string, maxChars: number): string;