UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

20 lines (16 loc) 513 B
import './get_tag.js'; import './is_array.js'; import './is_string.js'; import './is_map.js'; import './is_set.js'; import size from './size.js'; /** * Truncates a string up to a specified length. * The default length is 3, and the truncated symbol defaults '...' */ var truncate = function (str) { var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3; var len = size(str); return len > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str; }; export default truncate;