Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function length(str, eawOptions) {
let len = 0;
for (const char of str) {
if (eawOptions.alwaysWideChars.has(char)) {
len += 2;
continue;
}
if (eawOptions.alwaysNarrowChars.has(char)) {
len += 1;
continue;
}
switch (getEAW(char)) {
case 'F':
case 'W':
len += 2;
break;
case 'A':
len += eawOptions.ambiguousAsWide ? 2 : 1;
break;
default:
len += 1;
}
}
return len;
}
export function _computeTextWidth(text, options) {
const normalized = options.normalize ? text.normalize("NFC") : text;
let w = 0;
for (const char of normalized) {
if (options.wideChars.has(char)) {
w += 2;
continue;
}
if (options.narrowChars.has(char)) {
w += 1;
continue;
}
switch (getEAW(char)) {
case "F":
case "W":
w += 2;
break;
case "A":
w += options.ambiguousAsWide ? 2 : 1;
break;
default:
w += 1;
}
}
return w;
}