Comparing version 2.0.0 to 2.0.1
@@ -247,3 +247,9 @@ 'use strict'; | ||
if (raw === undefined) { | ||
throw new MissingEnvError("Missing value"); | ||
var errMessage = "Missing value"; | ||
if (!validator.allowEmpty) { | ||
errMessage += ' or empty string'; | ||
} | ||
throw new MissingEnvError(errMessage); | ||
} | ||
@@ -250,0 +256,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function i(t,e,r){return(i=o()?Reflect.construct:function(t,e,r){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return r&&n(i,r.prototype),i}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,o)}function o(){return i(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)})(t)}function c(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}Object.defineProperty(exports,"__esModule",{value:!0});var s=function(t){function r(e){var n;return n=t.call(this,e)||this,Object.setPrototypeOf(c(n),r.prototype),n}return e(r,t),r}(u(TypeError)),a=function(t,e){return new s("Invalid "+t+' input: "'+e+'"')},f=function(t){function r(e){var n;return n=t.call(this,e)||this,Object.setPrototypeOf(c(n),r.prototype),n}return e(r,t),r}(u(ReferenceError)),p=["length","inspect","hasOwnProperty","toJSON","asymmetricMatch","nodeType","$$typeof","constructor","@@__IMMUTABLE_ITERABLE__@@","@@__IMMUTABLE_RECORD__@@","_isMockFunction","then","__esModule"];function l(t,e){var r=Object.freeze?Object.freeze(t):t;return global.Proxy?new Proxy(r,{get:function(t,n){if("string"!=typeof n||p.includes(n))return r[n];if(!r.hasOwnProperty(n)){if(e.hasOwnProperty(n))throw new ReferenceError("[envsafe] Env var "+String(n)+" was accessed but not validated. This var is set in the environment; please add an envsafe validator for it.");throw new ReferenceError('[envsafe] Env var "'+String(n)+'" not found')}return r[n]}}):r}function v(t){for(var e=t.errors,r=[],n=[],o=0,i=Object.keys(e);o<i.length;o++){var u=i[o],c=e[u];c instanceof f?n.push(" "+u+": "+(c.message||"required")):r.push(" "+u+": "+(c.message||"invalid"))}return r.length&&r.unshift("❌ Invalid environment variables:"),n.length&&n.unshift("💨 Missing environment variables:"),["========================================"].concat(r,n,["========================================"]).join("\n")}function d(t){var e,r=v(t);throw console.error(r),"undefined"!=typeof window&&(null==(e=window)?void 0:e.alert)&&window.alert(r),new TypeError(r)}function h(t){var e,r=t.env,n=t.validator,o=null!=(e=n.input)?e:r[t.key];if(n.allowEmpty||""!==o||(o=void 0),void 0===o&&"production"!==r.NODE_ENV&&void 0!==n.devDefault&&(o=n.devDefault),void 0===o&&void 0!==n.default&&(o=n.default),void 0===o)throw new f("Missing value");var i=n._parse(o);if(n.choices&&!n.choices.includes(i))throw new s('Value "'+i+'" not in choices ['+n.choices+"]");return i}var y=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function w(e){return function(r){return void 0===r&&(r={}),t({},r,{_parse:e})}}var O=w((function(t){switch(t){case!0:case"true":case"t":case"1":return!0;case!1:case"false":case"f":case"0":return!1;default:throw a("str",t)}})),b=w((function(t){if("string"!=typeof t)throw a("str",t);return t})),_=w((function(t){if(!y.test(t))throw a("email",t);return t})),g=w((function(t){var e=+t;if(Number.isNaN(e))throw a("num",t);return e})),E=w((function(t){var e=+t;if(Number.isNaN(e)||""+e!=""+t||e%1!=0||e<1||e>65535)throw a("port",t);return e})),x=w((function(t){try{return new URL(t),t}catch(e){throw a("url",t)}})),j=w((function(t){try{return"string"!=typeof t?t:JSON.parse(t)}catch(e){throw a("json",t)}}));exports.InvalidEnvError=s,exports.MissingEnvError=f,exports.bool=O,exports.defaultReporter=d,exports.defaultReporterText=v,exports.email=_,exports.envsafe=function(t,e){var r=void 0===e?{}:e,n=r.reporter,o=void 0===n?d:n,i=r.env,u=void 0===i?process.env:i,c=r.strict,s=void 0!==c&&c,a={},f={};for(var p in t){var v=t[p];try{var y=h({env:u,validator:v,key:p});f[p]=y}catch(t){a[p]=t}}return Object.keys(a).length&&o({errors:a,output:f,env:u}),s?l(f,u):f},exports.freezeObject=l,exports.invalidEnvError=a,exports.json=j,exports.makeValidator=w,exports.num=g,exports.port=E,exports.str=b,exports.url=x; | ||
"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function i(t,e,r){return(i=o()?Reflect.construct:function(t,e,r){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return r&&n(i,r.prototype),i}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,o)}function o(){return i(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)})(t)}function c(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}Object.defineProperty(exports,"__esModule",{value:!0});var a=function(t){function r(e){var n;return n=t.call(this,e)||this,Object.setPrototypeOf(c(n),r.prototype),n}return e(r,t),r}(u(TypeError)),s=function(t,e){return new a("Invalid "+t+' input: "'+e+'"')},f=function(t){function r(e){var n;return n=t.call(this,e)||this,Object.setPrototypeOf(c(n),r.prototype),n}return e(r,t),r}(u(ReferenceError)),p=["length","inspect","hasOwnProperty","toJSON","asymmetricMatch","nodeType","$$typeof","constructor","@@__IMMUTABLE_ITERABLE__@@","@@__IMMUTABLE_RECORD__@@","_isMockFunction","then","__esModule"];function l(t,e){var r=Object.freeze?Object.freeze(t):t;return global.Proxy?new Proxy(r,{get:function(t,n){if("string"!=typeof n||p.includes(n))return r[n];if(!r.hasOwnProperty(n)){if(e.hasOwnProperty(n))throw new ReferenceError("[envsafe] Env var "+String(n)+" was accessed but not validated. This var is set in the environment; please add an envsafe validator for it.");throw new ReferenceError('[envsafe] Env var "'+String(n)+'" not found')}return r[n]}}):r}function v(t){for(var e=t.errors,r=[],n=[],o=0,i=Object.keys(e);o<i.length;o++){var u=i[o],c=e[u];c instanceof f?n.push(" "+u+": "+(c.message||"required")):r.push(" "+u+": "+(c.message||"invalid"))}return r.length&&r.unshift("❌ Invalid environment variables:"),n.length&&n.unshift("💨 Missing environment variables:"),["========================================"].concat(r,n,["========================================"]).join("\n")}function d(t){var e,r=v(t);throw console.error(r),"undefined"!=typeof window&&(null==(e=window)?void 0:e.alert)&&window.alert(r),new TypeError(r)}function h(t){var e,r=t.env,n=t.validator,o=null!=(e=n.input)?e:r[t.key];if(n.allowEmpty||""!==o||(o=void 0),void 0===o&&"production"!==r.NODE_ENV&&void 0!==n.devDefault&&(o=n.devDefault),void 0===o&&void 0!==n.default&&(o=n.default),void 0===o){var i="Missing value";throw n.allowEmpty||(i+=" or empty string"),new f(i)}var u=n._parse(o);if(n.choices&&!n.choices.includes(u))throw new a('Value "'+u+'" not in choices ['+n.choices+"]");return u}var y=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function w(e){return function(r){return void 0===r&&(r={}),t({},r,{_parse:e})}}var O=w((function(t){switch(t){case!0:case"true":case"t":case"1":return!0;case!1:case"false":case"f":case"0":return!1;default:throw s("str",t)}})),b=w((function(t){if("string"!=typeof t)throw s("str",t);return t})),_=w((function(t){if(!y.test(t))throw s("email",t);return t})),g=w((function(t){var e=+t;if(Number.isNaN(e))throw s("num",t);return e})),E=w((function(t){var e=+t;if(Number.isNaN(e)||""+e!=""+t||e%1!=0||e<1||e>65535)throw s("port",t);return e})),x=w((function(t){try{return new URL(t),t}catch(e){throw s("url",t)}})),m=w((function(t){try{return"string"!=typeof t?t:JSON.parse(t)}catch(e){throw s("json",t)}}));exports.InvalidEnvError=a,exports.MissingEnvError=f,exports.bool=O,exports.defaultReporter=d,exports.defaultReporterText=v,exports.email=_,exports.envsafe=function(t,e){var r=void 0===e?{}:e,n=r.reporter,o=void 0===n?d:n,i=r.env,u=void 0===i?process.env:i,c=r.strict,a=void 0!==c&&c,s={},f={};for(var p in t){var v=t[p];try{var y=h({env:u,validator:v,key:p});f[p]=y}catch(t){s[p]=t}}return Object.keys(s).length&&o({errors:s,output:f,env:u}),a?l(f,u):f},exports.freezeObject=l,exports.invalidEnvError=s,exports.json=m,exports.makeValidator=w,exports.num=g,exports.port=E,exports.str=b,exports.url=x; | ||
//# sourceMappingURL=envsafe.cjs.production.min.js.map |
@@ -243,3 +243,9 @@ function _extends() { | ||
if (raw === undefined) { | ||
throw new MissingEnvError("Missing value"); | ||
var errMessage = "Missing value"; | ||
if (!validator.allowEmpty) { | ||
errMessage += ' or empty string'; | ||
} | ||
throw new MissingEnvError(errMessage); | ||
} | ||
@@ -246,0 +252,0 @@ |
{ | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -12,4 +12,4 @@ [![Maintainability](https://api.codeclimate.com/v1/badges/c17614f0d80b810e47a6/maintainability)](https://codeclimate.com/github/KATT/envsafe/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/c17614f0d80b810e47a6/test_coverage)](https://codeclimate.com/github/KATT/envsafe/test_coverage) | ||
💨 Missing environment variables: | ||
MY_VAR: Missing value | ||
PORT: Missing value | ||
MY_VAR: Missing value or empty string | ||
PORT: Missing value or empty string | ||
======================================== | ||
@@ -16,0 +16,0 @@ ``` |
@@ -40,3 +40,7 @@ import { InvalidEnvError, MissingEnvError } from './errors'; | ||
if (raw === undefined) { | ||
throw new MissingEnvError(`Missing value`); | ||
let errMessage = `Missing value`; | ||
if (!validator.allowEmpty) { | ||
errMessage += ' or empty string'; | ||
} | ||
throw new MissingEnvError(errMessage); | ||
} | ||
@@ -43,0 +47,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
89570
1093