Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB // SPDX-License-Identifier: Apache-2.0 /** * @module Utils/MetadataUtils * @description Shared helpers for article metadata generation. */ /** Maximum length for a title suffix before truncation */ const MAX_SUFFIX_LENGTH = 60; /** Minimum title length to be considered meaningful (not placeholder) */ export const MIN_MEANINGFUL_TITLE_LENGTH = 10; /** * Return singular or plural form based on count. * * @param n - Item count * @param singular - Singular form * @param plural - Plural form * @returns `"N singular"` or `"N plural"` */ export function pl(n: number, singular: string, plural: string): string { return `${n} ${n === 1 ? singular : plural}`; } /** * Truncate a title string to the suffix length limit with ellipsis. * Used by all strategy title suffix builders for consistent truncation. * * @param title - Title string to truncate * @param maxLength - Maximum length (default: {@link MAX_SUFFIX_LENGTH}) * @returns Truncated title with `...` suffix if over limit, else unchanged */ export function truncateTitle(title: string, maxLength: number = MAX_SUFFIX_LENGTH): string { if (title.length <= maxLength) return title; return title.slice(0, maxLength - 3) + '...'; } |