From: Jérôme Benoit Date: Mon, 23 Jan 2023 21:43:03 +0000 (+0100) Subject: Avoid strings concatenation X-Git-Tag: v1.1.92~23 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=14ecae6a3d6b172ca29353e5a2faed513feff4f5;p=e-mobility-charging-stations-simulator.git Avoid strings concatenation Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7fdc9a95..7d66d720 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1228,7 +1228,7 @@ export default class ChargingStation { if (stationInfo?.Connectors) { const connectorsConfigHash = crypto .createHash(Constants.DEFAULT_HASH_ALGORITHM) - .update(JSON.stringify(stationInfo?.Connectors) + configuredMaxConnectors.toString()) + .update(`${JSON.stringify(stationInfo?.Connectors)}${configuredMaxConnectors.toString()}`) .digest('hex'); const connectorsConfigChanged = this.connectors?.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash; diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index c10a3a15..426ff5c0 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -78,8 +78,10 @@ export class ChargingStationUtils { return crypto .createHash(Constants.DEFAULT_HASH_ALGORITHM) .update( - JSON.stringify(chargingStationInfo) + - ChargingStationUtils.getChargingStationId(index, stationTemplate) + `${JSON.stringify(chargingStationInfo)}${ChargingStationUtils.getChargingStationId( + index, + stationTemplate + )}` ) .digest('hex'); } @@ -268,13 +270,13 @@ export class ChargingStationUtils { : ''; stationInfo.chargePointSerialNumber = stationTemplate?.chargePointSerialNumberPrefix && - stationTemplate.chargePointSerialNumberPrefix + serialNumberSuffix; + `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`; stationInfo.chargeBoxSerialNumber = stationTemplate?.chargeBoxSerialNumberPrefix && - stationTemplate.chargeBoxSerialNumberPrefix + serialNumberSuffix; + `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`; stationInfo.meterSerialNumber = stationTemplate?.meterSerialNumberPrefix && - stationTemplate.meterSerialNumberPrefix + serialNumberSuffix; + `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`; } public static propagateSerialNumber( diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 04806853..14817511 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -79,11 +79,11 @@ export default class SharedLRUCache { } private getChargingStationConfigurationKey(hash: string): string { - return CacheType.CHARGING_STATION_CONFIGURATION + hash; + return `${CacheType.CHARGING_STATION_CONFIGURATION}${hash}`; } private getChargingStationTemplateKey(hash: string): string { - return CacheType.CHARGING_STATION_TEMPLATE + hash; + return `${CacheType.CHARGING_STATION_TEMPLATE}${hash}`; } private has(key: string): boolean { diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 6f77cde0..af378a47 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1091,7 +1091,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../'), diagnosticsArchive ), - uri.pathname + diagnosticsArchive + `${uri.pathname}${diagnosticsArchive}` ); if (uploadResponse.code === 226) { await chargingStation.ocppRequestService.requestHandler< diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index ef9d393a..49ebc79b 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -50,7 +50,7 @@ export default class PerformanceStatistics { } public static beginMeasure(id: string): string { - const markId = `${id.charAt(0).toUpperCase() + id.slice(1)}~${Utils.generateUUID()}`; + const markId = `${id.charAt(0).toUpperCase()}${id.slice(1)}~${Utils.generateUUID()}`; performance.mark(markId); return markId; } diff --git a/src/scripts/deleteChargingStations.js b/src/scripts/deleteChargingStations.js index f92cdcf1..4f65bdd3 100755 --- a/src/scripts/deleteChargingStations.js +++ b/src/scripts/deleteChargingStations.js @@ -20,7 +20,7 @@ if (config && config.mongoConnectionString) { for await (const tenantID of config.tenantIDs) { const response = await db - .collection(tenantID + '.chargingstations') + .collection(`${tenantID}.chargingstations`) .deleteMany({ _id: { $regex: config.idPattern } }); console.info( response.deletedCount, diff --git a/src/scripts/setCSPublicFlag.js b/src/scripts/setCSPublicFlag.js index c3364732..e591d3ba 100755 --- a/src/scripts/setCSPublicFlag.js +++ b/src/scripts/setCSPublicFlag.js @@ -21,7 +21,7 @@ if (config && config.mongoConnectionString) { for await (const tenantID of config.tenantIDs) { const response = await db - .collection(tenantID + '.chargingstations') + .collection(`${tenantID}.chargingstations`) .updateMany({ _id: { $regex: config.idPattern } }, { $set: { public: config.publicFlag } }); console.info( response.modifiedCount, diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 9586a868..b51e8ada 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -311,7 +311,7 @@ export default class Configuration { } private static logPrefix(): string { - return new Date().toLocaleString() + ' Simulator configuration |'; + return `${new Date().toLocaleString()} Simulator configuration |`; } private static warnDeprecatedConfigurationKey( @@ -421,7 +421,7 @@ export default class Configuration { error: NodeJS.ErrnoException, params: HandleErrorParams = { throwError: true } ): void { - const prefix = logPrefix.length !== 0 ? logPrefix + ' ' : ''; + const prefix = logPrefix.trim().length !== 0 ? `${logPrefix} ` : ''; let logMsg: string; switch (error.code) { case 'ENOENT': diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index 69b5240d..ccee788b 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -52,7 +52,7 @@ export default class FileUtils { error: NodeJS.ErrnoException, params: HandleErrorParams = { throwError: true, consoleOut: false } ): void { - const prefix = !Utils.isEmptyString(logPrefix) ? logPrefix + ' ' : ''; + const prefix = !Utils.isEmptyString(logPrefix) ? `${logPrefix} ` : ''; let logMsg: string; switch (error.code) { case 'ENOENT': diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 89119bc2..f6fe0670 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -12,7 +12,7 @@ export default class Utils { } public static logPrefix(prefixString = ''): string { - return new Date().toLocaleString() + prefixString; + return `${new Date().toLocaleString()} ${prefixString}`; } public static generateUUID(): string { diff --git a/test/robohydra/plugins/wsServer/index.js b/test/robohydra/plugins/wsServer/index.js index fb5e4969..dfb42689 100644 --- a/test/robohydra/plugins/wsServer/index.js +++ b/test/robohydra/plugins/wsServer/index.js @@ -43,10 +43,10 @@ exports.getBodyParts = function (conf) { mountPath: '/proxy', proxyTo: 'ws://server.example.com', preProcessor: function (data) { - console.info('From the client: ' + data); + console.info(`From the client: ${data}`); }, postProcessor: function (data) { - console.info('From the server: ' + data); + console.info(`From the server: ${data}`); }, }),