UNPKG

@yookue/ts-lang-utils

Version:

Common lang utilities for typescript

14 lines 485 B
export function abbreviate(text) { var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; var placeholder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '...'; if (!text || width < 0 || width >= text.length) { return text; } if (width === 0) { return ''; } if (width <= placeholder.length) { return placeholder.substring(0, width); } return text.substring(0, width - placeholder.length) + placeholder; }