1 export const DEFAULT_TRUNCATE_OMISSION = '…';
4 * Truncate `str` to a maximum length `charsToDisplay`.
5 * Appends `omission` if `str` is too long.
7 * The length of the string returned (which may include
8 * the omission) will not exceed `charsToDisplay`.
10 export default function truncate(
16 * Number of characters to display.
20 * The string appended if `str` is too long.
22 omission = DEFAULT_TRUNCATE_OMISSION
24 if (str.length === 0 || str.length <= charsToDisplay) {
28 return str.substring(0, charsToDisplay - omission.length) + omission;