@humanwhocodes/env
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -25,3 +25,3 @@ 'use strict'; | ||
if (typeof Deno !== "undefined") { | ||
return Deno.env(); | ||
return Deno.env.toObject(); | ||
} | ||
@@ -28,0 +28,0 @@ |
@@ -21,3 +21,3 @@ /** | ||
if (typeof Deno !== "undefined") { | ||
return Deno.env(); | ||
return Deno.env.toObject(); | ||
} | ||
@@ -24,0 +24,0 @@ |
@@ -1,1 +0,1 @@ | ||
const defaultEnvSource=(()=>"object"==typeof process?process.env:"undefined"==typeof Deno?{}:Deno.env())();function keyNotFound(a){throw new Error(`Required environment variable '${a}' not found.`)}function emptyString(a){throw new Error(`Required environment variable '${a}' is an empty string.`)}class Env{constructor(a=defaultEnvSource){this.source=a}get(a,b=null){return a in this.source?this.source[a]:b}has(a){return a in this.source}first(a,b=null){if(!Array.isArray(a)||2>a.length)throw new TypeError("First argument must be an array of two or more strings.");for(const c of a)if(c in this.source)return this.source[c];return b}require(a){const b=this.get(a);if(null===b)keyNotFound(a);else if(""===b)throw emptyString(a);else return b}get exists(){const a=new Proxy(this.source,{get(a,b){return b in a?a[b]:void keyNotFound(b)}});return Object.defineProperty(this,"exists",{value:a,writable:!1,enumerable:!1,configurable:!1}),a}get required(){const a=new Proxy(this.source,{get(a,b){return b in a?(""===a[b]&&emptyString(b),a[b]):void keyNotFound(b)}});return Object.defineProperty(this,"required",{value:a,writable:!1,enumerable:!1,configurable:!1}),a}}export{Env}; | ||
const defaultEnvSource=(()=>"object"==typeof process?process.env:"undefined"==typeof Deno?{}:Deno.env.toObject())();function keyNotFound(a){throw new Error(`Required environment variable '${a}' not found.`)}function emptyString(a){throw new Error(`Required environment variable '${a}' is an empty string.`)}class Env{constructor(a=defaultEnvSource){this.source=a}get(a,b=null){return a in this.source?this.source[a]:b}has(a){return a in this.source}first(a,b=null){if(!Array.isArray(a)||2>a.length)throw new TypeError("First argument must be an array of two or more strings.");for(const c of a)if(c in this.source)return this.source[c];return b}require(a){const b=this.get(a);if(null===b)keyNotFound(a);else if(""===b)throw emptyString(a);else return b}get exists(){const a=new Proxy(this.source,{get(a,b){return b in a?a[b]:void keyNotFound(b)}});return Object.defineProperty(this,"exists",{value:a,writable:!1,enumerable:!1,configurable:!1}),a}get required(){const a=new Proxy(this.source,{get(a,b){return b in a?(""===a[b]&&emptyString(b),a[b]):void keyNotFound(b)}});return Object.defineProperty(this,"required",{value:a,writable:!1,enumerable:!1,configurable:!1}),a}}export{Env}; |
{ | ||
"name": "@humanwhocodes/env", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A utility to verify that environment variables exist.", | ||
@@ -5,0 +5,0 @@ "main": "dist/env.cjs.js", |
@@ -45,3 +45,3 @@ # Env utility | ||
By default, an `Env` instance will read from `Deno.env()`. | ||
By default, an `Env` instance will read from `Deno.env`. | ||
@@ -48,0 +48,0 @@ ### Browser |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18300