Skip to content

Commit

Permalink
Use for..of loop (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 28, 2022
1 parent 8b84b9b commit 2fe6df9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -23,8 +23,8 @@ export default function stringWidth(string, options = {}) {
const ambiguousCharacterWidth = options.ambiguousIsNarrow ? 1 : 2;
let width = 0;

for (let index = 0; index < string.length; index++) {
const codePoint = string.codePointAt(index);
for (const character of string) {
const codePoint = character.codePointAt(0);

// Ignore control characters
if (codePoint <= 0x1F || (codePoint >= 0x7F && codePoint <= 0x9F)) {
Expand All @@ -36,7 +36,7 @@ export default function stringWidth(string, options = {}) {
continue;
}

const code = eastAsianWidth.eastAsianWidth(string.charAt(index));
const code = eastAsianWidth.eastAsianWidth(character);
switch (code) {
case 'F':
case 'W':
Expand Down

0 comments on commit 2fe6df9

Please sign in to comment.