should append names

This commit is contained in:
Borys Levytskyi
2015-04-04 19:35:18 +03:00
parent f14425da75
commit a22a6deae0

View File

@@ -4,19 +4,19 @@
window.core.should = {
beNumber: function (num, name) {
this.check(typeof num == "number" && !isNaN(num), num + " is not a number");
this.check(isFinite(num), num + "is an infinite number")
this.check(isFinite(num), append(name, "is an infinite number"));
},
bePositiveInteger: function(num) {
bePositiveInteger: function(num, name) {
this.beNumber(num);
this.check(num >= 0, "Should be positive integer")
this.check(num >= 0, append(name, "should be positive integer"));
},
notBeNull: function (obj, name) {
this.check(obj != null, name + " is null or undefined");
this.check(obj != null, append(name, "is null or undefined"));
},
beString: function(obj) {
beString: function(obj, name) {
this.check(typeof obj == "string", "should be a string");
},
check: function(assertion, message) {
@@ -25,6 +25,10 @@
}
}
};
function append(name, msg) {
return typeof name == "string" ? name + " " + msg : msg;
}
})();