1.0.0 • Published 3 years ago

validated-function v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

validated-function

Invoke a function until it's return value satisfies a check. Useful for ensuring random IDs are unique within a database.

NPM Badge

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.