ts-env-support
Version:
Typescript support for .env files
101 lines (70 loc) • 1.7 kB
Markdown
# ts-env
typescript support for .env files
# Usage
*.env file*
```
withoutQuotes=without quotes
DOUBLE_QUOTED_STRING="double quotes"
single_quoted_string='single quotes'
plain_bool=true
stringifiedBool=false
plain_number=9
stringifiedNumber=18
URL=https://www.google.com
```
```
Works only on static properties
Any non-static members in the env file are not allowed
It is recommended to set `strict: true`,
with which the actual purpose of the library is achieved
Any non-static members, declared in the class,
are not set into the Custom Env class that is decorated
with `Env`
```
*app.ts*
```
import { Env, Value } from 'ts-env';
class TestEnv {
static withoutQuotes: string;
static doubelQuotedString: string;
static singleQuotedString: string;
static plainBool: boolean;
static stringifiedBool: boolean;
static plainNumber: number;
static stringifiedNumber: number;
static validatedUrl: string;
}
console.log(TestEnv.withoutQuotes);
console.log(TestEnv.doubelQuotedString);
console.log(TestEnv.singleQuotedString);
console.log(TestEnv.plainBool);
console.log(TestEnv.stringifiedBool);
console.log(TestEnv.plainNumber);
console.log(TestEnv.stringifiedNumber);
console.log(TestEnv.validatedUrl);
```