fix: readd safety check in charging station log prefix helper
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index fa82ba1d334836cb4454cabcd6b544564dd0f317..b8083596b2618a3b5c2360d15a4fc6542a00c9dd 100644 (file)
@@ -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 = <T, A extends any[], R>(
 ): ((...args: A) => R) => {
   let result: R
   return (...args: A) => {
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
     if (fn != null) {
       result = fn.apply<T, A, R>(context, args)
       ;(fn as unknown as undefined) = (context as unknown as undefined) = undefined