Socket
Book a DemoInstallSign in
Socket

stable-function

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stable-function

Ensure a function is stable, meaning the same input always produces the same output

latest
Source
npmnpm
Version
4.0.0
Version published
Maintainers
1
Created
Source

stable-function

Ensure a function is stable, meaning the same input always produces the same output

Useful for stress testing functions in your unit tests to make sure their behaviors are consistent.

Install

npm install stable-function

Usage

import stableFunction from 'stable-function';

stableFunction(() => true);
//=> true

let index = 0;
stableFunction.returnValue(100, () => {
	if (++index === 10) {
		return 'bar';
	}

	return 'foo';
});
//=> 'bar'

API

stableFunction(count?, testFunction)

Returns a boolean whether the output of testFunction was stable.

stableFunction.returnValue(count?, testFunction)

Returns the first differing output of testFunction or the first output if stable.

count

Type: number Default: 1000

The number of times to call the testFunction.

testFunction

Type: function

The function to be tested.

Keywords

stable

FAQs

Package last updated on 04 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts