1.0.0 • Published 3 years ago
validated-function v1.0.0
validated-function
Invoke a function until it's return value satisfies a check. Useful for ensuring random IDs are unique within a database.
Install
npm install validated-function
Usage
const validatedFunction = require("validated-function")
const uniqueId = validatedFunction(randomId, id => !currentIds.includes(id))
console.log(uniqueId())
API
validateFunction(function_, check, options?)
function_
Type: () => any
The function to invoke.
check
Type: (value) => boolean
The function to check the return value.
options
Type: object
maximumTries
Type: number
\
Default: Infinity
The maximum amount of times to invoke the function.
1.0.0
3 years ago