X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=4306d8872e0114928481769feb6bb6daf5ff603e;hb=039211f91daa930e261a976c0c5ffbf729fbe922;hp=9323e4be72b71d22b114a32834d6c49e26d5dc8e;hpb=ef4932d8aec470321413643e3c0647b0b29396de;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 9323e4be..4306d887 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -3,7 +3,8 @@ import util from 'node:util'; import clone from 'just-clone'; -import { Constants } from './internal'; +// import { Constants } from './internal'; +import { Constants } from './Constants'; import { WebSocketCloseEventStatusString } from '../types'; export class Utils { @@ -190,7 +191,7 @@ export class Utils { } public static isCFEnvironment(): boolean { - return process.env.VCAP_APPLICATION !== undefined; + return !Utils.isNullOrUndefined(process.env.VCAP_APPLICATION); } public static isIterable(obj: T): boolean { @@ -222,17 +223,11 @@ export class Utils { } public static isEmptyArray(object: unknown | unknown[]): boolean { - if (Array.isArray(object) && object.length === 0) { - return true; - } - return false; + return Array.isArray(object) && object.length === 0; } public static isNotEmptyArray(object: unknown | unknown[]): boolean { - if (Array.isArray(object) && object.length > 0) { - return true; - } - return false; + return Array.isArray(object) && object.length > 0; } public static isEmptyObject(obj: object): boolean { @@ -254,9 +249,9 @@ export class Utils { * @param retryNumber - the number of retries that have already been attempted * @returns delay in milliseconds */ - public static exponentialDelay(retryNumber = 0): number { + public static exponentialDelay(retryNumber = 0, maxDelayRatio = 0.2): number { const delay = Math.pow(2, retryNumber) * 100; - const randomSum = delay * 0.2 * Utils.secureRandom(); // 0-20% of the delay + const randomSum = delay * maxDelayRatio * Utils.secureRandom(); // 0-20% of the delay return delay + randomSum; }