Skip to content

Commit af90c79

Browse files
committed
Diacritical marks
1 parent fd00450 commit af90c79

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ node_modules
3131

3232
# Optional REPL history
3333
.node_repl_history
34+
package-lock.json

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const FITZPATRICK_MODIFIER_END = 0x1f3ff
1414
const VARIATION_MODIFIER_START = 0xfe00
1515
const VARIATION_MODIFIER_END = 0xfe0f
1616

17+
const DIACRITICAL_MARKS_START = 0x20D0
18+
const DIACRITICAL_MARKS_END = 0x20FF
19+
1720
const ZWJ = 0x200d
1821

1922
const GRAPHEMS = [
@@ -49,6 +52,9 @@ function runes (string) {
4952
if (isVariationSelector(string[i + increment])) {
5053
increment++
5154
}
55+
if (isDiacriticalMark(string[i + increment])) {
56+
increment++
57+
}
5258
if (isZeroWidthJoiner(string[i + increment])) {
5359
increment++
5460
continue
@@ -114,6 +120,10 @@ function isVariationSelector (string) {
114120
return typeof string === 'string' && betweenInclusive(string.charCodeAt(0), VARIATION_MODIFIER_START, VARIATION_MODIFIER_END)
115121
}
116122

123+
function isDiacriticalMark (string) {
124+
return typeof string === 'string' && betweenInclusive(string.charCodeAt(0), DIACRITICAL_MARKS_START, DIACRITICAL_MARKS_END)
125+
}
126+
117127
function isGraphem (string) {
118128
return typeof string === 'string' && GRAPHEMS.indexOf(string.charCodeAt(0)) !== -1
119129
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"index.js"
3131
],
3232
"devDependencies": {
33-
"ava": "^0.19.1",
33+
"ava": "^0.22.0",
3434
"eslint": "^4.1.1",
3535
"eslint-config-standard": "^10.2.1",
3636
"eslint-plugin-ava": "^4.0.0",

test/runes.js

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ test('✂️ Runes should handle country flags/regional indicator characters',
9494
t.deepEqual(runes('🇦🇸'), ['🇦🇸'])
9595
})
9696

97+
test('✂️ Runes should handle 3️⃣', (t) => {
98+
t.deepEqual(runes('3️⃣'), ['3️⃣'])
99+
})
100+
97101
test('✂️ Runes should handle 🏳️‍🌈', (t) => {
98102
t.deepEqual(runes('🏳️‍🌈'), ['🏳️‍🌈'])
99103
})

0 commit comments

Comments
 (0)