Skip to content

Function: trimToNull()

trimToNull(value): string | null

Trim value and return null for non-strings, undefined, or strings that are empty after trimming. Lets call sites collapse the common

typeof v === "string" && v.trim() ? v.trim() : null

dance into a single helper. Useful for HTTP header / query / form extractors where downstream code wants string | null to drive a cheap ?? / if (x) cascade.

unknown

string | null