X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.js;h=15ee30711ec2c3645626b0e6af071abd212c71aa;hb=4a56deef7aeca58425c92ec27388bbe34543ad4f;hp=e85090d49626156d4e2fdb913781762448bdcc8a;hpb=a6e68f340a9c5837c767b316dee5d5121188dc47;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.js b/src/utils/Utils.js index e85090d4..15ee3071 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) { @@ -125,7 +128,29 @@ class Utils { 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; } }