Files
BitwiseCmd/src.old/js/core/should.js
Borys_Levytskyi de0dfba04f React boilerplate
2016-11-20 18:59:57 +02:00

36 lines
976 B
JavaScript

(function(){
"use strict";
var is = window.core.is;
window.core.should = {
beNumber: function (num, name) {
this.check(is.number(num), num + " is not a number");
this.check(isFinite(num), append(name, "is an infinite number"));
},
bePositiveInteger: function(num, name) {
this.beNumber(num);
this.check(num >= 0, append(name, "should be positive integer"));
},
notBeNull: function (obj, name) {
this.check(obj != null, append(name, "is null or undefined"));
},
beString: function(obj, name) {
this.check(typeof obj == "string", "should be a string");
},
check: function(assertion, message) {
if(assertion !== true) {
throw new Error (message);
}
}
};
function append(name, msg) {
return typeof name == "string" ? name + " " + msg : msg;
}
})();