vega-frontend-monorepo/libs/react-helpers/src/lib/format/strings.ts
Art d271f28b82
feat: page title (660) (#1437)
* feat: page title (660)

* fix: trading-e2e home tests
2022-09-23 16:29:35 +02:00

29 lines
918 B
TypeScript

export const ELLIPSIS = '\u2026';
export function truncateByChars(input: string, start = 6, end = 6) {
// if the text is shorted than the total number of chars to show
// no truncation is needed. Plus one is to account for the ellipsis
if (input.length <= start + end + 1) {
return input;
}
return input.slice(0, start) + ELLIPSIS + input.slice(-end);
}
export function shorten(input: string, limit?: number) {
if (!input || !limit || input.length < limit || limit <= 0) {
return input;
}
const output = input.substring(0, limit - 1);
const suffix = output.length < limit ? ELLIPSIS : '';
return input.substring(0, limit - 1) + suffix;
}
const TITLE_SEPARATOR = ' - ';
const TITLE_SUFFIX = 'Vega';
export function titlefy(words: (string | null | undefined)[]) {
const title = [...words, TITLE_SUFFIX]
.filter((w) => w && w.length > 0)
.join(TITLE_SEPARATOR);
return title;
}