Skip to main content

throwIfDoesNotContain

Stentor API Reference


Stentor API Reference / stentor-utils/src / throwIfDoesNotContain

Function: throwIfDoesNotContain()

throwIfDoesNotContain(obj, requiredAttrs, undefinedPermitted?, onError?): void

Defined in: packages/stentor-utils/src/object/index.ts:131

A validation function that can check if an object contains the required attributes and throws an error if they are not part of it.

Parameters​

obj​

object

Object to check

requiredAttrs​

string[]

The attributes in the object that are required.

undefinedPermitted?​

boolean

True if the object is allowed to be undefined. Default is false in which case an error will be thrown.

onError?​

ValidationErrorHandler = defaultValidationErrorHandler

An optional error handler that allows for custom messages or actions. The keys passed in will be the keys that were required but are not inside the object.

Returns​

void