Skip to content

Commit

Permalink
Support emoji (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytonyjan authored and sindresorhus committed Dec 15, 2018
1 parent 74d8d55 commit 0bc308a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';
const stripAnsi = require('strip-ansi');
const isFullwidthCodePoint = require('is-fullwidth-code-point');
const emojiRegex = require('emoji-regex')();

module.exports = str => {
str = str.replace(emojiRegex, ' ');

if (typeof str !== 'string' || str.length === 0) {
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"fixed-width"
],
"dependencies": {
"emoji-regex": "^7.0.1",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^4.0.0"
},
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ test('main', t => {
t.is(m('안녕하세요'), 10);
t.is(m('A\uD83C\uDE00BC'), 5, 'surrogate');
t.is(m('\u001B[31m\u001B[39m'), 0);
t.is(m('\u{231A}'), 2, '⌚ default emoji presentation character (Emoji_Presentation)');
t.is(m('\u{2194}\u{FE0F}'), 2, '↔️ default text presentation character rendered as emoji');
t.is(m('\u{1F469}'), 2, '👩 emoji modifier base (Emoji_Modifier_Base)');
t.is(m('\u{1F469}\u{1F3FF}'), 2, '👩🏿 emoji modifier base followed by a modifier');
});

test('ignores control characters', t => {
Expand Down

0 comments on commit 0bc308a

Please sign in to comment.