const {v4: uuid} = require('uuid');
class Utils {
- static generateGUID() {
+ static generateUUID() {
return uuid();
}
return changedID;
}
- static convertToInt(id) {
- let changedID = id;
- if (!id) {
+ static convertToInt(value) {
+ let changedValue = value;
+ if (!value) {
return 0;
}
+ if (Number.isSafeInteger(value)) {
+ return value;
+ }
// Check
- if (typeof id === 'string') {
+ if (typeof value === 'string') {
// Create Object
- changedID = parseInt(id);
+ changedValue = parseInt(value);
}
- return changedID;
+ return changedValue;
}
- static convertToFloat(id) {
- let changedID = id;
- if (!id) {
+ static convertToFloat(value) {
+ let changedValue = value;
+ if (!value) {
return 0;
}
// Check
- if (typeof id === 'string') {
+ if (typeof value === 'string') {
// Create Object
- changedID = parseFloat(id);
+ changedValue = parseFloat(value);
}
- return changedID;
+ return changedValue;
}
static convertToBoolean(value) {
static getRandomInt(max, min) {
if (min) {
- return Math.floor((Math.random() * (max - min)) + min);
+ return Math.floor((Math.random() * (max - min + 1)) + min);
}
- return Math.floor((Math.random() * max));
+ return Math.floor((Math.random() * max + 1));
}
static basicFormatLog(prefixString = '') {
const date = new Date();
- return date.toISOString().substr(0, 19) + prefixString;
+ return date.toLocaleString() + prefixString;
+ }
+
+ static objectHasOwnProperty(object, property) {
+ return Object.prototype.hasOwnProperty.call(object, property);
+ }
+
+ static cloneJSonDocument(jsonDocument) {
+ return JSON.parse(JSON.stringify(jsonDocument));
+ }
+
+ static isUndefined(value) {
+ if (typeof value === 'undefined') {
+ return true;
+ }
+ return false;
+ }
+
+ static isEmptyArray(object) {
+ if (Array.isArray(object) && object.length > 0) {
+ return false;
+ }
+ return true;
}
}