tiinvo

tiinvo / Exports / Assert

Namespace: Assert

Table of contents

Functions

Functions

check

check(a, m): void

Asserts that a specified condition is true, otherwise throws an error with the given message

Example

import { Assert } from 'tiinvo'

Assert.check(true, 'will not throw')     // does not throw
Assert.check(false, 'yup it throws')     // throws

Since

4.0.0

Parameters

Name Type Description
a boolean if true it throws
m string the error message

Returns

void

Defined in

src/Assert.ts:28

check(a): Unary<boolean, void>

Returns a unary function which accepts a boolean which asserts that the argument is true, otherwise throws an error with the given message

Example

import { Assert } from 'tiinvo'

const somecheck = Assert.check(`It's not true!`);

somecheck(true)      // undefined
somecheck(false)     // throws new Error(`It's not true!`)

Since

4.0.0

Parameters

Name Type Description
a string the error message

Returns

Unary<boolean, void>

the unary function which returns

Defined in

src/Assert.ts:51


checkResult

checkResult(a, b): T<boolean>

Asserts that a specified condition is true and returns it, otherwise returns Result.Err with the given errorMessage

Example

import { Assert } from 'tiinvo'

Assert.checkResult(true, 'will not throw')     // true
Assert.checkResult(false, 'yup it throws')     // Error("yup it throws")
Assert.checkResult('will not throw')(true)     // true
Assert.checkResult('yup it throws')(false)     // Error("yup it throws")

Since

4.0.0

Parameters

Name Type Description
a boolean the condition
b string the error message

Returns

T<boolean>

Defined in

src/Assert.ts:92

checkResult(a): Unary<boolean, T<boolean>>

Returns a unary function which asserts that a specified condition is true returning it, otherwise returns Result.Err with the given error message a

Example

import { Assert } from 'tiinvo'

Assert.checkResult('will not throw')(true)     // true
Assert.checkResult('yup it throws')(false)     // Error("yup it throws")

Since

4.0.0

Parameters

Name Type Description
a string the error message

Returns

Unary<boolean, T<boolean>>

the unary function which returns

Defined in

src/Assert.ts:112


make

make<a>(p, m): Unary<a, void>

Creates a check function starting from a Predicate.t<a> and a message.

Example

import { Assert, Num } from 'tiinvo'

const check0 = Assert.make(Num.isEven, 'number is not even')

check0(10)              // does not throw
check0(11)              // throws "number is not even"
check1(10)              // does not throw
check1(11)              // throws "number 11 is not even"

Since

4.0.0

Type parameters

Name Description
a the type passed to the predicate and to the mappable functor (if any)

Parameters

Name Type Description
p T<a> the predicate
m string | Mappable<a, string> the error message or the mappable functor

Returns

Unary<a, void>

the asserting unary function which returns

Defined in

src/Assert.ts:158

make<a>(p): Unary<T<a>, Unary<a, void>>

Creates a check function starting from a Predicate.t<a> and a message.

Example

import { Assert, Num } from 'tiinvo'

const check1 = Assert.make(Num.isEven, x => `number ${x} is not even`)

check0(10)              // does not throw
check0(11)              // throws "number is not even"
check1(10)              // does not throw
check1(11)              // throws "number 11 is not even"

Since

4.0.0

Type parameters

Name Description
a the type passed to the predicate and to the mappable functor (if any)

Parameters

Name Type Description
p string | Mappable<a, string> the error message or the mappable functor

Returns

Unary<T<a>, Unary<a, void>>

the asserting unary function which returns

Defined in

src/Assert.ts:182


makeResult

makeResult<A>(p, m): Unary<A, T<boolean>>

Creates a check function starting from a Predicate.t<a> and a message.

Example

import { Assert, Num } from 'tiinvo'

const check0 = Assert.makeResult(Num.isEven, 'number is not even')
const check1 = Assert.makeResult(Num.isEven, x => `number ${x} is not even`)

check0(10)              // true
check0(11)              // Error("number is not even")
check1(10)              // true
check1(11)              // Error("number 11 is not even")

Since

4.0.0

Type parameters

Name Description
A the type passed to the predicate and to the mappable functor (if any)

Parameters

Name Type Description
p T<A> the asserting predicate
m string | Mappable<A, string> the error message or the mappable functor

Returns

Unary<A, T<boolean>>

the asserting function which returns

Defined in

src/Assert.ts:218

makeResult<A>(p): Unary<T<A>, Unary<A, T<boolean>>>

Creates a check function starting from a a message or a mappable functor.

Example

import { Assert, Num } from 'tiinvo'

const check1 = Assert.makeResult(Num.isEven, x => `number ${x} is not even`)

check0(10)              // true
check0(11)              // Error("number is not even")
check1(10)              // true
check1(11)              // Error("number 11 is not even")

Since

4.0.0

Type parameters

Name Description
A the type passed to the predicate and to the mappable functor (if any)

Parameters

Name Type Description
p string | Mappable<A, string> the error message or the mappable functor

Returns

Unary<T<A>, Unary<A, T<boolean>>>

the asserting unary function which returns

Defined in

src/Assert.ts:242