Skip to content

Commit 0bc308a

Browse files
tonytonyjansindresorhus
authored andcommittedDec 15, 2018
Support emoji (#17)
1 parent 74d8d55 commit 0bc308a

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed
 

‎index.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use strict';
22
const stripAnsi = require('strip-ansi');
33
const isFullwidthCodePoint = require('is-fullwidth-code-point');
4+
const emojiRegex = require('emoji-regex')();
45

56
module.exports = str => {
7+
str = str.replace(emojiRegex, ' ');
8+
69
if (typeof str !== 'string' || str.length === 0) {
710
return 0;
811
}

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"fixed-width"
4646
],
4747
"dependencies": {
48+
"emoji-regex": "^7.0.1",
4849
"is-fullwidth-code-point": "^2.0.0",
4950
"strip-ansi": "^4.0.0"
5051
},

‎test.js

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ test('main', t => {
1010
t.is(m('안녕하세요'), 10);
1111
t.is(m('A\uD83C\uDE00BC'), 5, 'surrogate');
1212
t.is(m('\u001B[31m\u001B[39m'), 0);
13+
t.is(m('\u{231A}'), 2, '⌚ default emoji presentation character (Emoji_Presentation)');
14+
t.is(m('\u{2194}\u{FE0F}'), 2, '↔️ default text presentation character rendered as emoji');
15+
t.is(m('\u{1F469}'), 2, '👩 emoji modifier base (Emoji_Modifier_Base)');
16+
t.is(m('\u{1F469}\u{1F3FF}'), 2, '👩🏿 emoji modifier base followed by a modifier');
1317
});
1418

1519
test('ignores control characters', t => {

0 commit comments

Comments
 (0)
Please sign in to comment.