Skip to main content

@rtorcato/js-common / validation

validation

Functions

isDefined()

isDefined<T>(value): value is T

Defined in: validation/index.ts:15

Checks if a value is defined (not null or undefined).

Example

isDefined(0) // true
isDefined('') // true
isDefined(null) // false
isDefined(undefined) // false

Type Parameters

T

T

Parameters

value

T | null | undefined

The value to check.

Returns

value is T


isString()

isString(value): value is string

Defined in: validation/index.ts:33

Check if a value is a string.

Example

isString('hi') // true
isString(42) // false
isString(new String('hi')) // false (boxed, not a primitive)

Parameters

value

unknown

The value to check.

Returns

value is string

true if the value is a string, false otherwise.


isNumber()

isNumber(value): value is number

Defined in: validation/index.ts:51

Checks if a value is a number (and not NaN).

Example

isNumber(42) // true
isNumber(Number.NaN) // false
isNumber('42') // false

Parameters

value

unknown

The value to check.

Returns

value is number


isBoolean()

isBoolean(value): value is boolean

Defined in: validation/index.ts:61

Checks if a value is a boolean.

Parameters

value

unknown

The value to check.

Returns

value is boolean


isArray()

isArray(value): value is unknown[]

Defined in: validation/index.ts:71

Checks if a value is an array.

Parameters

value

unknown

The value to check.

Returns

value is unknown[]


isObject()

isObject(value): value is object

Defined in: validation/index.ts:81

Checks if a value is an object (but not null or array).

Parameters

value

unknown

The value to check.

Returns

value is object


isEmail()

isEmail(str): boolean

Defined in: validation/index.ts:90

Checks if a string is a valid email address (simple regex).

Parameters

str

string

The string to check.

Returns

boolean


isUrl()

isUrl(str): boolean

Defined in: validation/index.ts:101

Checks if a string is a valid URL.

Parameters

str

string

The string to check.

Returns

boolean