rem, strLength(..) 추가

master
mjkhan21 4 weeks ago
parent e43c075831
commit 07f404053e

@ -29,6 +29,29 @@ function trim(s) {
return s.replace(/^\s+/, "").replace(/\s+$/, "");
}
function strLength(str) {
let length = 0;
for (let i = 0; i < str.length; i++) {
let char = str.charCodeAt(i);
if (char <= 0x7F) {
length += 1; // 영문, 숫자, 일부 특수문자
} else if (char <= 0x7FF) {
length += 2;
} else if (char <= 0xFFFF) {
length += 3; // 한글, 한자 등
} else {
length += 4; // 이모지 등
}
}
return length;
}
const rem = {
base: parseFloat(getComputedStyle(document.documentElement).fontSize),
toPx(r) {return r * rem.base + "px";},
fromPx(px) {return px / rem.base + "rem";}
};
function isEmpty(v) {
if (v == undefined
|| v == "undefined"

Loading…
Cancel
Save