@arcanix/validate

Assists in validating arguments

Usage no npm install needed!

<script type="module">
  import arcanixValidate from 'https://cdn.skypack.dev/@arcanix/validate';
</script>

README

Validate

Assists in validating arguments

Install

$ npm install @arcanix/validate

Usage

Validations

Here is the list of validations:

Validation Description
validate(value [, message]) alias for validate.ok()
validate.ok(value [, message]) Checks if value if truthy, if not, throws a ValidationError with the specified message
validate.notNull(value [, message]) Checks if the value if not null, if null, throws a ValidationError with the specified message

Example

const validate = require('@arcanix/validate');

class SomeClass {

  constructor(myFirstArgument, mySecondArgument) {
    this.myFirstArgument = validate(myFirstArgument, 'expected myFirstArgument');
    this.mySecondArgument = validate(mySecondArgument, 'expected mySecondArgument');  
  }

}