@thangk/easythemer
Version:
Easily generate shades from a colour palette for use in your app
50 lines (49 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @param object
* @getters getResult(), hasErrors(), getErrorsList()
* @result boolean
* @description Validates if object is an object or an array
*/
class ValidateIsObject {
result = false;
errors = false;
errmsg = [];
constructor(object) {
this.result = this.isObject(object);
}
get getResult() {
return this.result;
}
get hasErrors() {
return this.errors;
}
get getErrorsList() {
return this.errmsg;
}
showErrors() {
this.errmsg.forEach((msg) => {
console.log(msg);
});
}
addError(msg) {
this.errmsg.push(msg);
}
setErrorState() {
this.errors = true;
}
isObject(object) {
const firstIndexElement = object[Object.keys(object)[0]];
// non numbers return NaN after doing with Number(), so we can check if it is a number
const result = Number(firstIndexElement) >= 0 ? false : true;
if (result) {
// result returns NaN, therefore it's not a number, thus it's an object
return true;
}
this.addError("Object is not an object.");
this.setErrorState();
return false;
}
}
exports.default = ValidateIsObject;