fix: Avatar renders an incorrect symbol if it has emoji (#5184)

This commit is contained in:
Sivin Varghese
2022-08-03 14:11:33 +05:30
committed by GitHub
parent e0cebfaa1a
commit f7d4f39b5c
3 changed files with 22 additions and 1 deletions

View File

@@ -32,3 +32,13 @@ export const hasEmojiSupport = () => {
ctx.fillText('\ud83d\udc28', 0, 0); // U+1F428 KOALA
return ctx.getImageData(offset, offset, 1, 1).data[0] !== 0;
};
export const removeEmoji = text => {
return text
.replace(
/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,
''
)
.replace(/\s+/g, ' ')
.trim();
};

View File

@@ -0,0 +1,7 @@
import { removeEmoji } from '../emoji';
describe('#removeEmoji', () => {
it('returns values without emoji', () => {
expect(removeEmoji('😄Hi👋🏻 there❕')).toEqual('Hi there');
});
});