hexo/node_modules/ali-oss/lib/common/utils/getStrBytesCount.js

18 lines
470 B
JavaScript
Raw Normal View History

2023-10-03 11:14:36 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStrBytesCount = void 0;
function getStrBytesCount(str) {
let bytesCount = 0;
for (let i = 0; i < str.length; i++) {
const c = str.charAt(i);
if (/^[\u00-\uff]$/.test(c)) {
bytesCount += 1;
}
else {
bytesCount += 2;
}
}
return bytesCount;
}
exports.getStrBytesCount = getStrBytesCount;