validated-function
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i validated-function

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.02 kB

Total Files

6

Last publish

Collaborators

  • richienb