UNPKG

lenye_base

Version:

基础方法

22 lines (17 loc) 546 B
'use strict'; require('./get_tag.js'); require('./is_array.js'); require('./is_string.js'); require('./is_map.js'); require('./is_set.js'); var size = require('./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; }; module.exports = truncate;