14 lines · 622 BRaw
| 1 | import { MAX_BODY_LENGTH, MAX_TITLE_LENGTH } from "./contract/limits.ts"; |
| 2 | |
| 3 | export function titleError(title: string): string | undefined { |
| 4 | if (!title || title.length > MAX_TITLE_LENGTH) return `Title must be 1–${MAX_TITLE_LENGTH} characters.`; |
| 5 | } |
| 6 | |
| 7 | export function bodyError(body: string, what = "Description"): string | undefined { |
| 8 | if (body.length > MAX_BODY_LENGTH) return `${what} is too long.`; |
| 9 | } |
| 10 | |
| 11 | /** A body that must not be empty, such as a comment or a reply. */ |
| 12 | export function requiredBodyError(body: string, what: string, empty: string): string | undefined { |
| 13 | return body ? bodyError(body, what) : empty; |
| 14 | } |