UNPKG

@liplum/env

Version:

Reading and parsing environment variables from "process.env"

38 lines 1 kB
import { EnvMixin } from "./shared.js"; export class UrlEnv extends EnvMixin { getOrNull = () => { const raw = this.env.getOrNull() ?? this.getDefaultValue(); if (raw === undefined) { return; } try { const result = new URL(raw); return result; } catch (error) { throw new Error(`${raw} is not a valid URL.`); } }; get = () => { const result = this.getOrNull(); if (result === undefined) { throw this.missingEnvError(); } return result; }; getStringOrNull = () => { const result = this.getOrNull(); if (result === undefined) { return; } return result.toString(); }; getString = () => { const result = this.getStringOrNull(); if (result === undefined) { throw this.missingEnvError(); } return result; }; } //# sourceMappingURL=url.js.map