So I have two .js files. This is the contract function inside contract.js file:
function contract(preList, post, f) {
// ***YOUR CODE HERE***
for(let i in preList){
if (! preList[i]){
throw " Contract violation in position 1." +
"Expected number but received four. Blame -> Top-level code";
}
}
if(!post){
throw " Contract violation in position 1." +
"Expected number but returned undefined. Blame -> brokenMult";
}
return f;
}
I am trying to involving above contract function:
var contracts = require('contracts');
var contract = contracts.contract;
var isNumber = contracts.isNumber;
var mult = contract(
[isNumber, isNumber],
isNumber,
function mult (x, y) {
return x+y;
});
var brokenMult = contract(
[isNumber, isNumber],
isNumber,
function brokenMult(x, y) {
return undefined;
});
This is where exporting contract function inside contracts.js
module.exports = {
contract: contract,
any: any,
isBoolean: isBoolean,
isDefined: isDefined,
isNumber: isNumber,
isPositive: isPositive,
isNegative: isNegative,
isInteger: Number.isInteger,
isString: isString,
and: and,
or: or,
not: not,
};
For somehow reason TypeError: contract is not a function