env-vars-validator
Advanced tools
Comparing version 1.0.3 to 1.1.2
@@ -30,3 +30,4 @@ 'use strict'; | ||
var ajv = /*#__PURE__*/new Ajv({ | ||
coerceTypes: true | ||
coerceTypes: true, | ||
useDefaults: true | ||
}); | ||
@@ -36,7 +37,10 @@ addFormats(ajv); | ||
if (options === void 0) { | ||
options = {}; | ||
options = { | ||
coerceVars: true | ||
}; | ||
} | ||
var _options = options, | ||
requiredProperties = _options.requiredProperties; | ||
requiredProperties = _options.requiredProperties, | ||
coerceVars = _options.coerceVars; | ||
@@ -54,3 +58,5 @@ if (!validationSchema) { | ||
if (!validate(process.env)) { | ||
var data = _extends({}, process.env); | ||
if (!validate(data)) { | ||
throw new Error(ajv.errorsText(validate.errors, { | ||
@@ -60,2 +66,6 @@ dataVar: 'process.env' | ||
} | ||
if (typeof coerceVars === 'undefined' ? true : coerceVars) { | ||
process.env = data; | ||
} | ||
}; | ||
@@ -62,0 +72,0 @@ var Environment; |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r,t,o=e(require("ajv")),n=e(require("ajv-formats"));function i(){return(i=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e}).apply(this,arguments)}var s,a=new o({coerceTypes:!0});n(a),function(e){e.PRODUCTION="production",e.DEVELOPMENT="development",e.TEST="test"}(s||(s={}));var p=null==(r="production".toString())||null==(t=r.toLowerCase())?void 0:t.trim(),v=p===s.PRODUCTION,u=p===s.DEVELOPMENT,c=p===s.TEST,l=p!==s.DEVELOPMENT&&p!==s.TEST;exports.currentEnv=p,exports.isDeployedEnv=l,exports.isDevelopmentEnv=u,exports.isProductionEnv=v,exports.isTestEnv=c,exports.validateEnv=function(e,r){void 0===r&&(r={});var t=r.requiredProperties;if(!e)throw new Error("Impossible to load environment variables validation schema.");var o={type:"object",properties:i({},e),required:t},n=a.compile(o);if(!n(process.env))throw new Error(a.errorsText(n.errors,{dataVar:"process.env"}))}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r,o,t=e(require("ajv")),n=e(require("ajv-formats"));function s(){return(s=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var o=arguments[r];for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&(e[t]=o[t])}return e}).apply(this,arguments)}var i,a=new t({coerceTypes:!0,useDefaults:!0});n(a),function(e){e.PRODUCTION="production",e.DEVELOPMENT="development",e.TEST="test"}(i||(i={}));var p=null==(r="production".toString())||null==(o=r.toLowerCase())?void 0:o.trim(),v=p===i.PRODUCTION,c=p===i.DEVELOPMENT,u=p===i.TEST,l=p!==i.DEVELOPMENT&&p!==i.TEST;exports.currentEnv=p,exports.isDeployedEnv=l,exports.isDevelopmentEnv=c,exports.isProductionEnv=v,exports.isTestEnv=u,exports.validateEnv=function(e,r){void 0===r&&(r={coerceVars:!0});var o=r.requiredProperties,t=r.coerceVars;if(!e)throw new Error("Impossible to load environment variables validation schema.");var n={type:"object",properties:s({},e),required:o},i=a.compile(n),p=s({},process.env);if(!i(p))throw new Error(a.errorsText(i.errors,{dataVar:"process.env"}));(void 0===t||t)&&(process.env=p)}; | ||
//# sourceMappingURL=env-vars-validator.cjs.production.min.js.map |
@@ -24,3 +24,4 @@ import Ajv from 'ajv'; | ||
var ajv = /*#__PURE__*/new Ajv({ | ||
coerceTypes: true | ||
coerceTypes: true, | ||
useDefaults: true | ||
}); | ||
@@ -30,7 +31,10 @@ addFormats(ajv); | ||
if (options === void 0) { | ||
options = {}; | ||
options = { | ||
coerceVars: true | ||
}; | ||
} | ||
var _options = options, | ||
requiredProperties = _options.requiredProperties; | ||
requiredProperties = _options.requiredProperties, | ||
coerceVars = _options.coerceVars; | ||
@@ -48,3 +52,5 @@ if (!validationSchema) { | ||
if (!validate(process.env)) { | ||
var data = _extends({}, process.env); | ||
if (!validate(data)) { | ||
throw new Error(ajv.errorsText(validate.errors, { | ||
@@ -54,2 +60,6 @@ dataVar: 'process.env' | ||
} | ||
if (typeof coerceVars === 'undefined' ? true : coerceVars) { | ||
process.env = data; | ||
} | ||
}; | ||
@@ -56,0 +66,0 @@ var Environment; |
export declare const validateEnv: (validationSchema: object, options?: { | ||
requiredProperties?: string[]; | ||
coerceVars?: boolean; | ||
}) => void; | ||
@@ -4,0 +5,0 @@ export declare const currentEnv: string; |
{ | ||
"version": "1.0.3", | ||
"version": "1.1.2", | ||
"license": "MIT", | ||
@@ -51,6 +51,6 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "7.0.5", | ||
"@typescript-eslint/eslint-plugin": "5.10.1", | ||
"@typescript-eslint/parser": "5.10.1", | ||
"eslint": "8.7.0", | ||
"@size-limit/preset-small-lib": "7.0.8", | ||
"@typescript-eslint/eslint-plugin": "5.10.2", | ||
"@typescript-eslint/parser": "5.10.2", | ||
"eslint": "8.8.0", | ||
"eslint-config-prettier": "8.3.0", | ||
@@ -63,3 +63,4 @@ "eslint-plugin-import": "2.25.4", | ||
"prettier": "2.5.1", | ||
"size-limit": "7.0.5", | ||
"size-limit": "7.0.8", | ||
"standard-version": "9.3.2", | ||
"tsdx": "0.14.1", | ||
@@ -70,3 +71,3 @@ "tslib": "2.3.1", | ||
"dependencies": { | ||
"ajv": "^8.8.2", | ||
"ajv": "^8.9.0", | ||
"ajv-formats": "^2.1.1" | ||
@@ -73,0 +74,0 @@ }, |
@@ -35,2 +35,3 @@ [![Maintainability](https://api.codeclimate.com/v1/badges/9d8e089c9e3e1115302f/maintainability)](https://codeclimate.com/github/qlaffont/env-vars-validator/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/9d8e089c9e3e1115302f/test_coverage)](https://codeclimate.com/github/qlaffont/env-vars-validator/test_coverage) ![npm](https://img.shields.io/npm/v/env-vars-validator) ![npm](https://img.shields.io/npm/dm/env-vars-validator) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/env-vars-validator) ![NPM](https://img.shields.io/npm/l/env-vars-validator) | ||
| requiredProperties | string[] | [] | Indicate if field is required (*More Information :* [JSON Schema Required](https://ajv.js.org/json-schema.html#required)) | | ||
| coercevars | boolean | true | Indicate if fields will be cast to type (*Example:* NODE_ENV will be cast to number in our usage example) | | ||
@@ -37,0 +38,0 @@ ### currentEnv |
@@ -6,2 +6,3 @@ import Ajv from 'ajv'; | ||
coerceTypes: true, | ||
useDefaults: true, | ||
}); | ||
@@ -14,5 +15,6 @@ addFormats(ajv); | ||
requiredProperties?: string[]; | ||
coerceVars?: boolean; | ||
}, | ||
) => void = (validationSchema, options = {}) => { | ||
const { requiredProperties } = options; | ||
) => void = (validationSchema, options = { coerceVars: true }) => { | ||
const { requiredProperties, coerceVars } = options; | ||
@@ -35,3 +37,5 @@ if (!validationSchema) { | ||
if (!validate(process.env)) { | ||
const data = { ...process.env }; | ||
if (!validate(data)) { | ||
throw new Error( | ||
@@ -41,2 +45,6 @@ ajv.errorsText(validate.errors, { dataVar: 'process.env' }), | ||
} | ||
if (typeof coerceVars === 'undefined' ? true : coerceVars) { | ||
process.env = data; | ||
} | ||
}; | ||
@@ -43,0 +51,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
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
23316
212
72
16
11
Updatedajv@^8.9.0