Skip to content

duckafire/is-it

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Is it?

Simple runtime type validator, built upon the Steam of Pipelines concept.

Installing

<!-- 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

User documentation

  • isIt(value: unknown): IsIt: is used as interface to IsIt.

  • class IsIt:

    • constructor(value: unknown): catches a non-undefined value to be validated. It can be a primitive value (except undefined); 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 validate value.

    • 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 if fallback() is not used.

    • val(): boolean: validates the type of the catched value. It throws an exception if required() is used, fallback() is not used, and the catched value is invalid - different type/class.

    • get(): unknown: is equal to val(); returns null if required() and fallback() is not used, and the values catched is invalid.

About

Simple runtime type validator, built upon the Steam of Pipelines concept.

Topics

Resources

License

Stars

Watchers

Forks

Contributors