Files
SlpSoftware/src/cms-client/hero/title.ts
T

18 lines
656 B
TypeScript

/** The lines of a title: split on line breaks, trimmed, empty lines dropped. */
export function titleLines(title: string): string[] {
return title
.split(/\r\n|\r|\n/)
.map((line) => line.trim())
.filter((line) => line !== '');
}
/**
* The text for screen readers and search engines (the sr-only part of the `h1`): the brand prefix, a space and the
* title lines joined with single spaces. Without a prefix only the joined lines.
*/
export function headingFromLines(lines: readonly string[], prefix = ''): string {
const joined = lines.join(' ');
const start = prefix.trim();
return start === '' ? joined : `${start} ${joined}`;
}