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 | 1x 1x | /**
* 取字符串 utf8 编码长度,from 王集鹄
* @method str/sizeOfUTF8String
* @param {String} str
* @returns {Number} 字符串长度
* @example
* var $sizeOfUTF8String = require('@spore-ui/kit/packages/str/sizeOfUTF8String');
* $sizeOfUTF8String('中文cc'); //return 8
*/
function sizeOfUTF8String(str) {
return (
typeof unescape !== 'undefined'
? unescape(encodeURIComponent(str)).length
: new ArrayBuffer(str, 'utf8').length
);
}
module.exports = sizeOfUTF8String;
|