

const filterWildCard = moduleList => {
    if (moduleList === '*') {
        return [];
    } else {
        return moduleList.filter(module => module !== '*');
    }
};

const getRoot = () => {
    const vm2Conf = config.get("vm2");
    return vm2Conf && vm2Conf.root ? vm2Conf.root : './';
};

const getExternalWhitelist = () => {
    const vm2Conf = config.get("vm2");
    let external = vm2Conf && vm2Conf.externalModuleWhitelist ? vm2Conf.externalModuleWhitelist : [];
    return filterWildCard(external);
};

const getBuiltInWhitelist = () => {
    const vm2Conf = config.get("vm2");
    let builtin = vm2Conf && vm2Conf.builtinModuleWhitelist ? vm2Conf.builtinModuleWhitelist : [];
    return filterWildCard(builtin);
};

module.exports = {
    getExternalWhitelist,
    getBuiltInWhitelist,
    getRoot
};