Ƭ T: number
A number type alias
Since
4.0.0
▸ guard(x
): x is number
Checks (at compile and runtime) if a given parameter x
is a number
Example
import { Num } from 'tiinvo'
const or0 = (x: unknown): t => Num.guard(x) ? x : 0;
or0(10) // 10
or0(20) // 20
or0(-1) // -1
or0(4e12) // 4e12
or0('hello world') // 0
or0(true) // 0
or0(false) // 0
or0({}) // 0
Since
4.0.0
Name | Type | Description |
---|---|---|
x |
unknown |
the value to check |
x is number
▸ cmp(a
, b
): ComparableResult
Compares two numbers a
and b
.
Returns:
a
is greater than b
a
is same of b
b
is greater than a
Example
import { Num } from 'tiinvo';
Num.cmp(1, 1) // 0
Num.cmp(1, 0) // 1
Num.cmp(0, 1) // -1
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left compared number |
b |
number |
the right compared number |
the comparison result
▸ cmp(a
): Unary
<T
, ComparableResult
>
Compares two numbers a
and b
.
Returns:
a
is greater than b
a
is same of b
b
is greater than a
Example
import { Num } from 'tiinvo';
const cmp0 = Num.cmp(0)
cmp0(2) // 1
cmp0(0) // 0
cmp0(-2) // -1
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number to compare |
▸ eq(a
, b
): boolean
Returns true
if two numbers are the same
import { Num } from 'tiinvo';
Num.eq(1, 1) // true
Num.eq(1, 0) // false
Num.eq(0, 1) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the first number |
b |
number |
the last number |
boolean
true if a equals to b
Returns true
if two numbers are the same
import { Num } from 'tiinvo';
const eq1 = Num.eq(1);
eq1(1) // true
eq1(0) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the first number |
the unary function
▸ gt(a
, b
): boolean
Returns true if a
is greater than b
Example
import { Num } from 'tiinvo';
Num.gt(5, -2) // true
Num.gt(5, 12) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
boolean
true if a
is greater than b
▸ gt(a
): Unary
<number
, boolean
>
Returns a unarty function which once called returns true if b
is greater than a
Example
import { Num } from 'tiinvo';
const gt5 = Num.gt(5)
gt5(10) // true
gt5(-2) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
Unary
<number
, boolean
>
the unary function
▸ lt(a
, b
): boolean
Returns true if a
is lesser than b
Example
import { Num } from 'tiinvo';
Num.lt(5, -2) // false
Num.lt(5, 12) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
left number |
b |
number |
right number |
boolean
true if a is less than b
▸ lt(a
): Unary
<number
, boolean
>
Returns a function which once called returns true if b
is less than a
Example
import { Num } from 'tiinvo';
const lt5 = Num.lt(5)
lt5(10) // true
lt5(-2) // false
Since
4.0.0
Name | Type |
---|---|
a |
number |
Unary
<number
, boolean
>
▸ gte(a
, b
): boolean
Returns true if a
is great or equal to b
.
Example
import { Num } from 'tiinvo';
Num.gte(5, -2) // true
Num.gte(5, 12) // false
Num.gte(10, 10) // true
Since
4.0.0
Name | Type |
---|---|
a |
number |
b |
number |
boolean
true if a is greater or equal to b
▸ gte(a
): Unary
<number
, boolean
>
Returns a function which once called returns true if b
is great or equal to a
Example
import { Num } from 'tiinvo';
const gte5 = Num.gte(5)
gte5(10) // false
gte5(5) // false
gte5(-2) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
Unary
<number
, boolean
>
the unary function
▸ lte(a
, b
): boolean
Returns true if a
is less or equal to b
.
Example
import { Num } from 'tiinvo';
Num.lte(5, -2) // false
Num.lte(5, 12) // true
Num.lte(5, 5) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
boolean
true if a is less or equal than b
▸ lte(a
): Unary
<number
, boolean
>
Returns a function which once called returns true if b
is less or equal to a
Example
import { Num } from 'tiinvo';
const lte5 = Num.lte(5)
lte5(5) // true
lte5(10) // false
lte5(-2) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
Unary
<number
, boolean
>
the unary function
▸ ne(a
, b
): boolean
Returns true if a
not equal to b
.
Example
import { Num } from 'tiinvo';
Num.ne(5, -2) // true
Num.ne(5, 12) // true
Num.ne(5, 5) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
boolean
true if a is not equal to b
▸ ne(a
): Unary
<number
, boolean
>
Returns a unary function which once called returns true if b
not equal to a
Example
import { Num } from 'tiinvo';
const ne5 = Num.ne(5)
ne5(5) // false
ne5(10) // true
ne5(-2) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
Unary
<number
, boolean
>
the unary function
▸ map<b
>(m
): (a
: number
) => Error
| b
Maps a number a
to a value Result.t<b>
if a is number
, otherwise returns Err
.
Example
import { Num } from 'tiinvo';
const toHex = Num.map(x => '0x' + x.toString(16))
toHex(10) // 0xa
toHex("a") // Error("a is not a number")
Since
4.0.0
Name |
---|
b |
Name | Type |
---|---|
m |
Mappable <number , b > |
fn
▸ (a
): Error
| b
Name | Type |
---|---|
a |
number |
Error
| b
▸ mapOr<b
>(m
, b
): (a
: number
) => b
Maps a number a
to a value Result.t<b>
if a is number
, otherwise returns b
.
Example
import { Num } from 'tiinvo';
const toHex = Num.mapOr(x => '0x' + x.toString(16), "0x0")
toHex(10) // 0xa
toHex("a") // 0x0
Since
4.0.0
Name |
---|
b |
Name | Type |
---|---|
m |
Mappable <number , b > |
b |
b |
fn
▸ (a
): b
Name | Type |
---|---|
a |
number |
b
▸ isEven(a
): boolean
Returns true if a number x
is even.
Example
import { Num } from 'tiinvo';
Num.isEven(10) // true
Num.isEven(91) // false
Since
4.0.0
Name | Type |
---|---|
a |
number |
boolean
▸ isOdd(a
): boolean
Returns true if a number x
is odd.
Example
import { Num } from 'tiinvo';
Num.isOdd(10) // false
Num.isOdd(91) // true
Since
4.0.0
Name | Type |
---|---|
a |
number |
boolean
▸ isNegative(a
): boolean
Returns true if a number x
is positive.
Example
import { Num } from 'tiinvo';
Num.isNegative(-1) // true
Num.isNegative(10) // false
Since
4.0.0
Name | Type |
---|---|
a |
number |
boolean
▸ isPositive(a
): boolean
Returns true if a number x
is positive.
Example
import { Num } from 'tiinvo';
Num.isPositive(-1) // false
Num.isPositive(10) // true
Since
4.0.0
Name | Type |
---|---|
a |
number |
boolean
▸ toExponential(a
, b
): string
Returns a string containing a number represented in exponential notation.
If a
and b
parameters are passed, b
counts as the fraction digits for a
.
If b
parameter is not passed, returns a Unary<number, string>
function and a
counts as the fraction digits for b
.
Example
import { Num } from 'tiinvo';
Num.toExponential(10, 2) // "1.00e+1"
Since
4.0.0
Name | Type |
---|---|
a |
number |
b |
number |
string
▸ toExponential(a
): Unary
<T
, string
>
Returns a unary function which returns a string containing a number represented in exponential notation.
If a
and b
parameters are passed, b
counts as the fraction digits for a
.
If b
parameter is not passed, returns a Unary<number, string>
function and a
counts as the fraction digits for b
.
Example
import { Num } from 'tiinvo';
Num.toExponential(10)(2) // "2.0000000000e+0"
Since
4.0.0
Name | Type |
---|---|
a |
number |
▸ toFixed(a
, b
): string
Returns a string representing a number in fixed-point notation.
If a
and b
parameters are passed, b
counts as the fraction digits for a
.
If b
parameter is not passed, returns a Unary<number, string>
function and a
counts as the fraction digits for b
.
Example
import { Num } from 'tiinvo';
Num.toFixed(10.505, 2) // "10.51"
Since
4.0.0
Name | Type |
---|---|
a |
number |
b |
number |
string
▸ toFixed(a
): Unary
<T
, string
>
Returns a unary function which returns string representing a number in fixed-point notation.
If a
and b
parameters are passed, b
counts as the fraction digits for a
.
If b
parameter is not passed, returns a Unary<number, string>
function and a
counts as the fraction digits for b
.
Example
import { Num } from 'tiinvo';
Num.toFixed(10.505)(2) // "2.0000000000"
Since
4.0.0
Name | Type |
---|---|
a |
number |
▸ toPrecision(a
, b
): string
Returns a string representing a number in fixed-point notation.
If a
and b
parameters are passed, b
counts as the fraction digits for a
.
If b
parameter is not passed, returns a Unary<number, string>
function and a
counts as the fraction digits for b
.
Example
import { Num } from 'tiinvo';
Num.toPrecision(10, 2) // "10"
Since
4.0.0
Name | Type |
---|---|
a |
number |
b |
number |
string
▸ toPrecision(a
): Unary
<T
, string
>
Returns a unary function which returns a string representing a number in fixed-point notation.
If a
and b
parameters are passed, b
counts as the fraction digits for a
.
If b
parameter is not passed, returns a Unary<number, string>
function and a
counts as the fraction digits for b
.
Example
import { Num } from 'tiinvo';
Num.toPrecision(10)(2) // "2.000000000"
Since
4.0.0
Name | Type |
---|---|
a |
number |
▸ add(a
, b
): T
Adds a
to b
Example
import { Num } from 'tiinvo';
Num.add(5, -2) // 3
Num.add(5, 12) // 17
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the sum
Returns a unary function which adds b
to a
Example
import { Num } from 'tiinvo';
const add5 = Num.add(5)
add5(5) // 10
add5(10) // 15
Retuns
the unary function
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
▸ div(a
, b
): T
Divides a
by b
Example
import { Num } from 'tiinvo';
Num.div(4, 2) // 2
Num.div(12, 3) // 4
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the division
Returns a Unary<number, number>
function which once called divides b
by a
Example
import { Num } from 'tiinvo';
const div2 = Num.div(2)
div2(4) // 2
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
the unary function
▸ mod(a
, b
): T
Returns the modulus of a % b
Example
import { Num } from 'tiinvo';
Num.mod(2, 2) // 0
Num.mod(3, 2) // 1
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the modulus
Returns a Unary<number, number>
function which once
called returns the modulus of b % a
Example
import { Num } from 'tiinvo';
const mod2 = Num.mod(2)
mod2(10) // 0
mod2(15) // 1
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
the unary function
▸ mul(a
, b
): T
Multiplies a
to b
Example
import { Num } from 'tiinvo';
Num.mul(5, -2) // -10
Num.mul(5, 12) // 60
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the multiplication
Returns a Unary<number, number>
function which once called multiplies b
to a
Example
import { Num } from 'tiinvo';
const mul5 = Num.mul(5)
mul5(10) // 50
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
▸ pow(a
, b
): T
Elevates a
by b
Example
import { Num } from 'tiinvo';
Num.pow(2, 3) // 8
Num.pow(3, 2) // 9
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the result
Returns a Unary<number, number>
function which once called elevates b
by a
Example
import { Num } from 'tiinvo';
const pow5 = Num.pow(5)
pow5(10) // 100_000
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the exponent |
▸ root(a
, b
): T
Root of a
under b
Example
import { Num } from 'tiinvo';
Num.root(4, 2) // 2
Num.root(9, 2) // 3
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the result
Returns a Unary<number, number>
function which once called returns the root of b
under a
Example
import { Num } from 'tiinvo';
Num.root(4, 2) // 2
Num.root(9, 2) // 3
const root2 = Num.root(2)
root2(4) // 2
root2(9) // 3
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the root |
▸ sub(a
, b
): T
Subtracts b
to a
Example
import { Num } from 'tiinvo';
Num.sub(5, -2) // 7
Num.sub(5, 12) // -7
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the result
Returns a Unary<number, number>
function which once called subtracts a
to b
Example
import { Num } from 'tiinvo';
const sub5 = Num.sub(5)
sub5(10) // 5
sub5(-2) // -7
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
the unary function
▸ asc(a
, b
): ComparableResult
Compares two numbers a
and b
Great to sort a numeric array in ASC direction.
Example
import { Num } from 'tiinvo';
const collection = [10, 5, 6, 4, 12, 22, 3];
collection.sort(Num.asc) // [3, 4, 5, 6, 10, 12, 22]
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the comparison result
▸ asc(a
): Unary
<T
, ComparableResult
>
Returns a Unary<number, number>
function which once called compares b
and a
Great to sort a numeric array in ASC direction.
Example
import { Num } from 'tiinvo';
const collection = [10, 5, 6, 4, 12, 22, 3];
collection.sort(Num.asc) // [3, 4, 5, 6, 10, 12, 22]
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
the unary function
▸ desc(a
, b
): ComparableResult
Compares two numbers b
and a
Great to sort a numeric array in DESC direction.
Example
import { Num } from 'tiinvo';
const collection = [10, 5, 6, 4, 12, 22, 3];
collection.sort(Num.desc) // [22, 12, 10, 6, 5, 4, 3]
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the left number |
b |
number |
the right number |
the comparison result
▸ desc(a
): Unary
<T
, ComparableResult
>
Returns a Unary<number, number>
function which once called compares a
and b
Great to sort a numeric array in DESC direction.
Example
import { Num } from 'tiinvo';
const collection = [10, 5, 6, 4, 12, 22, 3];
collection.sort(Num.desc) // [22, 12, 10, 6, 5, 4, 3]
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the right number |
the unary function
▸ toBin(a
): string
| Error
Returns a number in binary notation.
If the passed argument at runtime is not a number, an Error will be returned.
Example
import { Num } from 'tiinvo';
Num.toBin(10) // "0b1010"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the number to convert to binary |
string
| Error
the binary string
▸ toHex(a
): string
| Error
Returns a number in hexadecimal notation
If the passed argument at runtime is not a number, an Error will be returned.
Example
import { Num } from 'tiinvo';
Num.toHex(10) // "0xa"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the number to convert to hexadecimal |
string
| Error
the hexadecimal string
▸ toOct(a
): string
| Error
Returns a number in octal notation
If the passed argument at runtime is not a number, an Error will be returned.
Example
import { Num } from 'tiinvo';
Num.toOct(10) // "0o12"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the number to convert to octal |
string
| Error
the octal string
▸ toJSON(a
): string
| Error
Returns a number in json notation.
If the passed argument at runtime is not a number, an Error will be returned.
Example
import { Num } from 'tiinvo';
Num.toJSON(10) // "10"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the number to convert to json value |
string
| Error
the string
▸ toString(a
): string
| Error
Returns a stringified number.
If the passed argument at runtime is not a number, an Error will be returned.
Example
import { Num } from 'tiinvo';
Num.toString(10) // "10"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
number |
the number to convert to string |
string
| Error
the string