diff --git a/index.js b/index.js index bbc49d2..6dd33ee 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/package.json b/package.json index 89f0b6a..62ca913 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "fixed-width" ], "dependencies": { + "emoji-regex": "^7.0.1", "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^4.0.0" }, diff --git a/test.js b/test.js index a5e894b..291f799 100644 --- a/test.js +++ b/test.js @@ -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 => {