UNPKG

nsn-comp

Version:

NSN核心组件

29 lines (22 loc) 615 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cutStrByFullLength = void 0; var _nsnConst = require("nsn-const"); var cutStrByFullLength = function cutStrByFullLength(str, maxLength) { var showLength = 0; return str.split(_nsnConst.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; }, ''); }; exports.cutStrByFullLength = cutStrByFullLength;