Fast, efficient, and easy-to-use number extensions for TypeScript.
npm install @ariesclark/extensions
# Or directly, if you only need the number extension.
npm install @ariesclark/number
Clamps a number within the range specified by the minimum and maximum values.
Parameters:
- /**
- The value to clamp.
*/
value (
number
)
- /**
- The minimum value, inclusive.
*/
minimum (
number
)
- /**
- The maximum value, inclusive.
*/
maximum (
number
)
returns: number
[object Object],[object Object],[object Object],[object Object],[object Object]
A random number generator function that returns a float between 0 and 1.
The default random number generator function.
Get the current random number generator function, or set a new one.
Parameters:
- newValue (
RandomFunction
) - The new random number generator function, orundefined
to get the current value, ornull
to reset to the default.
returns: RandomFunction
import { randomFunction } from '@ariesclark/number/random-function';
import { randomInt } from '@ariesclark/number/random-int';
randomInt(); // Random number between 0 and 100.
randomFunction(() => 0.5);
randomInt(); // Always 50.
Create a pseudo-random number generator from a seed.
Parameters:
- seed (
string
)
returns: RandomFunction
import {
pseudoRandomFloat,
randomFunction,
randomInt
} from '@ariesclark/number';
randomFunction(pseudoRandomFloat('hello world'));
randomInt(); // Predictable random number, based on the seed.
Get a random value between minimum
and maximum
.
Parameters:
- /**
- The minimum value, inclusive, defaults to
0
*/ minimum (number
)
- /**
- The maximum value, inclusive, defaults to
100
*/ maximum (number
)
- /**
- The random number generator function.
*/
random (
RandomFunction
)
returns: number
// eslint-disable-next-line no-shadow-restricted-names NaN, POSITIVE_INFINITY, isFinite, isInteger, isNaN, isSafeInteger, parseFloat, parseInt }` (variable)
Returns the sum of the numbers.
Parameters:
- numbers (
number[]
) - The numbers to sum.
returns: number
Returns the average of the numbers.
Parameters:
- numbers (
number[]
) - The numbers to average.
returns: number
Returns the median of the numbers.
Parameters:
- numbers (
number[]
) - The numbers to find the median of.
returns: number