refactor: adopt POSITIONS constants, fix ESLint warnings, break menuUtils into modules
- Replace hardcoded position strings with POSITIONS.* constants - Prefix unused variables with _ to resolve no-unused-vars warnings - Fix no-prototype-builtins with Object.prototype.hasOwnProperty.call() - Extract menuUtils.js (543 lines) into 6 focused modules under menu/ - menuUtils.js now 35 lines, delegates via prototype mixin pattern - Add 158 unit tests for ConfigManager, MeasurementContainer, ValidationUtils Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
const MeasurementBuilder = require('./MeasurementBuilder');
|
||||
const EventEmitter = require('events');
|
||||
const convertModule = require('../convert/index');
|
||||
const { POSITIONS } = require('../constants/positions');
|
||||
|
||||
class MeasurementContainer {
|
||||
constructor(options = {},logger) {
|
||||
constructor(options = {},_logger) {
|
||||
this.emitter = new EventEmitter();
|
||||
this.measurements = {};
|
||||
this.windowSize = options.windowSize || 10; // Default window size
|
||||
@@ -359,7 +360,7 @@ class MeasurementContainer {
|
||||
|
||||
|
||||
// Difference calculations between positions
|
||||
difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
||||
difference({ from = POSITIONS.DOWNSTREAM, to = POSITIONS.UPSTREAM, unit: requestedUnit } = {}) {
|
||||
if (!this._currentType || !this._currentVariant) {
|
||||
throw new Error("Type and variant must be specified for difference calculation");
|
||||
}
|
||||
@@ -526,11 +527,11 @@ difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
||||
|
||||
_convertPositionStr2Num(positionString) {
|
||||
switch(positionString) {
|
||||
case "atEquipment":
|
||||
case POSITIONS.AT_EQUIPMENT:
|
||||
return 0;
|
||||
case "upstream":
|
||||
case POSITIONS.UPSTREAM:
|
||||
return Number.POSITIVE_INFINITY;
|
||||
case "downstream":
|
||||
case POSITIONS.DOWNSTREAM:
|
||||
return Number.NEGATIVE_INFINITY;
|
||||
|
||||
default:
|
||||
@@ -544,11 +545,11 @@ difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
||||
_convertPositionNum2Str(positionValue) {
|
||||
switch (positionValue) {
|
||||
case 0:
|
||||
return "atEquipment";
|
||||
return POSITIONS.AT_EQUIPMENT;
|
||||
case (positionValue < 0):
|
||||
return "upstream";
|
||||
return POSITIONS.UPSTREAM;
|
||||
case (positionValue > 0):
|
||||
return "downstream";
|
||||
return POSITIONS.DOWNSTREAM;
|
||||
default:
|
||||
console.log(`Invalid position provided: ${positionValue}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user