cartodb/lib/assets/javascripts/new-dashboard/utils/dynamic-import.js
2020-06-15 10:58:47 +08:00

17 lines
457 B
JavaScript

export function importFilesFrom (folderContext, patternNameRegex) {
const components = {};
folderContext.keys().forEach(filename => {
const name = stripTokenFromString(filename, patternNameRegex);
const component = folderContext(filename);
components[name] = component.default;
});
return components;
}
function stripTokenFromString (string, patternNameRegex) {
const results = patternNameRegex.exec(string);
return results[1];
}