UNPKG

nsn-comp

Version:

NSN核心组件

22 lines (17 loc) 467 B
import { NConst } from 'nsn-const'; var cutStrByFullLength = function cutStrByFullLength(str, maxLength) { var showLength = 0; return str.split(NConst.EMPTY).reduce(function (pre, cur) { var charCode = cur.charCodeAt(0); if (charCode >= 0 && charCode <= 128) { showLength += 1; } else { showLength += 2; } if (showLength <= maxLength) { return pre + cur; } return pre; }, ''); }; export { cutStrByFullLength };