Function that generates a "then" function for Promise that avoid any falsy value by throwing an error.
Falsy values: false, 0, -0, 0n, "", null, undefined, and NaN
import { truthyPromiseOrThrow } from '@helpers4/promise'Promise.resolve(false) .then(truthyPromiseOrThrow('My custom error message')) .then(console.log)// => 'My custom error message'
the error message thrown if the data is falsy
Generated using TypeDoc
Function that generates a "then" function for Promise that avoid any falsy value by throwing an error.
Falsy values: false, 0, -0, 0n, "", null, undefined, and NaN
Example (es module)