refactor: cleanup loops over object keys
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPServiceUtils.ts
index b01ff1e080161f68b52440122a00e4013a3e603e..8e2064905d7691525cd6b20fc885557b761b5cbb 100644 (file)
@@ -1,5 +1,5 @@
-import fs from 'node:fs';
-import path from 'node:path';
+import { readFileSync } from 'node:fs';
+import { dirname, join } from 'node:path';
 import { fileURLToPath } from 'node:url';
 
 import type { DefinedError, ErrorObject, JSONSchemaType } from 'ajv';
@@ -30,7 +30,13 @@ import {
   type StatusNotificationRequest,
   type StatusNotificationResponse,
 } from '../../types';
-import { Utils, handleFileException, logger } from '../../utils';
+import {
+  handleFileException,
+  isNotEmptyArray,
+  isNotEmptyString,
+  logPrefix,
+  logger,
+} from '../../utils';
 
 export class OCPPServiceUtils {
   protected constructor() {
@@ -269,9 +275,9 @@ export class OCPPServiceUtils {
     moduleName?: string,
     methodName?: string
   ): JSONSchemaType<T> {
-    const filePath = path.join(path.dirname(fileURLToPath(import.meta.url)), relativePath);
+    const filePath = join(dirname(fileURLToPath(import.meta.url)), relativePath);
     try {
-      return JSON.parse(fs.readFileSync(filePath, 'utf8')) as JSONSchemaType<T>;
+      return JSON.parse(readFileSync(filePath, 'utf8')) as JSONSchemaType<T>;
     } catch (error) {
       handleFileException(
         filePath,
@@ -314,7 +320,7 @@ export class OCPPServiceUtils {
       chargingStation.getConnectorStatus(connectorId)?.MeterValues;
     for (
       let index = 0;
-      Utils.isNotEmptyArray(sampledValueTemplates) === true && index < sampledValueTemplates.length;
+      isNotEmptyArray(sampledValueTemplates) === true && index < sampledValueTemplates.length;
       index++
     ) {
       if (
@@ -392,9 +398,9 @@ export class OCPPServiceUtils {
     methodName?: string
   ): string => {
     const logMsg =
-      Utils.isNotEmptyString(moduleName) && Utils.isNotEmptyString(methodName)
+      isNotEmptyString(moduleName) && isNotEmptyString(methodName)
         ? ` OCPP ${ocppVersion} | ${moduleName}.${methodName}:`
         : ` OCPP ${ocppVersion} |`;
-    return Utils.logPrefix(logMsg);
+    return logPrefix(logMsg);
   };
 }