X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=73e5e3f96e421b7f2bbec4bb1021ab58f5c09d47;hb=7429b96a712aec23847317058bbdceada172cbc3;hp=38a212ca20c3f081cf2a9f6a2ec12719e49c70c1;hpb=97ef739c0f207e2b729bd3f185c463eb0ff35c7d;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 38a212ca..73e5e3f9 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -40,48 +40,48 @@ export default class Utils { } } - static convertToDate(value: any): Date { + static convertToDate(value: unknown): Date { // Check if (!value) { - return value; + return value as Date; } // Check Type if (!(value instanceof Date)) { - return new Date(value); + return new Date(value as string); } return value; } - static convertToInt(value: any): number { - let changedValue = value; + static convertToInt(value: unknown): number { + let changedValue: number = value as number; if (!value) { return 0; } if (Number.isSafeInteger(value)) { - return value; + return value as number; } // Check - if (typeof value === 'string') { + if (Utils.isString(value)) { // Create Object - changedValue = parseInt(value); + changedValue = parseInt(value as string); } return changedValue; } - static convertToFloat(value: any): number { - let changedValue = value; + static convertToFloat(value: unknown): number { + let changedValue: number = value as number; if (!value) { return 0; } // Check - if (typeof value === 'string') { + if (Utils.isString(value)) { // Create Object - changedValue = parseFloat(value); + changedValue = parseFloat(value as string); } return changedValue; } - static convertToBoolean(value: any): boolean { + static convertToBoolean(value: unknown): boolean { let result = false; // Check boolean if (value) { @@ -144,7 +144,7 @@ export default class Utils { return false; } - static isEmptyJSon(document: any): boolean { + static isEmptyJSon(document: unknown): boolean { // Empty? if (!document) { return true; @@ -157,15 +157,15 @@ export default class Utils { return Object.keys(document).length === 0; } - static isString(value: any): boolean { + static isString(value: unknown): boolean { return typeof value === 'string'; } - static isUndefined(value: any): boolean { + static isUndefined(value: unknown): boolean { return typeof value === 'undefined'; } - static isNullOrUndefined(value: any): boolean { + static isNullOrUndefined(value: unknown): boolean { // eslint-disable-next-line no-eq-null, eqeqeq if (value == null) { return true; @@ -173,7 +173,7 @@ export default class Utils { return false; } - static isEmptyArray(object: any): boolean { + static isEmptyArray(object: unknown): boolean { if (!object) { return true; } @@ -183,15 +183,15 @@ export default class Utils { return true; } - static isEmptyObject(obj: any): boolean { + static isEmptyObject(obj: Record): boolean { return !Object.keys(obj).length; } static insertAt = (str: string, subStr: string, pos: number): string => `${str.slice(0, pos)}${subStr}${str.slice(pos)}`; /** - * @param {number} [retryNumber=0] - * @returns {number} delay in milliseconds + * @param [retryNumber=0] + * @returns delay in milliseconds */ static exponentialDelay(retryNumber = 0): number { const delay = Math.pow(2, retryNumber) * 100; @@ -202,8 +202,8 @@ export default class Utils { /** * Convert websocket error code to human readable string message * - * @param {number} code websocket error code - * @returns {string} human readable string message + * @param code websocket error code + * @returns human readable string message */ static getWebSocketCloseEventStatusString(code: number): string { if (code >= 0 && code <= 999) {