tiinvo

tiinvo / Exports / Num

Namespace: Num

Table of contents

Type Aliases

Guardables

Comparables

Mappables

Predicates

Natives

Operables

Sortables

Serializables

Type Aliases

T

Ƭ T: number

A number type alias

Since

4.0.0

Defined in

src/Num.ts:9

Guardables

guard

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

Parameters

Name Type Description
x unknown the value to check

Returns

x is number

Defined in

src/Functors.ts:338

Comparables

cmp

cmp(a, b): ComparableResult

Compares two numbers a and b.

Returns:

Example

import { Num } from 'tiinvo';

Num.cmp(1, 1)  // 0
Num.cmp(1, 0)  // 1
Num.cmp(0, 1)  // -1

Since

4.0.0

Parameters

Name Type Description
a number the left compared number
b number the right compared number

Returns

ComparableResult

the comparison result

Defined in

src/Num.ts:71

cmp(a): Unary<T, ComparableResult>

Compares two numbers a and b.

Returns:

Example

import { Num } from 'tiinvo';

const cmp0 = Num.cmp(0)

cmp0(2)   // 1
cmp0(0)   // 0
cmp0(-2)  // -1

Since

4.0.0

Parameters

Name Type Description
a number the right number to compare

Returns

Unary<T, ComparableResult>

Defined in

src/Num.ts:97


eq

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

Parameters

Name Type Description
a number the first number
b number the last number

Returns

boolean

true if a equals to b

Defined in

src/Num.ts:128

eq(a): Unary<T, boolean>

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

Parameters

Name Type Description
a number the first number

Returns

Unary<T, boolean>

the unary function

Defined in

src/Num.ts:146


gt

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

boolean

true if a is greater than b

Defined in

src/Num.ts:170

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

Parameters

Name Type Description
a number the right number

Returns

Unary<number, boolean>

the unary function

Defined in

src/Num.ts:190


lt

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

Parameters

Name Type Description
a number left number
b number right number

Returns

boolean

true if a is less than b

Defined in

src/Num.ts:219

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

Parameters

Name Type
a number

Returns

Unary<number, boolean>

Defined in

src/Num.ts:237


gte

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

Parameters

Name Type
a number
b number

Returns

boolean

true if a is greater or equal to b

Defined in

src/Num.ts:265

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

Parameters

Name Type Description
a number the right number

Returns

Unary<number, boolean>

the unary function

Defined in

src/Num.ts:286


lte

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

boolean

true if a is less or equal than b

Defined in

src/Num.ts:316

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

Parameters

Name Type Description
a number the right number

Returns

Unary<number, boolean>

the unary function

Defined in

src/Num.ts:337


ne

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

boolean

true if a is not equal to b

Defined in

src/Num.ts:367

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

Parameters

Name Type Description
a number the right number

Returns

Unary<number, boolean>

the unary function

Defined in

src/Num.ts:388

Mappables

map

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

Type parameters

Name
b

Parameters

Name Type
m Mappable<number, b>

Returns

fn

▸ (a): Error | b

Parameters
Name Type
a number
Returns

Error | b

Defined in

src/Num.ts:420


mapOr

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

Type parameters

Name
b

Parameters

Name Type
m Mappable<number, b>
b b

Returns

fn

▸ (a): b

Parameters
Name Type
a number
Returns

b

Defined in

src/Num.ts:439

Predicates

isEven

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

Parameters

Name Type
a number

Returns

boolean

Defined in

src/Functors.ts:442


isOdd

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

Parameters

Name Type
a number

Returns

boolean

Defined in

src/Functors.ts:442


isNegative

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

Parameters

Name Type
a number

Returns

boolean

Defined in

src/Functors.ts:442


isPositive

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

Parameters

Name Type
a number

Returns

boolean

Defined in

src/Functors.ts:442

Natives

toExponential

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

Parameters

Name Type
a number
b number

Returns

string

Defined in

src/Num.ts:535

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

Parameters

Name Type
a number

Returns

Unary<T, string>

Defined in

src/Num.ts:554


toFixed

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

Parameters

Name Type
a number
b number

Returns

string

Defined in

src/Num.ts:583

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

Parameters

Name Type
a number

Returns

Unary<T, string>

Defined in

src/Num.ts:602


toPrecision

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

Parameters

Name Type
a number
b number

Returns

string

Defined in

src/Num.ts:631

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

Parameters

Name Type
a number

Returns

Unary<T, string>

Defined in

src/Num.ts:650

Operables

add

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

T

the sum

Defined in

src/Num.ts:683

add(a): Unary<T, T>

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

Parameters

Name Type Description
a number the right number

Returns

Unary<T, T>

Defined in

src/Num.ts:703


div

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

T

the division

Defined in

src/Num.ts:732

div(a): Unary<T, T>

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

Parameters

Name Type Description
a number the right number

Returns

Unary<T, T>

the unary function

Defined in

src/Num.ts:751


mod

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

T

the modulus

Defined in

src/Num.ts:780

mod(a): Unary<T, T>

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

Parameters

Name Type Description
a number the right number

Returns

Unary<T, T>

the unary function

Defined in

src/Num.ts:801


mul

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

T

the multiplication

Defined in

src/Num.ts:830

mul(a): Unary<T, T>

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

Parameters

Name Type Description
a number the right number

Returns

Unary<T, T>

Defined in

src/Num.ts:848


pow

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

T

the result

Defined in

src/Num.ts:877

pow(a): Unary<T, T>

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

Parameters

Name Type Description
a number the exponent

Returns

Unary<T, T>

Defined in

src/Num.ts:895


root

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

T

the result

Defined in

src/Num.ts:924

root(a): Unary<T, T>

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

Parameters

Name Type Description
a number the root

Returns

Unary<T, T>

Defined in

src/Num.ts:946


sub

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

T

the result

Defined in

src/Num.ts:975

sub(a): Unary<T, T>

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

Parameters

Name Type Description
a number the right number

Returns

Unary<T, T>

the unary function

Defined in

src/Num.ts:995

Sortables

asc

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

ComparableResult

the comparison result

Defined in

src/Num.ts:1031

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

Parameters

Name Type Description
a number the right number

Returns

Unary<T, ComparableResult>

the unary function

Defined in

src/Num.ts:1052


desc

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

Parameters

Name Type Description
a number the left number
b number the right number

Returns

ComparableResult

the comparison result

Defined in

src/Num.ts:1084

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

Parameters

Name Type Description
a number the right number

Returns

Unary<T, ComparableResult>

the unary function

Defined in

src/Num.ts:1105

Serializables

toBin

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

Parameters

Name Type Description
a number the number to convert to binary

Returns

string | Error

the binary string

Defined in

src/Num.ts:420


toHex

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

Parameters

Name Type Description
a number the number to convert to hexadecimal

Returns

string | Error

the hexadecimal string

Defined in

src/Num.ts:420


toOct

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

Parameters

Name Type Description
a number the number to convert to octal

Returns

string | Error

the octal string

Defined in

src/Num.ts:420


toJSON

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

Parameters

Name Type Description
a number the number to convert to json value

Returns

string | Error

the string

Defined in

src/Num.ts:420


toString

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

Parameters

Name Type Description
a number the number to convert to string

Returns

string | Error

the string

Defined in

src/Num.ts:420