Skip to content

src/decide-reply.ts

13 lines · 587 B · TypeScript
Raw
/**
 * Resolve `decide`'s `reply` input to the text to post on the thread.
 *
 * - `true` posts the decision `reason`.
 * - A non-empty string posts that text.
 * - `false`, missing, or a blank string posts nothing.
 */
export function resolveReplyText(value: unknown, reason: string, exportName: string): string | undefined {
	if (value == null || value === false) return undefined
	if (value === true) return reason
	if (typeof value === 'string') return value.trim() || undefined
	throw new Error(`${exportName}: reply must be true (post the reason) or a string (post that text).`)
}