Skip to content

KBE3D / KBCore / Cesium / Check

变量: Check

const Check: { defined: asserts test is NonNullable<T>; typeOf: { string: asserts test is string; func: asserts test is Function; object: asserts test is Record<string | number | symbol, any>; bool: asserts test is boolean; bigint: asserts test is bigint; number: {(name: string, test: any): void; lessThan: asserts test is number; lessThanOrEquals: asserts test is number; greaterThan: asserts test is number; greaterThanOrEquals: asserts test is number; equals: void; }; }; }

Contains functions for checking that supplied arguments are of a specified type or meet specified conditions

类型声明

defined()

defined<T>(name: string, test: T): asserts test is NonNullable<T>

Throws if test is not defined

类型参数

T

T

参数

name

string

The name of the variable being tested

test

T

The value that is to be checked

返回

asserts test is NonNullable<T>

Exception

test must be defined

typeOf

typeOf: { string: asserts test is string; func: asserts test is Function; object: asserts test is Record<string | number | symbol, any>; bool: asserts test is boolean; bigint: asserts test is bigint; number: {(name: string, test: any): void; lessThan: asserts test is number; lessThanOrEquals: asserts test is number; greaterThan: asserts test is number; greaterThanOrEquals: asserts test is number; equals: void; }; }

Contains type checking functions, all using the typeof operator

typeOf.string()

string(name: string, test: any): asserts test is string

Throws if test is not typeof 'string'

参数
name

string

The name of the variable being tested

test

any

The value to test

返回

asserts test is string

Exception

test must be typeof 'string'

typeOf.func()

func(name: string, test: any): asserts test is Function

Throws if test is not typeof 'function'

参数
name

string

The name of the variable being tested

test

any

The value to test

返回

asserts test is Function

Exception

test must be typeof 'function'

typeOf.object()

object(name: string, test: any): asserts test is Record<string | number | symbol, any>

Throws if test is not typeof 'object'

参数
name

string

The name of the variable being tested

test

any

The value to test

返回

asserts test is Record<string | number | symbol, any>

Exception

test must be typeof 'object'

typeOf.bool()

bool(name: string, test: any): asserts test is boolean

Throws if test is not typeof 'boolean'

参数
name

string

The name of the variable being tested

test

any

The value to test

返回

asserts test is boolean

Exception

test must be typeof 'boolean'

typeOf.bigint()

bigint(name: string, test: any): asserts test is bigint

Throws if test is not typeof 'bigint'

参数
name

string

The name of the variable being tested

test

any

The value to test

返回

asserts test is bigint

Exception

test must be typeof 'bigint'

typeOf.number

number: {(name: string, test: any): void; lessThan: asserts test is number; lessThanOrEquals: asserts test is number; greaterThan: asserts test is number; greaterThanOrEquals: asserts test is number; equals: void; }

Throws if test is not typeof 'number'

参数
name

string

The name of the variable being tested

test

any

The value to test

返回

void

Exception

test must be typeof 'number'

typeOf.number.lessThan()

lessThan(name: string, test: any, limit: number): asserts test is number

Throws if test is not typeof 'number' and less than limit

参数
name

string

The name of the variable being tested

test

any

The value to test

limit

number

The limit value to compare against

返回

asserts test is number

Exception

test must be typeof 'number' and less than limit

typeOf.number.lessThanOrEquals()

lessThanOrEquals(name: string, test: any, limit: number): asserts test is number

Throws if test is not typeof 'number' and less than or equal to limit

参数
name

string

The name of the variable being tested

test

any

The value to test

limit

number

The limit value to compare against

返回

asserts test is number

Exception

test must be typeof 'number' and less than or equal to limit

typeOf.number.greaterThan()

greaterThan(name: string, test: any, limit: number): asserts test is number

Throws if test is not typeof 'number' and greater than limit

参数
name

string

The name of the variable being tested

test

any

The value to test

limit

number

The limit value to compare against

返回

asserts test is number

Exception

test must be typeof 'number' and greater than limit

typeOf.number.greaterThanOrEquals()

greaterThanOrEquals(name: string, test: any, limit: number): asserts test is number

Throws if test is not typeof 'number' and greater than or equal to limit

参数
name

string

The name of the variable being tested

test

any

The value to test

limit

number

The limit value to compare against

返回

asserts test is number

Exception

test must be typeof 'number' and greater than or equal to limit

typeOf.number.equals()

equals(name1: string, name2: string, test1: any, test2: any): void

Throws if test1 and test2 is not typeof 'number' and not equal in value

参数
name1

string

The name of the first variable being tested

name2

string

The name of the second variable being tested against

test1

any

The value to test

test2

any

The value to test against

返回

void

Exception

test1 and test2 should be type of 'number' and be equal in value

KBE3D @3.0.0 Copyright © 2024-present KBE3D