UI Server: dedupe some code in helpers
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / UIServiceUtils.ts
index 573520b9687c93b267fcf4fcfe4eb70f6ee4453e..06db5a47109f2c11b77eb938021748d86968eaf5 100644 (file)
@@ -23,21 +23,21 @@ export class UIServiceUtils {
         protocolIndex + Protocol.UI.length
       ) as Protocol;
       version = fullProtocol.substring(protocolIndex + Protocol.UI.length) as ProtocolVersion;
-      if (
-        Object.values(Protocol).includes(protocol) &&
-        Object.values(ProtocolVersion).includes(version)
-      ) {
+      if (UIServiceUtils.isProtocolSupported(protocol, version) === true) {
         return fullProtocol;
       }
     }
     logger.error(
       `${Utils.logPrefix(
-        ' UI WebSocket Server:'
+        ' UI WebSocket Server |'
       )} Unsupported protocol: ${protocol} or protocol version: ${version}`
     );
     return false;
   };
 
+  public static isProtocolSupported = (protocol: Protocol, version: ProtocolVersion): boolean =>
+    Object.values(Protocol).includes(protocol) && Object.values(ProtocolVersion).includes(version);
+
   public static isLoopback(address: string): boolean {
     const isLoopbackRegExp = new RegExp(
       // eslint-disable-next-line no-useless-escape