call .check() upon any function, and pass a string or a function to see if your arguments pass this test, otherwise it will throw an error.
This makes javascript functions to accept static types rather than dynamic, and reduces run-time bugs
function add7(x){
return x + 7;
}
//desired behavior:
add7(3); //returns -> 10
//undesired:
add7('3'); //returns -> "37"
//solution:
add7.check('number',3); //returns -> 10, just as normal add7()
add7.check('number','3'); //throws -> Uncaught TypeError: 3 is not of type number
function isInteger(data){
return data === parseInt(data, 10)
}
add7.check(isInteger,3.4); // Uncaught TypeError: 3.4 is not passing isInteger check
someFunc(['boolean', Array.isArray, isInteger], true, [23,4,5], 3);
add7OnlyToInts = add7.check.add(isInteger)
add7OnlyToInts(3.4) //throws
add7.check.add(isInteger)(3.4)