/** * 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 outputUtils = require('./src/helper/outputUtils.js'); const logger = require('./src/helper/logger.js'); const validation = require('./src/helper/validationUtils.js'); const configUtils = require('./src/helper/configUtils.js'); // Domain-specific modules const measurements = require('./src/measurements/index.js'); const nrmse = require('./src/nrmse/ErrorMetrics.js'); const state = require('./src/state/state.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, outputUtils, configUtils, logger, validation, measurements, nrmse, state, configs, loadHelper, loadAssetDatasets };