diff --git a/app/javascript/dashboard/components/widgets/Thumbnail.vue b/app/javascript/dashboard/components/widgets/Thumbnail.vue index ea0e0f99a..4bfc729de 100644 --- a/app/javascript/dashboard/components/widgets/Thumbnail.vue +++ b/app/javascript/dashboard/components/widgets/Thumbnail.vue @@ -9,7 +9,7 @@ /> { 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(); +}; diff --git a/app/javascript/shared/helpers/specs/Emoji.spec.js b/app/javascript/shared/helpers/specs/Emoji.spec.js new file mode 100644 index 000000000..f6583e4ea --- /dev/null +++ b/app/javascript/shared/helpers/specs/Emoji.spec.js @@ -0,0 +1,7 @@ +import { removeEmoji } from '../emoji'; + +describe('#removeEmoji', () => { + it('returns values without emoji', () => { + expect(removeEmoji('๐Ÿ˜„Hi๐Ÿ‘‹๐Ÿป thereโ•')).toEqual('Hi there'); + }); +});