changed the folder and added index.js
This commit is contained in:
60
index.js
Normal file
60
index.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* generalFunctions/index.js
|
||||
* -----------------------------------------------------------
|
||||
* Central barrel file for re-exporting helpers and configurations.
|
||||
* Provides both namespace exports and dynamic loading capabilities.
|
||||
*/
|
||||
|
||||
// Core helper modules
|
||||
export * as menuUtils from './src/helper/menuUtils.js';
|
||||
export * as logger from './src/helper/logger.js';
|
||||
export * as validation from './src/helper/validationUtils.js';
|
||||
|
||||
// Domain-specific modules
|
||||
export * as measurements from './src/measurements/index.js';
|
||||
export * as nrmse from './src/nrmse/index.js';
|
||||
export * as state from './src/state/index.js';
|
||||
|
||||
// Configuration loader with error handling
|
||||
async function loadConfig(path) {
|
||||
try {
|
||||
const module = await import(path, { assert: { type: 'json' } });
|
||||
return module.default;
|
||||
} catch (error) {
|
||||
console.warn(`Failed to load config: ${path}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Lazy-loaded configurations
|
||||
export const configs = {
|
||||
get projectSettings() {
|
||||
return loadConfig('./configs/projectSettings.json');
|
||||
},
|
||||
get measurementConfig() {
|
||||
return loadConfig('./configs/measurementConfig.json');
|
||||
}
|
||||
};
|
||||
|
||||
// Dynamic loaders with validation
|
||||
export async function loadHelper(name) {
|
||||
if (!name || typeof name !== 'string') {
|
||||
throw new Error('Helper name must be a non-empty string');
|
||||
}
|
||||
|
||||
try {
|
||||
return await import(`./src/helper/${name}.js`);
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to load helper "${name}": ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadAssetDatasets() {
|
||||
try {
|
||||
return await import('./datasets/assetData/suppliers.json', {
|
||||
assert: { type: 'json' }
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to load asset datasets: ${error.message}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user