X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=b8083596b2618a3b5c2360d15a4fc6542a00c9dd;hb=41f18326bd0c915a2390208ab1c1973cc6c82a6e;hp=fa82ba1d334836cb4454cabcd6b544564dd0f317;hpb=aa63c9b772ff17bce2febf68a57720eab96d5f8e;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index fa82ba1d..b8083596 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -85,10 +85,8 @@ export const convertToDate = ( return value } if (isString(value) || typeof value === 'number') { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const valueToDate = new Date(value) if (isNaN(valueToDate.getTime())) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion throw new Error(`Cannot convert to date: '${value}'`) } return valueToDate @@ -156,7 +154,7 @@ export const getRandomFloat = (max = Number.MAX_VALUE, min = 0): number => { export const getRandomInteger = (max = Constants.MAX_RANDOM_INTEGER, min = 0): number => { max = Math.floor(max) - if (min != null && min !== 0) { + if (min !== 0) { min = Math.ceil(min) return Math.floor(randomInt(min, max + 1)) } @@ -177,7 +175,7 @@ export const roundTo = (numberValue: number, scale: number): number => { } export const getRandomFloatRounded = (max = Number.MAX_VALUE, min = 0, scale = 2): number => { - if (min != null && min !== 0) { + if (min !== 0) { return roundTo(getRandomFloat(max, min), scale) } return roundTo(getRandomFloat(max), scale) @@ -287,14 +285,6 @@ export const isNotEmptyString = (value: unknown): boolean => { return isString(value) && (value as string).trim().length > 0 } -export const isUndefined = (value: unknown): boolean => { - return value === undefined -} - -export const isNullOrUndefined = (value: unknown): boolean => { - return value == null -} - export const isEmptyArray = (object: unknown): boolean => { return Array.isArray(object) && object.length === 0 } @@ -304,7 +294,7 @@ export const isNotEmptyArray = (object: unknown): boolean => { } export const isEmptyObject = (obj: object): boolean => { - if (obj?.constructor !== Object) { + if (obj.constructor !== Object) { return false } // Iterates over the keys of an object, if @@ -381,9 +371,8 @@ export const getWebSocketCloseEventStatusString = (code: number): string => { } } if ( - !isUndefined( - WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString] - ) + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString] != null ) { return WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString] } @@ -406,6 +395,7 @@ export const once = ( ): ((...args: A) => R) => { let result: R return (...args: A) => { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (fn != null) { result = fn.apply(context, args) ;(fn as unknown as undefined) = (context as unknown as undefined) = undefined