Comparing version 1.2.0 to 1.2.1
@@ -1,1 +0,1 @@ | ||
export declare function Env(name: string): any; | ||
export declare function Env(inputName?: string): any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function Env(name) { | ||
function Env(inputName) { | ||
return (target, key) => { | ||
const name = inputName !== null && inputName !== void 0 ? inputName : key | ||
.split(/(?=[A-Z])/) | ||
.join('_') | ||
.toUpperCase(); | ||
let value = process.env[name]; | ||
if (typeof value === 'undefined') { | ||
if (typeof target[key] === 'undefined') { | ||
throw new Error(`Environment variable ${name} is undefined`); | ||
} | ||
else { | ||
value = target[key]; | ||
} | ||
} | ||
const designType = Reflect.getMetadata('design:type', target, key); | ||
if ([String, Number, Boolean].includes(designType)) { | ||
if (typeof process.env[name] === 'undefined') { | ||
throw new Error(`Environment variable ${name} is undefined`); | ||
} | ||
Object.defineProperty(target, key, { | ||
value: designType(process.env[name]), | ||
value: designType(value), | ||
writable: false, | ||
@@ -13,0 +23,0 @@ enumerable: true, |
@@ -0,1 +1,7 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./env")); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "classenv", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Describe your environment variables contract with TypeScript class", | ||
@@ -10,3 +10,6 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "tsc", | ||
"test": "npx jest", | ||
"prebuild": "rm -rf ./dist", | ||
"prepublish": "npm run build" | ||
}, | ||
@@ -23,6 +26,8 @@ "author": "bowzee", | ||
"prettier": "^2.0.2", | ||
"reflect-metadata": "^0.1.13", | ||
"ts-jest": "^25.2.1", | ||
"typescript": "^3.8.3" | ||
}, | ||
"peerDependencies": { | ||
"reflect-metadata": "^0.1.13" | ||
}, | ||
"keywords": [ | ||
@@ -29,0 +34,0 @@ "dotenv", |
@@ -8,3 +8,2 @@ # classenv | ||
- Auto UPPER_SNAKE_CASE conversion | ||
- 0 dependencies | ||
- Throws runtime error if variable doesn't exist | ||
@@ -56,1 +55,24 @@ - Default values support | ||
`@Env` property data type should be scalar (string, number or boolean). | ||
## Dependencies | ||
###reflect-metadata | ||
``` | ||
npm i reflect-metadata | ||
``` | ||
And then import it somewhere close to your entry point (`index.ts`/`main.ts`/etc...). | ||
Should be imported before any of your environment classes. | ||
```typescript | ||
import 'reflect-metadata'; | ||
``` | ||
###tsconfig.json | ||
These settings should be enabled | ||
``` | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
``` |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5
1
76
0
5297
1
8
40