X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.js;h=5b26a4f8b9d2a7d473415843e67ae5c00602882c;hb=546dec0fafb76402766ba55c89866b9f8b329895;hp=a06d57ead326e3dc052417fe902b54a9036b04fa;hpb=2e6f5966ecbefada47d60b1b53d21fe49be439a5;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.js b/src/utils/Utils.js index a06d57ea..5b26a4f8 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -1,7 +1,7 @@ const {v4: uuid} = require('uuid'); class Utils { - static generateGUID() { + static generateUUID() { return uuid(); } @@ -74,30 +74,33 @@ class Utils { 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) { @@ -118,14 +121,14 @@ class Utils { 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) { @@ -135,6 +138,20 @@ class Utils { 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; + } } module.exports = Utils;