JSFiddle - React, Tailwind, and code Playground
JavaScript
var Number = function(val) {
if(typeof(val) === 'number') {
return {
is: function($) {
if (!eval($)) throw $;
}
};
}
function TypeError(message) {
this.message = message;
}
TypeError.prototype.toString = function () {
return 'TypeError: ' + this.message;
}
throw new TypeError('Not a number!');
};
var a = 5;
var b = 'foo';
// should pass
Number(a).is('a > 0');
// should fail
Number(b);
// TODO: implement checkers for other main types
// TODO: figure out how to deal with variadic case (ie. Number or Array)
// -> just use the old assert for this?