handleFileException,
isNotEmptyArray,
isNotEmptyString,
- isUndefined,
logPrefix,
logger,
min,
connectorId?: number
): boolean {
const reservation = this.getReservationBy('reservationId', reservationId)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const reservationExists = !isUndefined(reservation) && !hasReservationExpired(reservation!)
+ const reservationExists = reservation !== undefined && !hasReservationExpired(reservation)
if (arguments.length === 1) {
return !reservationExists
} else if (arguments.length > 1) {
- const userReservation = !isUndefined(idTag)
- ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getReservationBy('idTag', idTag!)
- : undefined
+ const userReservation =
+ idTag !== undefined ? this.getReservationBy('idTag', idTag) : undefined
const userReservationExists =
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- !isUndefined(userReservation) && !hasReservationExpired(userReservation!)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0
+ userReservation !== undefined && !hasReservationExpired(userReservation)
+ const notConnectorZero = connectorId === undefined ? true : connectorId > 0
const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0
return (
!reservationExists && !userReservationExists && notConnectorZero && freeConnectorsAvailable
isEmptyString,
isNotEmptyArray,
isNotEmptyString,
- isUndefined,
isValidTime,
logger,
secureRandom
const chargingStationInfo = {
chargePointModel: stationTemplate.chargePointModel,
chargePointVendor: stationTemplate.chargePointVendor,
- ...(!isUndefined(stationTemplate.chargeBoxSerialNumberPrefix) && {
+ ...(stationTemplate.chargeBoxSerialNumberPrefix !== undefined && {
chargeBoxSerialNumber: stationTemplate.chargeBoxSerialNumberPrefix
}),
- ...(!isUndefined(stationTemplate.chargePointSerialNumberPrefix) && {
+ ...(stationTemplate.chargePointSerialNumberPrefix !== undefined && {
chargePointSerialNumber: stationTemplate.chargePointSerialNumberPrefix
}),
- ...(!isUndefined(stationTemplate.meterSerialNumberPrefix) && {
+ ...(stationTemplate.meterSerialNumberPrefix !== undefined && {
meterSerialNumber: stationTemplate.meterSerialNumberPrefix
}),
- ...(!isUndefined(stationTemplate.meterType) && {
+ ...(stationTemplate.meterType !== undefined && {
meterType: stationTemplate.meterType
})
}
if (connectorId === 0) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
connectors.get(connectorId)!.availability = AvailabilityType.Operative
- if (isUndefined(connectors.get(connectorId)?.chargingProfiles)) {
+ if (connectors.get(connectorId)?.chargingProfiles == null) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
connectors.get(connectorId)!.chargingProfiles = []
}
return {
chargePointModel: stationInfo.chargePointModel,
chargePointVendor: stationInfo.chargePointVendor,
- ...(!isUndefined(stationInfo.chargeBoxSerialNumber) && {
+ ...(stationInfo.chargeBoxSerialNumber !== undefined && {
chargeBoxSerialNumber: stationInfo.chargeBoxSerialNumber
}),
- ...(!isUndefined(stationInfo.chargePointSerialNumber) && {
+ ...(stationInfo.chargePointSerialNumber !== undefined && {
chargePointSerialNumber: stationInfo.chargePointSerialNumber
}),
- ...(!isUndefined(stationInfo.firmwareVersion) && {
+ ...(stationInfo.firmwareVersion !== undefined && {
firmwareVersion: stationInfo.firmwareVersion
}),
- ...(!isUndefined(stationInfo.iccid) && { iccid: stationInfo.iccid }),
- ...(!isUndefined(stationInfo.imsi) && { imsi: stationInfo.imsi }),
- ...(!isUndefined(stationInfo.meterSerialNumber) && {
+ ...(stationInfo.iccid !== undefined && { iccid: stationInfo.iccid }),
+ ...(stationInfo.imsi !== undefined && { imsi: stationInfo.imsi }),
+ ...(stationInfo.meterSerialNumber !== undefined && {
meterSerialNumber: stationInfo.meterSerialNumber
}),
- ...(!isUndefined(stationInfo.meterType) && {
+ ...(stationInfo.meterType !== undefined && {
meterType: stationInfo.meterType
})
} satisfies OCPP16BootNotificationRequest
chargingStation: {
model: stationInfo.chargePointModel,
vendorName: stationInfo.chargePointVendor,
- ...(!isUndefined(stationInfo.firmwareVersion) && {
+ ...(stationInfo.firmwareVersion !== undefined && {
firmwareVersion: stationInfo.firmwareVersion
}),
- ...(!isUndefined(stationInfo.chargeBoxSerialNumber) && {
+ ...(stationInfo.chargeBoxSerialNumber !== undefined && {
serialNumber: stationInfo.chargeBoxSerialNumber
}),
- ...((!isUndefined(stationInfo.iccid) || !isUndefined(stationInfo.imsi)) && {
+ ...((stationInfo.iccid !== undefined || stationInfo.imsi !== undefined) && {
modem: {
- ...(!isUndefined(stationInfo.iccid) && { iccid: stationInfo.iccid }),
- ...(!isUndefined(stationInfo.imsi) && { imsi: stationInfo.imsi })
+ ...(stationInfo.iccid !== undefined && { iccid: stationInfo.iccid }),
+ ...(stationInfo.imsi !== undefined && { imsi: stationInfo.imsi })
}
})
}
templateKey.deprecatedKey,
logPrefix,
templateFile,
- !isUndefined(templateKey.key) ? `Use '${templateKey.key}' instead` : undefined
+ templateKey.key !== undefined ? `Use '${templateKey.key}' instead` : undefined
)
convertDeprecatedTemplateKey(stationTemplate, templateKey.deprecatedKey, templateKey.key)
}
const numberOfConnectors = stationTemplate.numberOfConnectors as number[]
configuredMaxNumberOfConnectors =
numberOfConnectors[Math.floor(secureRandom() * numberOfConnectors.length)]
- } else if (!isUndefined(stationTemplate.numberOfConnectors)) {
+ } else if (stationTemplate.numberOfConnectors != null) {
configuredMaxNumberOfConnectors = stationTemplate.numberOfConnectors as number
} else if (stationTemplate.Connectors != null && stationTemplate.Evses == null) {
configuredMaxNumberOfConnectors =
connectorStatus.transactionStarted = false
connectorStatus.energyActiveImportRegisterValue = 0
connectorStatus.transactionEnergyActiveImportRegisterValue = 0
- if (isUndefined(connectorStatus.chargingProfiles)) {
+ if (connectorStatus.chargingProfiles == null) {
connectorStatus.chargingProfiles = []
}
}
templateFile: string,
logMsgToAppend = ''
): void => {
- if (!isUndefined(template?.[key as keyof ChargingStationTemplate])) {
+ if (template?.[key as keyof ChargingStationTemplate] !== undefined) {
const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${
isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
}`
deprecatedKey: string,
key?: string
): void => {
- if (!isUndefined(template?.[deprecatedKey as keyof ChargingStationTemplate])) {
- if (!isUndefined(key)) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- (template as unknown as Record<string, unknown>)[key!] =
+ if (template?.[deprecatedKey as keyof ChargingStationTemplate] !== undefined) {
+ if (key !== undefined) {
+ (template as unknown as Record<string, unknown>)[key] =
template[deprecatedKey as keyof ChargingStationTemplate]
}
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
isEmptyArray,
isNotEmptyArray,
isNotEmptyString,
- isUndefined,
logger,
sleep
} from '../../../utils/index.js'
const { key } = commandPayload
const configurationKey: OCPPConfigurationKey[] = []
const unknownKey: string[] = []
- if (isUndefined(key)) {
+ if (key == null) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for (const configuration of chargingStation.ocppConfiguration!.configurationKey!) {
- if (isUndefined(configuration.visible)) {
+ if (configuration.visible == null) {
configuration.visible = true
}
- if (configuration.visible === false) {
+ if (!configuration.visible) {
continue
}
configurationKey.push({
})
}
} else if (isNotEmptyArray(key)) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- for (const k of key!) {
+ for (const k of key) {
const keyFound = getConfigurationKey(chargingStation, k, true)
if (keyFound != null) {
- if (isUndefined(keyFound.visible)) {
+ if (keyFound.visible == null) {
keyFound.visible = true
}
- if (keyFound.visible === false) {
+ if (!keyFound.visible) {
continue
}
configurationKey.push({
try {
const { reservationId } = commandPayload
const reservation = chargingStation.getReservationBy('reservationId', reservationId)
- if (isUndefined(reservation)) {
+ if (reservation == null) {
logger.debug(
`${chargingStation.logPrefix()} Reservation with id ${reservationId} does not exist on charging station`
)
return OCPP16Constants.OCPP_CANCEL_RESERVATION_RESPONSE_REJECTED
}
await chargingStation.removeReservation(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- reservation!,
+ reservation,
ReservationTerminationReason.RESERVATION_CANCELED
)
return OCPP16Constants.OCPP_CANCEL_RESERVATION_RESPONSE_ACCEPTED
handleFileException,
isNotEmptyArray,
isNotEmptyString,
- isUndefined,
logPrefix,
logger,
max,
chargingStation: ChargingStation,
measurandType: MeterValueMeasurand
): void => {
- if (isUndefined(chargingStation.powerDivider)) {
+ if (chargingStation.powerDivider == null) {
const errMsg = `MeterValues measurand ${
measurandType ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
}: powerDivider is undefined`
logPrefix
} from './ConfigurationUtils.js'
import { Constants } from './Constants.js'
-import { hasOwnProp, isCFEnvironment, isUndefined, once } from './Utils.js'
+import { hasOwnProp, isCFEnvironment, once } from './Utils.js'
import {
ApplicationProtocol,
type ConfigurationData,
public static getSupervisionUrls (): string | string[] | undefined {
if (
- !isUndefined(
- Configuration.getConfigurationData()?.['supervisionURLs' as keyof ConfigurationData]
- )
+ Configuration.getConfigurationData()?.['supervisionURLs' as keyof ConfigurationData] !==
+ undefined
) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Configuration.getConfigurationData()!.supervisionUrls = Configuration.getConfigurationData()![
undefined,
"Use 'stationTemplateUrls' instead"
)
- !isUndefined(
- Configuration.getConfigurationData()?.['stationTemplateURLs' as keyof ConfigurationData]
- ) &&
+ Configuration.getConfigurationData()?.['stationTemplateURLs' as keyof ConfigurationData] !==
+ undefined &&
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(Configuration.getConfigurationData()!.stationTemplateUrls =
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
] as StationTemplateUrl[])
Configuration.getConfigurationData()?.stationTemplateUrls.forEach(
(stationTemplateUrl: StationTemplateUrl) => {
- if (!isUndefined(stationTemplateUrl?.['numberOfStation' as keyof StationTemplateUrl])) {
+ if (stationTemplateUrl?.['numberOfStation' as keyof StationTemplateUrl] !== undefined) {
console.error(
`${chalk.green(logPrefix())} ${chalk.red(
`Deprecated configuration key 'numberOfStation' usage for template file '${stationTemplateUrl.file}' in 'stationTemplateUrls'. Use 'numberOfStations' instead`
): void {
if (
sectionName != null &&
- !isUndefined(
- Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData]
- ) &&
- !isUndefined(
- (
- Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] as Record<
- string,
- unknown
- >
- )?.[key]
- )
+ Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] !==
+ undefined &&
+ (
+ Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] as Record<
+ string,
+ unknown
+ >
+ )?.[key] !== undefined
) {
console.error(
`${chalk.green(logPrefix())} ${chalk.red(
)}`
)
} else if (
- !isUndefined(Configuration.getConfigurationData()?.[key as keyof ConfigurationData])
+ Configuration.getConfigurationData()?.[key as keyof ConfigurationData] !== undefined
) {
console.error(
`${chalk.green(logPrefix())} ${chalk.red(
)
delete Configuration.configurationData
Configuration.configurationSectionCache.clear()
- if (!isUndefined(Configuration.configurationChangeCallback)) {
+ if (Configuration.configurationChangeCallback !== undefined) {
Configuration.configurationChangeCallback()
.catch((error) => {
throw typeof error === 'string' ? new Error(error) : error
return isString(value) && (value as string).trim().length > 0
}
-export const isUndefined = (value: unknown): boolean => {
- return value === undefined
-}
-
export const isEmptyArray = (object: unknown): boolean => {
return Array.isArray(object) && object.length === 0
}
}
}
if (
- !isUndefined(
- WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString]
- )
+ WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString] !==
+ undefined
) {
return WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString]
}
isEmptyString,
isNotEmptyArray,
isNotEmptyString,
- isUndefined,
isValidTime,
logPrefix,
max,
isNotEmptyArray,
isNotEmptyString,
isObject,
- isUndefined,
isValidTime,
max,
min,
expect(isNotEmptyString(new WeakSet())).toBe(false)
})
- await it('Verify isUndefined()', () => {
- expect(isUndefined(undefined)).toBe(true)
- expect(isUndefined(null)).toBe(false)
- expect(isUndefined('')).toBe(false)
- expect(isUndefined(0)).toBe(false)
- expect(isUndefined({})).toBe(false)
- expect(isUndefined([])).toBe(false)
- expect(isUndefined(new Map())).toBe(false)
- expect(isUndefined(new Set())).toBe(false)
- expect(isUndefined(new WeakMap())).toBe(false)
- expect(isUndefined(new WeakSet())).toBe(false)
- })
-
await it('Verify isEmptyArray()', () => {
expect(isEmptyArray([])).toBe(true)
expect(isEmptyArray([1, 2])).toBe(false)