@onesy/utils
Version:
10 lines (8 loc) • 382 B
JavaScript
import is from './is';
const truncate = function (text) {
let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
let sufix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '...';
if (!is('string', text)) return text;
return text.length > maxLength ? text.slice(0, maxLength) + sufix : text;
};
export default truncate;