npm.io
0.1.5 • Published 5 years ago

@whi/skeptic

Licence
ISC
Version
0.1.5
Deps
1
Size
21 kB
Vulns
0
Weekly
0

Skeptic

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.

Overview

These validation methods cover more complex scenarios and throw specific error types where assert statements would only throw AssertionError.

Usage

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