Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

classenv

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classenv

Describe your environment variables contract with TypeScript class

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
90
increased by38.46%
Maintainers
1
Weekly downloads
 
Created
Source

A perfect typescript environment variables library.

  • Type-casting using TypeScript metadata reflection
  • Auto UPPER_SNAKE_CASE conversion
  • 0 dependencies
  • Throws runtime error if variable doesn't exist
  • Makes decorated properties read-only in runtime

Built-in support for type-casting.

.env

IS_SOMETHING_ENABLED=1
import { Env } from 'classenv';

class Environment {
  @Env('IS_SOMETHING_ENABLED')
  static isEnabledStr: string;

  @Env('IS_SOMETHING_ENABLED')
  static isEnabledNmbr: number;

  @Env('IS_SOMETHING_ENABLED')
  static isEnabledBln: boolean;

  @Env() // Auto UPPER_SNAKE_CASE conversion supported
  static isSomethingEnabled: number
}

 // string 1
console.log(typeof Environment.isEnabledStr, Environment.isEnabledStr)
 // number 1
console.log(typeof Environment.isEnabledNmbr, Environment.isEnabledNmbr)
 // boolean true
console.log(typeof Environment.isEnabledBln, Environment.isEnabledBln)
 // number 1
console.log(typeof Environment.isSomethingEnabled, Environment.isSomethingEnabled)

Environment.isEnabledBln = false;
// TypeError: Cannot assign to read only property 'isEnabledBln' of function 'class Test{}'

@Env property data type should be scalar (string, number or boolean).

FAQs

Package last updated on 27 Mar 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc