diff options
author | Eric Bailey <git@esb.lol> | 2024-02-27 16:04:49 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-27 14:04:49 -0800 |
commit | 978bcc1ba9cb426c8da34a970a79a023936e3dbc (patch) | |
tree | 5023c6caf283e1255a7492947a437bd3795702b5 /src/lib | |
parent | 6717f8f11e69d12bcde3e5601ed02281b927c378 (diff) | |
download | voidsky-978bcc1ba9cb426c8da34a970a79a023936e3dbc.tar.zst |
Tags menu/muted words improvements (#3002)
* Fix translations * Handle loooong words * Truncate on desktop web, revert mobile changes * Break the words * Small enough for mobile web * Fix alignment on mobile web * Clarify
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/strings/helpers.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/lib/strings/helpers.ts b/src/lib/strings/helpers.ts index e2abe9019..de4562d2c 100644 --- a/src/lib/strings/helpers.ts +++ b/src/lib/strings/helpers.ts @@ -8,10 +8,27 @@ export function pluralize(n: number, base: string, plural?: string): string { return base + 's' } -export function enforceLen(str: string, len: number, ellipsis = false): string { +export function enforceLen( + str: string, + len: number, + ellipsis = false, + mode: 'end' | 'middle' = 'end', +): string { str = str || '' if (str.length > len) { - return str.slice(0, len) + (ellipsis ? '...' : '') + if (ellipsis) { + if (mode === 'end') { + return str.slice(0, len) + '…' + } else if (mode === 'middle') { + const half = Math.floor(len / 2) + return str.slice(0, half) + '…' + str.slice(-half) + } else { + // fallback + return str.slice(0, len) + } + } else { + return str.slice(0, len) + } } return str } |