Namespace

math

math

The math namespace of Bijou.js, containing functions to validate credit card numbers, animate with JavaScript, generate unique id's and much more!

View Source _copyright.js, line 131

Namespaces

ease

Methods

# static exports.animate(start, end, duration, callback, intervalopt, numopt) → {Number}

Animates a number from one value to another.

Parameters:
Name Type Attributes Default Description
start Number

The initial value of the number in the animation

end Number

The final value of the number in the animation

duration Number

The duration of the animation in milliseconds

callback animateCallback

The callback function to run with the number and the percentage (Between 0 and 1) of the animation.

interval Number <optional>
20

The amount of time to wait between frames in milliseconds.

num animateNumCallback <optional>
(num)=>num

The function to run to manipulate the timing of the animation, for example setting this to (current_number) => current_number **2 would make a simple ease in function. (The value received by this is also between 0 and 1, feel free to use some stuff from _$.ease.FUNCTION_HERE(current_number) to incorporate easy easing!)

View Source math.js, line 157

A unique number representing the setInterval loop used in the animation.

Number
Example
Animates from 50 to 100 over the course of 3 seconds, updating every half second, and writing the current value to the document body.
_$.animate(50,100, 3000, (e) => document.body.innerHTML = (Math.round(e)), 500, (num) => _$.ease.easeInOutQuart(num));

# static exports.equals(a, b)

Tests if two things are equal, like "thing === thing2" but it also works for dates and objects.

Parameters:
Name Type Description
a *

The first thing to test

b *

The second thing to test

View Source math.js, line 61

Examples
console.assert(new Date() === new Date());//Not equal
console.assert(_$.equals(new Date(), new Date()));//Equal!
console.assert({thing: "Thing!"} === {thing: "Thing!"});//Not equal;
console.assert(_$.equals({thing: "Thing!"}, {thing: "Thing!"}))

# static exports.factorial(n) → {Number}

Gets the factorial of a number given.

Parameters:
Name Type Description
n Number

The number to get the factorial of.

View Source math.js, line 98

Number
Example
_$.factorial(3);//6

# static exports.formatNumber(n) → {String}

Formats a number by adding commas to it.

Parameters:
Name Type Description
n Number

The number to format.

View Source math.js, line 282

The formatted string representation of the number.

String
Example
console.log(_$.formatNumber(100000000)); // "100,000,000"

# static exports.gcd(…arr) → {Number}

Gets the greatest common divisor of a list of numbers.

Parameters:
Name Type Attributes Description
arr Number <repeatable>

The numbers to compare

View Source math.js, line 12

The greatest common divisor

Number
Example
_$.gcd(12, 4, 8);//Returns 4

# static exports.isPrime(num) → {boolean}

Tests if a given number is prime.

Parameters:
Name Type Description
num Number

The number to test.

View Source math.js, line 84

Whether the number is prime

boolean
Example
_$.isPrime(11);//True
_$.isPrime(10);//False

# static exports.luhnCheck(num)

Performs the Luhn Check on a number, which is used to validate credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israeli ID Numbers, South African ID Numbers, Greek Social Security Numbers (ΑΜΚΑ), and survey codes appearing on McDonald's, Taco Bell, and Tractor Supply Co. receipts.

Parameters:
Name Type Description
num Number | String

The number or string to check on.

View Source math.js, line 116

Example
- _$.luhnCheck('4485275742308327'); // true
    - _$.luhnCheck(6011329933655299); //  false
    - _$.luhnCheck(123456789); // false

# static exports.primesTo(num) → {Array.<Number>}

Gives an array of prime numbers up to a certain one.

Parameters:
Name Type Description
num Number

The number to give primes to.

View Source math.js, line 220

Returns an array of prime numbers up to the given number.

Array.<Number>
Example
console.log(_$.primesTo(10)); // [2, 3, 5, 7]

# static exports.random(min, max, roundopt, seedopt) → {Number}

Generates a random number between a minimum and maximum number

Parameters:
Name Type Attributes Default Description
min Number

The lowest number that the random value generated can be.

max Number

The highest number that the random value generated can be.

round Boolean <optional>
true

Weather to round the generated number

seed Number <optional>
Math.random()

The seed for the generated number (Between 0 and 1).

View Source math.js, line 245

The random number generated.

Number
Example
console.log(_$.random(0, 100)); // e.g. 47

# static exports.range(start, end) → {Array.<Number>}

Returns an array of the whole numbers (inclusive) between the numbers specified.

Parameters:
Name Type Description
start Number

The start value of the array.

end Number

The end value of the array.

View Source math.js, line 181

An array of whole numbers (inclusive) between the numbers specified.

Array.<Number>
Example
console.log(_$.range(-2, 1)); // [-2, -1, 0, 1]

# static exports.round(number, amount) → {Number}

Rounds a number.

Parameters:
Name Type Description
number Number

The number to round.

amount Number

An optional multiple to round it to.

View Source math.js, line 46

The rounded number

Number
Examples
console.log(_$.round(14, 10));//Logs 10 to the console, as 14 rounded to the nearest 10 is 10.
console.log(_$.round(Math.PI));//Logs 3 to the console.

# static exports.seedRandom(seed) → {Number}

Get a random number from a seed.

Parameters:
Name Type Description
seed number

The seed to use to generate random numbers.

View Source math.js, line 266

The random number from the seed.

Number
Example
console.log(_$.seedRandom(13)); // 0.5663226493634284

# static exports.uuid(seedopt) → {String}

Generates a unique ID from a seed

Parameters:
Name Type Attributes Default Description
seed Number | String <optional>
Math.random()

The seed to use.

View Source math.js, line 198

The UUID

String
Example
console.log(_$.uuid()); // e.g. "863d0193-863d-0193-863d-0193863d0193"