A quality control validation library built on top of @whi/serious-error-types
. It enables
developers to clearly state input/output assumptions in their code.
These validation methods cover more complex scenarios and throw specific error types where assert
statements would only throw AssertionError
.
const { SeriousErrors,
FunctionIO,
DatabaseIO } = require('@whi/skeptic');
function user ( name, age ) {
FunctionIO.validateArguments(arguments, [
FunctionIO.requiredArgumentType("string", "User's Name"),
FunctionIO.optionalArgumentType("number", "User's Age"),
]);
}
user();
// throws MissingArgumentError
user( 22 );
// throws InvalidArgumentError
user( "Dave" );
// will not throw
user( "Dave", null );
// throws InvalidArgumentError
user( "Dave", 22 );
// will not throw