INNER CODE UNIT · TypeScript

get

getwud/wud · app/configuration/index.ts:14

export function get(prop, env = process.env) {
    const object = {};
    const envVarPattern = prop.replace(/\./g, '_').toUpperCase();
    const matchingEnvVars = Object.keys(env).filter((envKey) =>
        envKey.startsWith(envVarPattern),
    );
    matchingEnvVars.forEach((matchingEnvVar) => {
        const envVarValue = env[matchingEnvVar];
        const matchingPropPath = matchingEnvVar
            .replace(/_/g, '.')
            .toLowerCase();
        const matchingPropPathWithoutPrefix = matchingPropPath.replace(
            `${prop}.`,
            '',
        );
        setValue(object, matchingPropPathWithoutPrefix, envVarValue);
    });
    return object;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…