@ariesclark/number
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published
@ariesclark/number logo

Fast, efficient, and easy-to-use number extensions for TypeScript.

Packages

Installation

npm install @ariesclark/extensions
# Or directly, if you only need the number extension.
npm install @ariesclark/number

Documentation

clamp (function)

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

randomFloat (function)

[object Object],[object Object],[object Object],[object Object],[object Object]

RandomFunction (type)

A random number generator function that returns a float between 0 and 1.

defaultRandom (variable: RandomFunction)

The default random number generator function.

randomFunction (function)

Get the current random number generator function, or set a new one.

Parameters:

  • newValue (RandomFunction) - The new random number generator function, or undefined to get the current value, or null 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.

pseudoRandomFloat (function)

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.

randomInt (function)

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

`{ EPSILON, MAX_SAFE_INTEGER, MAX_VALUE, MIN_SAFE_INTEGER, MIN_VALUE, NEGATIVE_INFINITY,

// eslint-disable-next-line no-shadow-restricted-names NaN, POSITIVE_INFINITY, isFinite, isInteger, isNaN, isSafeInteger, parseFloat, parseInt }` (variable)

sum (function)

Returns the sum of the numbers.

Parameters:

  • numbers (number[]) - The numbers to sum.

returns: number

average (function)

Returns the average of the numbers.

Parameters:

  • numbers (number[]) - The numbers to average.

returns: number

median (function)

Returns the median of the numbers.

Parameters:

  • numbers (number[]) - The numbers to find the median of.

returns: number

Package Sidebar

Install

npm i @ariesclark/number

Weekly Downloads

5

Version

0.3.1

License

MIT

Unpacked Size

15.1 kB

Total Files

22

Last publish

Collaborators

  • ariesclark