r/javascript • u/ClickOk5811 • 3h ago
AskJS [AskJS] Utility functions named like verbs are the worst API design in JS libraries
I keep running into the same API design pattern in JS and TS libraries, and it quietly causes production bugs:
import { format, parse, validate } from 'some-lib'
format(date) // "2026-11-27" or "11/27/2026" depending on locale?
parse(input) // throws? returns null? returns the input unchanged?
validate(email) // true/false? or throws a ValidationError?The function names are verbs. They sound obvious. But the contract is anything but obvious.
format might respect the system locale, or it might not. It might throw on invalid input, or return null, or return the input unchanged. parse might be strict, lenient, or silently coerce. validate might return a boolean or throw.
The problem isn't any single library. It's that the ecosystem has converged on verb-named utilities without a shared contract. So every time I switch libraries, I re-learn whether parse throws on garbage input or swallows it.
Compare that to something like Date.prototype.toISOString(). The name is boring, but the behavior is exact. No locale surprises, no silent coercion, no guessing.
I'm starting to think libraries should name these functions after what they actually do, not after the general idea:
formatDateToISO(date) // exact contract
parseEmailStrict(input) // throws on invalid
isValidEmail(email) // boolean, never throwsMore verbose, yes. But you can read the call site and know what happens without checking docs.
What's your take? Do you prefer short verb names with documented behavior, or longer names that encode the contract? And have you ever been burned by a parse or validate that behaved differently than you expected?