/* eslint-disable n/no-unpublished-import */
+
import chalk from 'chalk'
import { build } from 'esbuild'
import { clean } from 'esbuild-plugin-clean'
this.evses = new Map<number, EvseStatus>()
this.requests = new Map<string, CachedRequest>()
this.flushingMessageBuffer = false
- this.messageQueue = new Array<string>()
+ this.messageQueue = [] as string[]
this.sharedLRUCache = SharedLRUCache.getInstance()
this.idTagsCache = IdTagsCache.getInstance()
this.chargingStationWorkerBroadcastChannel = new ChargingStationWorkerBroadcastChannel(this)
this,
this.stationInfo.amperageLimitationOcppKey,
// prettier-ignore
- (
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.stationInfo.maximumAmperage! * getAmperageLimitationUnitDivider(this.stationInfo)
- ).toString()
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ (this.stationInfo.maximumAmperage! * getAmperageLimitationUnitDivider(this.stationInfo)).toString()
)
}
if (getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles) == null) {
moduleName?: string,
methodName?: string
): JSONSchemaType<T> {
- return super.parseJsonSchemaFile<T>(
+ return OCPPServiceUtils.parseJsonSchemaFile<T>(
relativePath,
OCPPVersion.VERSION_16,
moduleName,
moduleName?: string,
methodName?: string
): JSONSchemaType<T> {
- return super.parseJsonSchemaFile<T>(
+ return OCPPServiceUtils.parseJsonSchemaFile<T>(
relativePath,
OCPPVersion.VERSION_201,
moduleName,
import { logger } from '../../utils/index.js'
import { OCPPConstants } from './OCPPConstants.js'
import { ajvErrorsToErrorType } from './OCPPServiceUtils.js'
+
type Ajv = _Ajv.default
// eslint-disable-next-line @typescript-eslint/no-redeclare
const Ajv = _Ajv.default
convertDateToISOString,
getMessageTypeString,
} from './OCPPServiceUtils.js'
+
type Ajv = _Ajv.default
// eslint-disable-next-line @typescript-eslint/no-redeclare
const Ajv = _Ajv.default
import { OCPPError } from '../../exception/index.js'
import { Constants, logger } from '../../utils/index.js'
import { ajvErrorsToErrorType } from './OCPPServiceUtils.js'
+
type Ajv = _Ajv.default
// eslint-disable-next-line @typescript-eslint/no-redeclare
const Ajv = _Ajv.default
}
export const isLoopback = (address: string): boolean => {
- // eslint-disable-next-line no-useless-escape
- return /^localhost$|^127(?:\.\d+){0,2}\.\d+$|^(?:0*\:)*?:?0*1$/i.test(address)
+ return /^localhost$|^127(?:\.\d+){0,2}\.\d+$|^(?:0*:)*?:?0*1$/i.test(address)
}
consoleWarnOnce(
`${chalk.green(logPrefix())} ${chalk.yellow(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- `${FileType.Configuration} ${this.configurationFile} file have changed, reload`
+ `${FileType.Configuration} ${Configuration.configurationFile} file have changed, reload`
)}`
)
delete Configuration.configurationData
if (Array.isArray(dataSet) && dataSet.length === 0) {
return 0
}
- return dataSet.reduce((accumulator, num) => accumulator + num, 0) / dataSet.length
+ if (Array.isArray(dataSet) && dataSet.length === 1) {
+ return dataSet[0]
+ }
+ return dataSet.reduce((accumulator, number) => accumulator + number, 0) / dataSet.length
}
export const median = (dataSet: number[]): number => {
if (Array.isArray(dataSet) && dataSet.length === 0) {
return 0
}
- const sortedDataSet = dataSet.slice().sort((a, b) => a - b)
- const length = sortedDataSet.length
- if (length % 2 === 0) {
- return (sortedDataSet[length / 2 - 1] + sortedDataSet[length / 2]) / 2
+ if (Array.isArray(dataSet) && dataSet.length === 1) {
+ return dataSet[0]
}
- return sortedDataSet[Math.floor(length / 2)]
+ const sortedDataSet = dataSet.slice().sort((a, b) => a - b)
+ return (
+ (sortedDataSet[(sortedDataSet.length - 1) >> 1] + sortedDataSet[sortedDataSet.length >> 1]) / 2
+ )
}
export const min = (...args: number[]): number =>
return 0
}
return Math.sqrt(
- dataSet.reduce((accumulator, num) => accumulator + Math.pow(num - dataSetAverage, 2), 0) /
+ dataSet.reduce((accumulator, num) => accumulator + (num - dataSetAverage) ** 2, 0) /
(dataSet.length - 1)
)
}
if (object == null) {
return false
}
- return Object.prototype.hasOwnProperty.call(object, property)
+ return Object.hasOwn(object, property)
}
const type = (value: unknown): string => {
* @returns The rounded number.
*/
export const roundTo = (numberValue: number, scale: number): number => {
- const roundPower = Math.pow(10, scale)
+ const roundPower = 10 ** scale
return Math.round(numberValue * roundPower * (1 + Number.EPSILON)) / roundPower
}
* @returns delay in milliseconds
*/
export const exponentialDelay = (retryNumber = 0, delayFactor = 100): number => {
- const delay = Math.pow(2, retryNumber) * delayFactor
+ const delay = 2 ** retryNumber * delayFactor
const randomSum = delay * 0.2 * secureRandom() // 0-20% of the delay
return delay + randomSum
}
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
+
import { expect } from '@std/expect'
import { describe, it } from 'node:test'
t.mock.method(logger, 'warn')
checkStationInfoConnectorStatus(1, {} as ConnectorStatus, 'log prefix |', 'test-template.json')
expect(logger.warn.mock.calls.length).toBe(0)
- const connectorStatus = { status: ConnectorStatusEnum.Available } as ConnectorStatus
+ const connectorStatus = {
+ status: ConnectorStatusEnum.Available,
+ } as ConnectorStatus
checkStationInfoConnectorStatus(1, connectorStatus, 'log prefix |', 'test-template.json')
expect(logger.warn.mock.calls.length).toBe(1)
expect(connectorStatus.status).toBeUndefined()
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
+
import { expect } from '@std/expect'
import { describe, it } from 'node:test'