Comparing version 1.2.3 to 1.2.4
{ | ||
"name": "classenv", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "Describe your environment variables contract with TypeScript class", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,3 +11,8 @@ # classenv | ||
- Makes decorated properties read-only in runtime | ||
- Supports both static and instance properties | ||
## Description | ||
Let's pretend we have very simple | ||
**.env** | ||
@@ -18,9 +23,15 @@ ``` | ||
How can we describe it using **classenv** | ||
**environment.ts** | ||
```typescript | ||
import { Env } from 'classenv'; | ||
class Environment { | ||
@Env() // Auto UPPER_SNAKE_CASE conversion supported | ||
static isSomethingEnabled: number; | ||
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 | ||
@@ -38,11 +49,21 @@ static withDefault: string = 'yeah its me' | ||
} | ||
``` | ||
`@Env` property data type should be scalar (string, number or boolean). | ||
**main.ts** | ||
```typescript | ||
import {Environment} from './environment.ts' | ||
console.log(typeof Environment.isEnabledStr, Environment.isEnabledStr) | ||
// string 1 | ||
console.log(typeof Environment.isEnabledStr, Environment.isEnabledStr) | ||
console.log(typeof Environment.isEnabledNmbr, Environment.isEnabledNmbr) | ||
// number 1 | ||
console.log(typeof Environment.isEnabledNmbr, Environment.isEnabledNmbr) | ||
console.log(typeof Environment.isEnabledBln, Environment.isEnabledBln) | ||
// boolean true | ||
console.log(typeof Environment.isEnabledBln, Environment.isEnabledBln) | ||
console.log(typeof Environment.isSomethingEnabled, Environment.isSomethingEnabled) | ||
// number 1 | ||
console.log(typeof Environment.isSomethingEnabled, Environment.isSomethingEnabled) | ||
@@ -52,6 +73,10 @@ Environment.isEnabledBln = false; | ||
// Let's check instance properties | ||
const env = new Environment(); | ||
console.log(env.isSomethingEnabled) // 1 | ||
``` | ||
`@Env` property data type should be scalar (string, number or boolean). | ||
## Dependencies | ||
@@ -58,0 +83,0 @@ |
6101
99