Simple runtime type validator, built upon the Steam of Pipelines concept.
<!-- CLIENT-SIDE: paste it in your HTML file. -->
<script src="https://cdn.jsdelivr.net/npm/@duckafire/is-it@0.0.1/index.min.js"></script># SERVER-SIDE: run it in your terminal.
npm install @duckafire/is-it
# or
yarn add @duckafire/is-it-
isIt(value: unknown): IsIt: is used as interface toIsIt. -
class IsIt:-
constructor(value: unknown): catches a non-undefined value to be validated. It can be a primitive value (exceptundefined); or an object instance. -
expect(typ: TParent): IsIt: sets the type name of the catched value; or sets the expected class if the catched object instance. -
fallback(value: unknown): IsIt: sets a fallback value to be returned if the catched value is not valid. It does not validatevalue. -
required(): IsIt: defines an exception must be throwed if the catched value is invalid. -
warning(): IsIt: defines a warning must be displayed, in the stdout, if the fallback value is used. It does not have effect iffallback()is not used. -
val(): boolean: validates the type of the catched value. It throws an exception ifrequired()is used,fallback()is not used, and the catched value is invalid - different type/class. -
get(): unknown: is equal toval(); returnsnullifrequired()andfallback()is not used, and the values catched is invalid.
-