2025-07-08 12:57:22 +02:00
|
|
|
/**
|
|
|
|
|
* @file assertionUtils.js
|
|
|
|
|
*
|
|
|
|
|
* Utility functions for assertions and throwing errors in EVOLV.
|
|
|
|
|
*
|
|
|
|
|
* @description This module provides functions to assert conditions and throw errors when those conditions are not met.
|
|
|
|
|
* @exports ValidationUtils
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class Assertions {
|
|
|
|
|
/**
|
|
|
|
|
* Assert that no NaN values are present in an array.
|
|
|
|
|
* @param {Array} arr - The array to check for NaN values.
|
|
|
|
|
* @param {string} label - Array label to indicate where the error occurs.
|
|
|
|
|
*/
|
|
|
|
|
assertNoNaN(arr, label = "array") {
|
|
|
|
|
if (Array.isArray(arr)) {
|
|
|
|
|
for (const el of arr) {
|
2026-03-11 13:39:40 +01:00
|
|
|
this.assertNoNaN(el, label);
|
2025-07-08 12:57:22 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (Number.isNaN(arr)) {
|
|
|
|
|
throw new Error(`NaN detected in ${label}!`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = Assertions;
|