Module: rgjs/num

RGJS6 Num module.

Methods


<static> addLeading0s(num [, len])

Add leading zero's to a number.

Parameters:
Name Type Argument Default Description
num number | string

The number that needs zeroes.

len number <optional>
2

The number of numbers that we want. Defaults to 2.

Returns:

The number that no longer needs zeroes.

Type
string
Example
rgjs.num.addLeading0s(1) // '01'
rgjs.num.addLeading0s(1, 4) / '0001'

<static> addLeadingZeroes()

Add leading zero's to a number.
Alias of addLeading0s().

See:
  • rgjs/num/addLeading0s

<static> addTrailing0s(num [, len])

Add trailing zero's to a float.

Parameters:
Name Type Argument Default Description
num number | string

The number that needs zeroes.

len number <optional>
2

The number of numbers that we want. Defaults to 2.

Returns:

The number that no longer needs zeroes.

Type
string
Example
rgjs.num.addTrailing0s(1) // '1.00'
rgjs.num.addTrailing0s(1.5) // '1.50'
rgjs.num.addTrailing0s(1, 4) / '1.000'

<static> addTrailingZeroes()

Add trailing zero's to a float.
Alias of addTrailing0s().

See:
  • rgjs/num/addTrailing0s

<static> clamp(n [, min] [, max])

Clamp a number between one or two values.

Parameters:
Name Type Argument Description
n number

The number to clamp.

min number <optional>

Optional. The minimum to clamp.

max number <optional>

Optional. The max to clamp.

Example
rgjs.num.clamp(1.1, 0, 1) // 1

<static> isNumeric(n)

Check if a value is numeric.
See http://www.neiland.net/blog/article/javascript-isnumeric/

Parameters:
Name Type Description
n *

A value

Returns:

True if the value is a numeric.

Type
boolean
Example
rgjs.num.isNumeric(1) // true
rgjs.num.isNumeric('1') // true
rgjs.num.isNumeric('') // false