Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 1x 6x 6x 6x 6x 1x | /* eslint-disable no-control-regex */
/**
* 从左到右取字符串,中文算两个字符
* @method str/leftB
* @param {String} str
* @param {Number} lens
* @returns {String} str
* @example
* var $leftB = require('@spore-ui/kit/packages/str/leftB');
* //向汉编致敬
* $leftB('世界真和谐', 6); // '世界真'
*/
var $bLength = require('./bLength');
function leftB(str, lens) {
var s = str.replace(/\*/g, ' ')
.replace(/[^\x00-\xff]/g, '**');
str = str.slice(0, s.slice(0, lens)
.replace(/\*\*/g, ' ')
.replace(/\*/g, '').length);
Iif ($bLength(str) > lens && lens > 0) {
str = str.slice(0, str.length - 1);
}
return str;
}
module.exports = leftB;
|