From c3d0cc55d98fb32b25cd2164cfa1c399985e7c84 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 15 Oct 2024 21:57:28 +0300 Subject: Edit profile dialog ALF refresh (#5633) --- src/lib/strings/helpers.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/lib/strings/helpers.ts') diff --git a/src/lib/strings/helpers.ts b/src/lib/strings/helpers.ts index acd55da2d..ca77c4666 100644 --- a/src/lib/strings/helpers.ts +++ b/src/lib/strings/helpers.ts @@ -41,6 +41,20 @@ export function useEnforceMaxGraphemeCount() { ) } +export function useWarnMaxGraphemeCount({ + text, + maxCount, +}: { + text: string + maxCount: number +}) { + const splitter = useMemo(() => new Graphemer(), []) + + return useMemo(() => { + return splitter.countGraphemes(text) > maxCount + }, [splitter, maxCount, text]) +} + // https://stackoverflow.com/a/52171480 export function toHashCode(str: string, seed = 0): number { let h1 = 0xdeadbeef ^ seed, -- cgit 1.4.1