signal-desktop/ts/util/isEmojiOnlyText.tsx
2023-01-03 11:55:46 -08:00

22 lines
491 B
TypeScript

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import emojiRegex from 'emoji-regex';
export function isEmojiOnlyText(text: string): boolean {
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;
}