Skip to content

Commit

Permalink
Support combining characters (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
gucong3000 authored and sindresorhus committed Jul 18, 2017
1 parent 175b26f commit 2af7be5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ module.exports = str => {
for (let i = 0; i < str.length; i++) {
const code = str.codePointAt(i);

// Ignore control characters
if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
// Ignore control characters & combining characters
if (code <= 0x1F || (code >= 0x7F && code <= 0x9F) || (code >= 0x300 && code <= 0x36F)) {
continue;
}

// Surrogates
if (code >= 0x10000) {
if (code > 0xFFFF) {
i++;
}

Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ test('ignores control characters', t => {
t.is(m('\u001B'), 0);
});

test.failing('handles combining characters', t => {
test('handles combining characters', t => {
t.is(m('x\u0300'), 1);
});

0 comments on commit 2af7be5

Please sign in to comment.