Brave Traveller
TTCTheo's Typesafe Cult
•Created by Brave Traveller on 10/23/2024 in #questions
One line param checking question
in javascript, you want to:
1. inside of a function (let's call this
functionA
), run a function once (let's cal this function functionB
)
2. check the return value of functionB
3. IF the return value of functionB
is truthy or meets a certain criteria, you return from the parent scope that called it (functionA
).
one example could be checking required params for an API endpoint and returning early with an error message if any are missing.
it's trivial to abstract out of the route handler a generic param checker. I just wish there was a way to make param checking just one line in the route handler.
are there any clever tricks I'm not thinking of?3 replies