-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Feat/519 big emoji messages (#2389)
- Loading branch information
Showing
8 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { hasEmoji, isAllEmoji } from './emojis' | ||
|
||
describe('Emoji Utilities', () => { | ||
it('Should detect an emoji in a string', () => { | ||
expect(hasEmoji('❤️🔥')).toBeTruthy() | ||
expect(hasEmoji('Hello ❤️🔥 Emoji')).toBeTruthy() | ||
expect(hasEmoji('No emoji :-(')).toBeFalsy() | ||
}) | ||
|
||
it('Should detect when a string is all emojis (or spaces)', () => { | ||
expect(isAllEmoji('🙂🙂🙂🙂🙂🙂🙂🙂')).toBeTruthy() | ||
expect(isAllEmoji('🐈⬛❤️🔥🏴')).toBeTruthy() | ||
expect(isAllEmoji('🐈⬛ ❤️🔥 🏴')).toBeTruthy() | ||
expect(isAllEmoji('❤️🔥')).toBeTruthy() | ||
expect(isAllEmoji('🐈⬛')).toBeTruthy() | ||
expect(isAllEmoji('❤️🔥 Emoji')).toBeFalsy() | ||
expect(isAllEmoji('Hello ❤️🔥')).toBeFalsy() | ||
expect(isAllEmoji('Hello ❤️🔥 Emoji')).toBeFalsy() | ||
expect(isAllEmoji('🐈⬛ (Not emoji) 🏴')).toBeFalsy() | ||
expect(isAllEmoji('No emoji :-(')).toBeFalsy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const hasEmoji = (testString: string) => { | ||
// All strings with at least one emoji character should match this | ||
const regExp = /\p{Emoji}/gu | ||
return regExp.test(testString) | ||
} | ||
|
||
export const isAllEmoji = (testString: string) => { | ||
// Detect whether a string is entirely emojis (and whitespace and zero-width-joins, region indicators, etc) | ||
// This may need to be updated as Unicode's Emoji spec is a moving target | ||
const emojiOrWhitespaceRegExp = /^(\p{Emoji}|\p{Emoji_Modifier}|\uFE0F|\u200D|\p{RI}|\uE007F|\s)+$/gu | ||
return emojiOrWhitespaceRegExp.test(testString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters