Files
generalFunctions/index.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-06-10 12:36:39 +02:00
/**
* generalFunctions/index.js
* -----------------------------------------------------------
* Central barrel file for re-exporting helpers and configurations.
* Provides both namespace exports and dynamic loading capabilities.
*/
// Core helper modules
2025-06-10 12:45:35 +02:00
const menuUtils = require('./src/helper/menuUtils.js');
2025-06-12 17:04:02 +02:00
const outputUtils = require('./src/helper/outputUtils.js');
2025-06-10 12:45:35 +02:00
const logger = require('./src/helper/logger.js');
const validation = require('./src/helper/validationUtils.js');
2025-06-12 17:04:02 +02:00
const configUtils = require('./src/helper/configUtils.js');
2025-06-10 12:36:39 +02:00
// Domain-specific modules
2025-06-10 12:45:35 +02:00
const measurements = require('./src/measurements/index.js');
2025-06-12 17:04:02 +02:00
const nrmse = require('./src/nrmse/ErrorMetrics.js');
const state = require('./src/state/state.js');
2025-06-10 12:36:39 +02:00
// Configuration loader with error handling
2025-06-10 12:45:35 +02:00
function loadConfig(path) {
2025-06-10 12:36:39 +02:00
try {
2025-06-10 12:45:35 +02:00
return require(path);
2025-06-10 12:36:39 +02:00
} catch (error) {
console.warn(`Failed to load config: ${path}`, error);
return null;
}
}
2025-06-10 12:45:35 +02:00
// Configurations
const configs = {
2025-06-10 12:36:39 +02:00
get projectSettings() {
return loadConfig('./configs/projectSettings.json');
},
get measurementConfig() {
return loadConfig('./configs/measurementConfig.json');
}
};
// Dynamic loaders with validation
2025-06-10 12:45:35 +02:00
function loadHelper(name) {
2025-06-10 12:36:39 +02:00
if (!name || typeof name !== 'string') {
throw new Error('Helper name must be a non-empty string');
}
try {
2025-06-10 12:45:35 +02:00
return require(`./src/helper/${name}.js`);
2025-06-10 12:36:39 +02:00
} catch (error) {
throw new Error(`Failed to load helper "${name}": ${error.message}`);
}
}
2025-06-10 12:45:35 +02:00
function loadAssetDatasets() {
2025-06-10 12:36:39 +02:00
try {
2025-06-10 12:45:35 +02:00
return require('./datasets/assetData/suppliers.json');
2025-06-10 12:36:39 +02:00
} catch (error) {
throw new Error(`Failed to load asset datasets: ${error.message}`);
}
}
2025-06-10 12:45:35 +02:00
// Export everything
module.exports = {
menuUtils,
2025-06-12 17:04:02 +02:00
outputUtils,
configUtils,
2025-06-10 12:45:35 +02:00
logger,
validation,
measurements,
nrmse,
state,
configs,
loadHelper,
loadAssetDatasets
};