HashAlgorithmEnumType,
InstallCertificateUseEnumType,
} from '../../../types/index.js'
-import { convertToDate, getErrorMessage } from '../../../utils/index.js'
+import { convertToDate, getErrorMessage, isEmpty } from '../../../utils/index.js'
/**
* Interface for ChargingStation with certificate manager
return false
}
- if (pemData.trim().length === 0) {
+ if (isEmpty(pemData)) {
return false
}
convertToDate,
convertToIntOrNaN,
generateUUID,
+ isEmpty,
+ isNotEmptyString,
logger,
promiseWithTimeout,
sleep,
)
// C10: Validate signing certificate PEM format if present
- if (firmware.signingCertificate != null && firmware.signingCertificate.trim() !== '') {
+ if (isNotEmptyString(firmware.signingCertificate)) {
if (
!hasCertificateManager(chargingStation) ||
!chargingStation.certificateManager.validateCertificateFormat(firmware.signingCertificate)
if (checkAborted()) return
// H9: If firmware location is empty or malformed, send DownloadFailed and stop
- if (location.trim() === '' || !this.isValidFirmwareLocation(location)) {
+ if (isEmpty(location) || !this.isValidFirmwareLocation(location)) {
// L01.FR.30: Simulate download retries before reporting DownloadFailed
const maxRetries = retries ?? 0
const retryDelayMs = secondsToMilliseconds(retryInterval ?? 0)
ErrorType,
type JsonObject,
type JsonType,
+ OCPP20ComponentName,
OCPP20RequestCommand,
+ OCPP20RequiredVariableName,
type OCPP20SignCertificateRequest,
type OCPP20StatusNotificationRequest,
type OCPP20TransactionEventOptions,
case OCPP20RequestCommand.SIGN_CERTIFICATE: {
let csr: string
try {
- const configKey = getConfigurationKey(chargingStation, 'SecurityCtrlr.OrganizationName')
+ const configKey = getConfigurationKey(
+ chargingStation,
+ `${OCPP20ComponentName.SecurityCtrlr}.${OCPP20RequiredVariableName.OrganizationName}`
+ )
const orgName = configKey?.value ?? 'Unknown'
const stationId = chargingStation.stationInfo?.chargingStationId ?? 'Unknown'
ReasonCodeEnumType,
type VariableName,
} from '../../../types/index.js'
-import { Constants, convertToIntOrNaN, has } from '../../../utils/index.js'
+import { Constants, convertToIntOrNaN, has, isEmpty } from '../../../utils/index.js'
import { OCPP20Constants } from './OCPP20Constants.js'
/**
}
case DataEnumType.MemberList:
case DataEnumType.SequenceList: {
- if (rawValue.trim().length === 0) {
+ if (isEmpty(rawValue)) {
return { info: 'List cannot be empty', ok: false, reason: ReasonCodeEnumType.InvalidValue }
}
if (rawValue.startsWith(',') || rawValue.endsWith(',')) {
import type { AuthConfiguration, Identifier } from '../types/AuthTypes.js'
+import { isNotEmptyString } from '../../../../utils/index.js'
import { IdentifierType } from '../types/AuthTypes.js'
/**
* @returns True if the value is a non-empty string with at least one non-whitespace character, false otherwise
*/
function isValidIdentifierValue (value: string): boolean {
- if (typeof value !== 'string' || value.length === 0) {
- return false
- }
-
- // Must contain at least one non-whitespace character
- return value.trim().length > 0
+ return isNotEmptyString(value)
}
/**
} from './ConfigurationUtils.js'
import { Constants } from './Constants.js'
import { ensureError, handleFileException } from './ErrorUtils.js'
-import { has, isCFEnvironment, mergeDeepRight, once } from './Utils.js'
+import { has, isCFEnvironment, isNotEmptyString, mergeDeepRight, once } from './Utils.js'
type ConfigurationSectionType =
| LogConfiguration
public static getConfigurationData (): ConfigurationData | undefined {
if (
Configuration.configurationData == null &&
- Configuration.configurationFile != null &&
- Configuration.configurationFile.trim().length > 0
+ isNotEmptyString(Configuration.configurationFile)
) {
try {
Configuration.configurationData = JSON.parse(
}
private static getConfigurationFileWatcher (): FSWatcher | undefined {
- if (
- Configuration.configurationFile == null ||
- Configuration.configurationFile.trim().length === 0
- ) {
+ if (!isNotEmptyString(Configuration.configurationFile)) {
return
}
try {
} from '../types/index.js'
import { WorkerProcessType } from '../worker/index.js'
import { logPrefix } from './ConfigurationUtils.js'
-import { has } from './Utils.js'
+import { has, isNotEmptyString } from './Utils.js'
/**
* Check and warn about deprecated configuration keys
console.error(
`${chalk.green(logPrefix())} ${chalk.red(
`Deprecated configuration key '${key}' usage in section '${configurationSection}'${
- logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : ''
+ isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
}`
)}`
)
console.error(
`${chalk.green(logPrefix())} ${chalk.red(
`Deprecated configuration key '${key}' usage${
- logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : ''
+ isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
}`
)}`
)
+import { isNotEmptyArray } from './Utils.js'
+
export const average = (dataSet: number[]): number => {
- if (!Array.isArray(dataSet) || dataSet.length === 0) {
+ if (!isNotEmptyArray<number>(dataSet)) {
return 0
}
if (dataSet.length === 1) {
}
export const median = (dataSet: number[]): number => {
- if (!Array.isArray(dataSet) || dataSet.length === 0) {
+ if (!isNotEmptyArray<number>(dataSet)) {
return 0
}
if (dataSet.length === 1) {