Files
generalFunctions/index.js
znetsixe 26ed170932 update
2025-06-10 12:45:35 +02:00

70 lines
1.8 KiB
JavaScript

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