Evaluation

Evaluation API allows for evaluating value against expectation as boolean - without throwing errors.

TypeScript API

Evaluates if provided value is instance of ≤T≥:

is

is≤T≥(value: any, isStrict?: boolean): boolean

Evaluates if a value matches an expectation.

Parameters:

NameTypeDescription
valueanyValue that needs to evaluated.
isStrictbooleanFlag indicating that evaluation should be done in strict mode.

Returns: boolean

Returns true if evaluation is successful, else false.


import { expect } from 'chai';
import { is } from 'typend';
expect(is<string>('im-a-string')).to.be.true;
expect(is<number>('im-not-a-number')).to.be.false;

instanceOf

instanceOf≤T≥(value: any): boolean

Evaluates if provided value is an instance of a specific type or interface.

Parameters:

NameTypeDescription
valueanyValue that needs to evaluated.

Returns: boolean

Returns true if evaluation is successful, else false.

import { expect } from 'chai';
import { instanceOf } from 'typend';
interface Person {
firstName: string;
lastName: string;
height: number;
getName(): string;
}
expect(
instanceOf<Person>({
firstName: 'Jane',
lastName: 'Doe',
height: 175,
getName(): string {
return `${this.firstName} ${this.lastName}`;
},
})
).to.be.true;
expect(
instanceOf<Person>({
firstName: 'Jane',
lastName: 'Doe',
height: 175,
})
).to.be.false;

JavaScript API

isInstanceOf

isInstanceOf(value: any, expectation: Expectation | Utility, isStrict?: boolean): boolean

Evaluates if provided value is an instance of a specific type or interface :

Parameters:

NameTypeDescription
valueanyValue that needs to evaluated.
expectationExpectation | UtilityExpectation as explicit Pattern instance, instance of Utility or implicit expectation against which value will be validated.

Returns: boolean

Returns true if evaluation is successful, else false.

import { expect } from 'chai';
import { isInstanceOf, convert } from 'typend';
interface Person {
firstName: string;
lastName: string;
height: number;
getName(): string;
}
expect(
isInstanceOf(
{
firstName: 'Jane',
lastName: 'Doe',
height: 175,
getName(): string {
return `${this.firstName} ${this.lastName}`;
},
},
convert<Person>()
)
).to.be.true;
expect(
isInstanceOf(
{
firstName: 'Jane',
lastName: 'Doe',
height: 175,
},
convert<Person>()
)
).to.be.false;