2022-01-27 21:28:04 +00:00
|
|
|
// Copyright 2021-2022 Signal Messenger, LLC
|
2021-10-06 17:37:53 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-01-27 21:28:04 +00:00
|
|
|
import emojiRegex from 'emoji-regex';
|
2021-10-06 17:37:53 +00:00
|
|
|
|
|
|
|
export function isEmojiOnlyText(text: string): boolean {
|
2022-01-27 21:28:04 +00:00
|
|
|
if (text.length === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const regex = emojiRegex();
|
|
|
|
let len = 0;
|
|
|
|
for (const match of text.matchAll(regex)) {
|
|
|
|
// Skipped some non-emoji text, return early
|
|
|
|
if (match.index !== len) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
len += match[0].length;
|
|
|
|
}
|
|
|
|
return len === text.length;
|
2021-10-06 17:37:53 +00:00
|
|
|
}
|