src/envalidWithoutDotenv.js
function validateVar({ spec = {}, name, rawValue }) {
    if (typeof spec._parse !== 'function') {
        throw new EnvError(`Invalid spec for "${name}"`)
    }
    const value = spec._parse(rawValue)

    if (spec.choices) {
        if (!Array.isArray(spec.choices)) {
            throw new TypeError(`"choices" must be an array (in spec for "${name}")`)
        } else if (!spec.choices.includes(value)) {
            throw new EnvError(`Value "${value}" not in choices [${spec.choices}]`)
        }
    }
    if (value == null) throw new EnvError(`Invalid value for env var "${name}"`)
    return value
}
function validateVar({ spec = {}, name, rawValue }) {
    if (typeof spec._parse !== 'function') {
        throw new EnvError(`Invalid spec for "${name}"`)
    }
    const value = spec._parse(rawValue)

    if (spec.choices) {
        if (!Array.isArray(spec.choices)) {
            throw new TypeError(`"choices" must be an array (in spec for "${name}")`)
        } else if (!spec.choices.includes(value)) {
            throw new EnvError(`Value "${value}" not in choices [${spec.choices}]`)
        }
    }
    if (value == null) throw new EnvError(`Invalid value for env var "${name}"`)
    return value
}
function validateVar ( { spec = { } , name , rawValue } ) { if ( typeof spec . _parse !== 'function' ) { throw new EnvError ( ` ${ name } ` ) } const value = spec . _parse ( rawValue ) if ( spec . choices ) { if ( ! Array . isArray ( spec . choices ) ) { throw new TypeError ( ` ${ name } ` ) } else if ( ! spec . choices . includes ( value ) ) { throw new EnvError ( ` ${ value } ${ spec . choices } ` ) } } if ( value == null ) throw new EnvError ( ` ${ name } ` ) return value }
Validate a single env var, given a spec object

@throws EnvError - If validation is unsuccessful
@return - The cleaned value
Validate a single env var given a spec object