Library for create contract on the type value of a data.
First class support about type union and iterator.
const a = new String('Hello world!');
const b = 'Hello world!';
const c = 15;
const ctString = contract('primitive', String);
// No error
{
if ((contract.validataBool(a, ctString) === false) ||,
(contract.validataBool(c, ctString) === false))
throw new Error('a && b shall be a String!');
}
// Throw error
{
contract.validate(c, ctString, new TypeError('c shall be a String!'));
}
// Create a contract who expect data has Symbol.iterator property and values are wheter Number || Boolean || String
{
contract('iterator', [Number, Boolean, String], 'primitive');
}
![]() |
Used to match primitive data type. Correct if data is an instance of model or an primitive of this. Function composing the model shall be an identifier of object primitives |
Simply a test based on instanceof operator.
Ensure that data is an iterable object and each values corresponding to the model.
subType
arg is required for the call to contract
and model
is complies to that.