Invoke a function until it's return value satisfies a check. Useful for ensuring random IDs are unique within a database.
npm install validated-function
const validatedFunction = require("validated-function")
const uniqueId = validatedFunction(randomId, id => !currentIds.includes(id))
console.log(uniqueId())
Type: () => any
The function to invoke.
Type: (value) => boolean
The function to check the return value.
Type: object
Type: number
Default: Infinity
The maximum amount of times to invoke the function.