about summary refs log tree commit diff
path: root/src/lib/strings/helpers.ts
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-08-30 18:45:49 +0100
committerGitHub <noreply@github.com>2024-08-30 18:45:49 +0100
commitc70ec1ce1aff6072934add1f543576d5200c1b02 (patch)
treeafd3c400517202c513dbe8031799e3259a06b948 /src/lib/strings/helpers.ts
parente7954e590b92b69dad8aabb0085a02e65024837d (diff)
downloadvoidsky-c70ec1ce1aff6072934add1f543576d5200c1b02.tar.zst
[Video] Captions and alt text (#5009)
* video settings modal in composer

* show done button on web

* rm download options

* fix logic for showing settings button

* add language picker (wip)

* subtitle list with language select

* send captions & alt text with video when posting

* style "ensure you have selected a language" text

* include aspect ratio with video

* filter out captions where the lang is not set

* rm log

* fix label and add hint

* minor scrubber fix
Diffstat (limited to 'src/lib/strings/helpers.ts')
-rw-r--r--src/lib/strings/helpers.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/strings/helpers.ts b/src/lib/strings/helpers.ts
index b4ce64fa5..acd55da2d 100644
--- a/src/lib/strings/helpers.ts
+++ b/src/lib/strings/helpers.ts
@@ -1,3 +1,6 @@
+import {useCallback, useMemo} from 'react'
+import Graphemer from 'graphemer'
+
 export function enforceLen(
   str: string,
   len: number,
@@ -23,6 +26,21 @@ export function enforceLen(
   return str
 }
 
+export function useEnforceMaxGraphemeCount() {
+  const splitter = useMemo(() => new Graphemer(), [])
+
+  return useCallback(
+    (text: string, maxCount: number) => {
+      if (splitter.countGraphemes(text) > maxCount) {
+        return splitter.splitGraphemes(text).slice(0, maxCount).join('')
+      } else {
+        return text
+      }
+    },
+    [splitter],
+  )
+}
+
 // https://stackoverflow.com/a/52171480
 export function toHashCode(str: string, seed = 0): number {
   let h1 = 0xdeadbeef ^ seed,