Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
A perfect typescript class environment variables library.
Let's pretend we have very simple
.env
IS_SOMETHING_ENABLED=1
How can we describe it using classenv
environment.ts
import { Env } from 'classenv';
export class Environment {
@Env() // Auto UPPER_SNAKE_CASE conversion
static isSomethingEnabled: number; // process.env.IS_SOMETHING_ENABLED
@Env() // Instance properties supported
isSomethingEnabled: number;
@Env() // Won't throw, because got default value
static withDefault: string = 'yeah its me'
@Env('IS_SOMETHING_ENABLED')
static isEnabledStr: string;
@Env('IS_SOMETHING_ENABLED')
static isEnabledNmbr: number;
@Env('IS_SOMETHING_ENABLED')
static isEnabledBln: boolean;
}
@Env
property data type should be scalar (string, number or boolean).
main.ts
import {Environment} from './environment.ts'
console.log(typeof Environment.isEnabledStr, Environment.isEnabledStr)
// string 1
console.log(typeof Environment.isEnabledNmbr, Environment.isEnabledNmbr)
// number 1
console.log(typeof Environment.isEnabledBln, Environment.isEnabledBln)
// boolean true
console.log(typeof Environment.isSomethingEnabled, Environment.isSomethingEnabled)
// number 1
Environment.isEnabledBln = false;
// TypeError: Cannot assign to read only property 'isEnabledBln' of function 'class Test{}'
// Let's check instance properties
const env = new Environment();
console.log(env.isSomethingEnabled) // 1
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.
import 'reflect-metadata';
These settings should be enabled
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
FAQs
Describe your environment variables contract with TypeScript class decorator
The npm package classenv receives a total of 33 weekly downloads. As such, classenv popularity was classified as not popular.
We found that classenv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.