diff options
| author | Kit Langton <[email protected]> | 2026-03-07 06:25:22 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-07 05:25:22 -0600 |
| commit | bbd0f3a25283b6f9567a04e79d7f6972950ab0a6 (patch) | |
| tree | 56cb41ff9c67749c6fa894fef32bb14cefd73db3 /packages/ui/src/components/text-utils.ts | |
| parent | b7e208b4f1e6641a1cbb1e13f59789c7b7f4c60a (diff) | |
| download | opencode-bbd0f3a25283b6f9567a04e79d7f6972950ab0a6.tar.gz opencode-bbd0f3a25283b6f9567a04e79d7f6972950ab0a6.zip | |
STUPID SEXY TIMELINE (#16420)
Diffstat (limited to 'packages/ui/src/components/text-utils.ts')
| -rw-r--r-- | packages/ui/src/components/text-utils.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/ui/src/components/text-utils.ts b/packages/ui/src/components/text-utils.ts new file mode 100644 index 000000000..c094b5e65 --- /dev/null +++ b/packages/ui/src/components/text-utils.ts @@ -0,0 +1,17 @@ +/** Find the longest common character prefix between two strings. */ +export function commonPrefix(a: string, b: string) { + const ac = Array.from(a) + const bc = Array.from(b) + let i = 0 + while (i < ac.length && i < bc.length && ac[i] === bc[i]) i++ + return { + prefix: ac.slice(0, i).join(""), + aSuffix: ac.slice(i).join(""), + bSuffix: bc.slice(i).join(""), + } +} + +export function list<T>(value: T[] | undefined | null, fallback: T[]): T[] { + if (Array.isArray(value)) return value + return fallback +} |
