Comparing version 0.1.4 to 0.2.0
@@ -121,27 +121,30 @@ 'use strict'; | ||
var EnvError = /*#__PURE__*/function (_TypeError) { | ||
_inheritsLoose(EnvError, _TypeError); | ||
var InvalidEnvError = /*#__PURE__*/function (_TypeError) { | ||
_inheritsLoose(InvalidEnvError, _TypeError); | ||
function EnvError(message) { | ||
function InvalidEnvError(message) { | ||
var _this; | ||
_this = _TypeError.call(this, message) || this; | ||
Object.setPrototypeOf(_assertThisInitialized(_this), EnvError.prototype); | ||
Object.setPrototypeOf(_assertThisInitialized(_this), InvalidEnvError.prototype); | ||
return _this; | ||
} | ||
return EnvError; | ||
return InvalidEnvError; | ||
}( /*#__PURE__*/_wrapNativeSuper(TypeError)); | ||
var EnvMissingError = /*#__PURE__*/function (_ReferenceError) { | ||
_inheritsLoose(EnvMissingError, _ReferenceError); | ||
var invalidEnvError = function invalidEnvError(type, input) { | ||
return new InvalidEnvError("Invalid " + type + " input: \"" + input + "\""); | ||
}; | ||
var MissingEnvError = /*#__PURE__*/function (_ReferenceError) { | ||
_inheritsLoose(MissingEnvError, _ReferenceError); | ||
function EnvMissingError(message) { | ||
function MissingEnvError(message) { | ||
var _this2; | ||
_this2 = _ReferenceError.call(this, message) || this; | ||
Object.setPrototypeOf(_assertThisInitialized(_this2), EnvMissingError.prototype); | ||
Object.setPrototypeOf(_assertThisInitialized(_this2), MissingEnvError.prototype); | ||
return _this2; | ||
} | ||
return EnvMissingError; | ||
return MissingEnvError; | ||
}( /*#__PURE__*/_wrapNativeSuper(ReferenceError)); | ||
@@ -159,6 +162,6 @@ | ||
if (err instanceof EnvMissingError) { | ||
if (err instanceof MissingEnvError) { | ||
missing.push(" " + key + ": " + (err.message || 'required')); | ||
} else { | ||
invalids.push(" " + key + ": " + (err.message || 'required')); | ||
invalids.push(" " + key + ": " + (err.message || 'invalid')); | ||
} | ||
@@ -179,10 +182,16 @@ } | ||
function defaultReporter(opts) { | ||
var _process, _window; | ||
var text = defaultReporterText(opts); | ||
console.error(text); | ||
if (typeof process !== 'undefined') { | ||
if (typeof process !== 'undefined' && ((_process = process) === null || _process === void 0 ? void 0 : _process.exit)) { | ||
process.exit(1); | ||
} | ||
throw new Error("Invalid/missing environment variables: " + Object.keys(opts.errors).join(', ')); | ||
if (typeof window !== 'undefined' && ((_window = window) === null || _window === void 0 ? void 0 : _window.alert)) { | ||
window.alert(text); | ||
} | ||
throw new Error(text); | ||
} | ||
@@ -206,3 +215,3 @@ | ||
if (raw === undefined) { | ||
throw new EnvMissingError("Missing value for " + key); | ||
throw new MissingEnvError("Missing value for " + key); | ||
} | ||
@@ -213,3 +222,3 @@ | ||
if (validator.choices && !validator.choices.includes(value)) { | ||
throw new EnvError("Value \"" + value + "\" not in choices [" + validator.choices + "]"); | ||
throw new InvalidEnvError("Value \"" + value + "\" not in choices [" + validator.choices + "]"); | ||
} | ||
@@ -282,3 +291,3 @@ | ||
default: | ||
throw new EnvError("Invalid boolean input: \"" + input + "\""); | ||
throw invalidEnvError('str', input); | ||
} | ||
@@ -288,3 +297,3 @@ }); | ||
if (typeof input !== 'string') { | ||
throw new EnvError("Invalid string input: \"" + input + "\""); | ||
throw invalidEnvError('str', input); | ||
} | ||
@@ -296,3 +305,3 @@ | ||
if (!EMAIL_REGEX.test(input)) { | ||
throw new EnvError("Invalid email address: \"" + input + "\""); | ||
throw invalidEnvError('email', input); | ||
} | ||
@@ -306,3 +315,3 @@ | ||
if (Number.isNaN(coerced)) { | ||
throw new EnvError("Invalid number input: \"" + input + "\""); | ||
throw invalidEnvError('num', input); | ||
} | ||
@@ -316,3 +325,3 @@ | ||
if (Number.isNaN(coerced) || "" + coerced !== "" + input || coerced % 1 !== 0 || coerced < 1 || coerced > 65535) { | ||
throw new EnvError("Invalid port input: \"" + input + "\""); | ||
throw invalidEnvError('port', input); | ||
} | ||
@@ -328,3 +337,3 @@ | ||
} catch (_) { | ||
throw new EnvError("Invalid url: \"" + input + "\""); | ||
throw invalidEnvError('url', input); | ||
} | ||
@@ -340,8 +349,8 @@ }); | ||
} catch (e) { | ||
throw new EnvError("Invalid json: \"" + input + "\""); | ||
throw invalidEnvError('json', input); | ||
} | ||
}); | ||
exports.EnvError = EnvError; | ||
exports.EnvMissingError = EnvMissingError; | ||
exports.InvalidEnvError = InvalidEnvError; | ||
exports.MissingEnvError = MissingEnvError; | ||
exports.bool = bool; | ||
@@ -352,2 +361,3 @@ exports.cleanEnv = cleanEnv; | ||
exports.email = email; | ||
exports.invalidEnvError = invalidEnvError; | ||
exports.json = json; | ||
@@ -354,0 +364,0 @@ exports.makeValidator = makeValidator; |
@@ -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){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));function f(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 a?n.push(" "+u+": "+(c.message||"required")):r.push(" "+u+": "+(c.message||"required"))}return r.length&&r.unshift("❌ Invalid environment variables:"),n.length&&n.unshift("💨 Missing environment variables:"),["================================"].concat(r,n,["================================"]).join("\n")}function p(t){var e=f(t);throw console.error(e),"undefined"!=typeof process&&process.exit(1),new Error("Invalid/missing environment variables: "+Object.keys(t.errors).join(", "))}function l(t){var e=t.env,r=t.validator,n=t.key,o=e[n];if(void 0===o&&"production"!==e.NODE_ENV&&void 0!==r.devDefault&&(o=r.devDefault),void 0===o&&void 0!==r.default&&(o=r.default),void 0===o)throw new a("Missing value for "+n);var i=r._parse(o);if(r.choices&&!r.choices.includes(i))throw new s('Value "'+i+'" not in choices ['+r.choices+"]");return i}var v=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function d(e){return function(r){return void 0===r&&(r={}),t({},r,{_parse:e})}}var h=d((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 new s('Invalid boolean input: "'+t+'"')}})),y=d((function(t){if("string"!=typeof t)throw new s('Invalid string input: "'+t+'"');return t})),b=d((function(t){if(!v.test(t))throw new s('Invalid email address: "'+t+'"');return t})),w=d((function(t){var e=+t;if(Number.isNaN(e))throw new s('Invalid number input: "'+t+'"');return e})),O=d((function(t){var e=+t;if(Number.isNaN(e)||""+e!=""+t||e%1!=0||e<1||e>65535)throw new s('Invalid port input: "'+t+'"');return e})),g=d((function(t){try{return new URL(t),t}catch(e){throw new s('Invalid url: "'+t+'"')}})),j=d((function(t){try{return"string"!=typeof t?t:JSON.parse(t)}catch(e){throw new s('Invalid json: "'+t+'"')}}));exports.EnvError=s,exports.EnvMissingError=a,exports.bool=h,exports.cleanEnv=function(t,e,r){var n=(void 0===r?{}:r).reporter,o=void 0===n?p:n,i={},u={};for(var c in e){var s=e[c];try{var a=l({env:t,validator:s,key:c});u[c]=a}catch(t){i[c]=t}}return Object.keys(i).length&&o({errors:i,output:u,env:t}),Object.freeze?Object.freeze(u):u},exports.defaultReporter=p,exports.defaultReporterText=f,exports.email=b,exports.json=j,exports.makeValidator=d,exports.num=w,exports.port=O,exports.str=y,exports.url=g; | ||
"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));function p(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 l(t){var e,r,n=p(t);throw console.error(n),"undefined"!=typeof process&&(null===(e=process)||void 0===e?void 0:e.exit)&&process.exit(1),"undefined"!=typeof window&&(null===(r=window)||void 0===r?void 0:r.alert)&&window.alert(n),new Error(n)}function v(t){var e=t.env,r=t.validator,n=t.key,o=e[n];if(void 0===o&&"production"!==e.NODE_ENV&&void 0!==r.devDefault&&(o=r.devDefault),void 0===o&&void 0!==r.default&&(o=r.default),void 0===o)throw new f("Missing value for "+n);var i=r._parse(o);if(r.choices&&!r.choices.includes(i))throw new s('Value "'+i+'" not in choices ['+r.choices+"]");return i}var d=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function h(e){return function(r){return void 0===r&&(r={}),t({},r,{_parse:e})}}var y=h((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)}})),w=h((function(t){if("string"!=typeof t)throw a("str",t);return t})),b=h((function(t){if(!d.test(t))throw a("email",t);return t})),O=h((function(t){var e=+t;if(Number.isNaN(e))throw a("num",t);return e})),x=h((function(t){var e=+t;if(Number.isNaN(e)||""+e!=""+t||e%1!=0||e<1||e>65535)throw a("port",t);return e})),g=h((function(t){try{return new URL(t),t}catch(e){throw a("url",t)}})),j=h((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=y,exports.cleanEnv=function(t,e,r){var n=(void 0===r?{}:r).reporter,o=void 0===n?l:n,i={},u={};for(var c in e){var s=e[c];try{var a=v({env:t,validator:s,key:c});u[c]=a}catch(t){i[c]=t}}return Object.keys(i).length&&o({errors:i,output:u,env:t}),Object.freeze?Object.freeze(u):u},exports.defaultReporter=l,exports.defaultReporterText=p,exports.email=b,exports.invalidEnvError=a,exports.json=j,exports.makeValidator=h,exports.num=O,exports.port=x,exports.str=w,exports.url=g; | ||
//# sourceMappingURL=envsafe.cjs.production.min.js.map |
@@ -117,27 +117,30 @@ function _extends() { | ||
var EnvError = /*#__PURE__*/function (_TypeError) { | ||
_inheritsLoose(EnvError, _TypeError); | ||
var InvalidEnvError = /*#__PURE__*/function (_TypeError) { | ||
_inheritsLoose(InvalidEnvError, _TypeError); | ||
function EnvError(message) { | ||
function InvalidEnvError(message) { | ||
var _this; | ||
_this = _TypeError.call(this, message) || this; | ||
Object.setPrototypeOf(_assertThisInitialized(_this), EnvError.prototype); | ||
Object.setPrototypeOf(_assertThisInitialized(_this), InvalidEnvError.prototype); | ||
return _this; | ||
} | ||
return EnvError; | ||
return InvalidEnvError; | ||
}( /*#__PURE__*/_wrapNativeSuper(TypeError)); | ||
var EnvMissingError = /*#__PURE__*/function (_ReferenceError) { | ||
_inheritsLoose(EnvMissingError, _ReferenceError); | ||
var invalidEnvError = function invalidEnvError(type, input) { | ||
return new InvalidEnvError("Invalid " + type + " input: \"" + input + "\""); | ||
}; | ||
var MissingEnvError = /*#__PURE__*/function (_ReferenceError) { | ||
_inheritsLoose(MissingEnvError, _ReferenceError); | ||
function EnvMissingError(message) { | ||
function MissingEnvError(message) { | ||
var _this2; | ||
_this2 = _ReferenceError.call(this, message) || this; | ||
Object.setPrototypeOf(_assertThisInitialized(_this2), EnvMissingError.prototype); | ||
Object.setPrototypeOf(_assertThisInitialized(_this2), MissingEnvError.prototype); | ||
return _this2; | ||
} | ||
return EnvMissingError; | ||
return MissingEnvError; | ||
}( /*#__PURE__*/_wrapNativeSuper(ReferenceError)); | ||
@@ -155,6 +158,6 @@ | ||
if (err instanceof EnvMissingError) { | ||
if (err instanceof MissingEnvError) { | ||
missing.push(" " + key + ": " + (err.message || 'required')); | ||
} else { | ||
invalids.push(" " + key + ": " + (err.message || 'required')); | ||
invalids.push(" " + key + ": " + (err.message || 'invalid')); | ||
} | ||
@@ -175,10 +178,16 @@ } | ||
function defaultReporter(opts) { | ||
var _process, _window; | ||
var text = defaultReporterText(opts); | ||
console.error(text); | ||
if (typeof process !== 'undefined') { | ||
if (typeof process !== 'undefined' && ((_process = process) === null || _process === void 0 ? void 0 : _process.exit)) { | ||
process.exit(1); | ||
} | ||
throw new Error("Invalid/missing environment variables: " + Object.keys(opts.errors).join(', ')); | ||
if (typeof window !== 'undefined' && ((_window = window) === null || _window === void 0 ? void 0 : _window.alert)) { | ||
window.alert(text); | ||
} | ||
throw new Error(text); | ||
} | ||
@@ -202,3 +211,3 @@ | ||
if (raw === undefined) { | ||
throw new EnvMissingError("Missing value for " + key); | ||
throw new MissingEnvError("Missing value for " + key); | ||
} | ||
@@ -209,3 +218,3 @@ | ||
if (validator.choices && !validator.choices.includes(value)) { | ||
throw new EnvError("Value \"" + value + "\" not in choices [" + validator.choices + "]"); | ||
throw new InvalidEnvError("Value \"" + value + "\" not in choices [" + validator.choices + "]"); | ||
} | ||
@@ -278,3 +287,3 @@ | ||
default: | ||
throw new EnvError("Invalid boolean input: \"" + input + "\""); | ||
throw invalidEnvError('str', input); | ||
} | ||
@@ -284,3 +293,3 @@ }); | ||
if (typeof input !== 'string') { | ||
throw new EnvError("Invalid string input: \"" + input + "\""); | ||
throw invalidEnvError('str', input); | ||
} | ||
@@ -292,3 +301,3 @@ | ||
if (!EMAIL_REGEX.test(input)) { | ||
throw new EnvError("Invalid email address: \"" + input + "\""); | ||
throw invalidEnvError('email', input); | ||
} | ||
@@ -302,3 +311,3 @@ | ||
if (Number.isNaN(coerced)) { | ||
throw new EnvError("Invalid number input: \"" + input + "\""); | ||
throw invalidEnvError('num', input); | ||
} | ||
@@ -312,3 +321,3 @@ | ||
if (Number.isNaN(coerced) || "" + coerced !== "" + input || coerced % 1 !== 0 || coerced < 1 || coerced > 65535) { | ||
throw new EnvError("Invalid port input: \"" + input + "\""); | ||
throw invalidEnvError('port', input); | ||
} | ||
@@ -324,3 +333,3 @@ | ||
} catch (_) { | ||
throw new EnvError("Invalid url: \"" + input + "\""); | ||
throw invalidEnvError('url', input); | ||
} | ||
@@ -336,7 +345,7 @@ }); | ||
} catch (e) { | ||
throw new EnvError("Invalid json: \"" + input + "\""); | ||
throw invalidEnvError('json', input); | ||
} | ||
}); | ||
export { EnvError, EnvMissingError, bool, cleanEnv, defaultReporter, defaultReporterText, email, json, makeValidator, num, port, str, url }; | ||
export { InvalidEnvError, MissingEnvError, bool, cleanEnv, defaultReporter, defaultReporterText, email, invalidEnvError, json, makeValidator, num, port, str, url }; | ||
//# sourceMappingURL=envsafe.esm.js.map |
@@ -1,6 +0,7 @@ | ||
export declare class EnvError extends TypeError { | ||
export declare class InvalidEnvError extends TypeError { | ||
constructor(message?: string); | ||
} | ||
export declare class EnvMissingError extends ReferenceError { | ||
export declare const invalidEnvError: (type: string, input: unknown) => InvalidEnvError; | ||
export declare class MissingEnvError extends ReferenceError { | ||
constructor(message?: string); | ||
} |
{ | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -37,8 +37,8 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"husky": "^4.3.0", | ||
"husky": "4.3.0", | ||
"np": "*", | ||
"tsdx": "^0.13.3", | ||
"tslib": "^2.0.1", | ||
"typescript": "^4.0.2" | ||
"tsdx": "0.13.3", | ||
"tslib": "2.0.1", | ||
"typescript": "4.0.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { EnvError, EnvMissingError } from './errors'; | ||
import { InvalidEnvError, MissingEnvError } from './errors'; | ||
import { defaultReporter } from './reporter'; | ||
@@ -35,3 +35,3 @@ import { | ||
if (raw === undefined) { | ||
throw new EnvMissingError(`Missing value for ${key}`); | ||
throw new MissingEnvError(`Missing value for ${key}`); | ||
} | ||
@@ -42,3 +42,3 @@ | ||
if (validator.choices && !validator.choices.includes(value)) { | ||
throw new EnvError( | ||
throw new InvalidEnvError( | ||
`Value "${value}" not in choices [${validator.choices}]` | ||
@@ -45,0 +45,0 @@ ); |
@@ -1,14 +0,17 @@ | ||
export class EnvError extends TypeError { | ||
export class InvalidEnvError extends TypeError { | ||
constructor(message?: string) { | ||
super(message); | ||
Object.setPrototypeOf(this, EnvError.prototype); | ||
Object.setPrototypeOf(this, InvalidEnvError.prototype); | ||
} | ||
} | ||
export class EnvMissingError extends ReferenceError { | ||
export const invalidEnvError = (type: string, input: unknown) => | ||
new InvalidEnvError(`Invalid ${type} input: "${input}"`); | ||
export class MissingEnvError extends ReferenceError { | ||
constructor(message?: string) { | ||
super(message); | ||
Object.setPrototypeOf(this, EnvMissingError.prototype); | ||
Object.setPrototypeOf(this, MissingEnvError.prototype); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { EnvMissingError } from './errors'; | ||
import { MissingEnvError } from './errors'; | ||
import { ReporterOpts } from './types'; | ||
@@ -14,6 +14,6 @@ | ||
const err = errors[key]; | ||
if (err instanceof EnvMissingError) { | ||
if (err instanceof MissingEnvError) { | ||
missing.push(` ${key}: ${err.message || 'required'}`); | ||
} else { | ||
invalids.push(` ${key}: ${err.message || 'required'}`); | ||
invalids.push(` ${key}: ${err.message || 'invalid'}`); | ||
} | ||
@@ -42,11 +42,10 @@ } | ||
if (typeof process !== 'undefined') { | ||
if (typeof process !== 'undefined' && process?.exit) { | ||
process.exit(1); | ||
} | ||
if (typeof window !== 'undefined' && window?.alert) { | ||
window.alert(text); | ||
} | ||
throw new Error( | ||
`Invalid/missing environment variables: ${Object.keys(opts.errors).join( | ||
', ' | ||
)}` | ||
); | ||
throw new Error(text); | ||
} |
@@ -1,2 +0,2 @@ | ||
import { EnvError } from './errors'; | ||
import { invalidEnvError } from './errors'; | ||
import { Spec, ValidatorSpec } from './types'; | ||
@@ -29,3 +29,3 @@ const EMAIL_REGEX = /^[^@\s]+@[^@\s]+\.[^@\s]+$/; // intentionally non-exhaustive | ||
default: | ||
throw new EnvError(`Invalid boolean input: "${input}"`); | ||
throw invalidEnvError('str', input); | ||
} | ||
@@ -36,3 +36,3 @@ }); | ||
if (typeof input !== 'string') { | ||
throw new EnvError(`Invalid string input: "${input}"`); | ||
throw invalidEnvError('str', input); | ||
} | ||
@@ -44,3 +44,3 @@ return input; | ||
if (!EMAIL_REGEX.test(input)) { | ||
throw new EnvError(`Invalid email address: "${input}"`); | ||
throw invalidEnvError('email', input); | ||
} | ||
@@ -53,3 +53,3 @@ return input; | ||
if (Number.isNaN(coerced)) { | ||
throw new EnvError(`Invalid number input: "${input}"`); | ||
throw invalidEnvError('num', input); | ||
} | ||
@@ -68,3 +68,3 @@ return coerced; | ||
) { | ||
throw new EnvError(`Invalid port input: "${input}"`); | ||
throw invalidEnvError('port', input); | ||
} | ||
@@ -79,3 +79,3 @@ return coerced; | ||
} catch (_) { | ||
throw new EnvError(`Invalid url: "${input}"`); | ||
throw invalidEnvError('url', input); | ||
} | ||
@@ -92,4 +92,4 @@ }); | ||
} catch (e) { | ||
throw new EnvError(`Invalid json: "${input}"`); | ||
throw invalidEnvError('json', input); | ||
} | ||
}); |
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
67510
900