File tree 5 files changed +34
-19
lines changed
5 files changed +34
-19
lines changed Original file line number Diff line number Diff line change
1
+ .vscode /
Original file line number Diff line number Diff line change 3
3
manage environment variables with deno.
4
4
5
5
## Usage
6
+
6
7
specify the path of the ` .env ` file and import dino_env.
7
8
8
- install dino_env with [ Trex ] ( https://deno.land/x/trex ) using:
9
+ install dino_env with [ trex ] ( https://deno.land/x/trex ) using:
9
10
10
- ``` sh
11
+ ``` sh
11
12
$ trex install --map dinoenv
12
13
```
13
14
14
- ``` javascript
15
+ ``` javascript
15
16
import * as env from " dinoenv" ;
16
17
17
18
env .config ();
18
19
```
19
20
20
21
or directly with the url.
21
22
22
- ``` javascript
23
-
23
+ ``` javascript
24
24
import * as env from " https://deno.land/x/dinoenv/mod.ts" ;
25
25
26
26
env .config ();
27
-
28
27
```
29
28
30
29
## Config
31
30
32
31
you can specify the path of the .env file.
33
32
34
-
35
- ``` javascript
33
+ ``` javascript
36
34
import * as env from " https://deno.land/x/dinoenv/mod.ts" ;
37
35
38
36
env .config ({ path: " ./environment/.env" });
39
-
40
37
```
41
- > ** note** : by default use root project path
42
38
39
+ > ** note** : by default use root project path
43
40
44
41
change the decode of the ` .env ` file
45
42
46
- ``` javascript
43
+ ``` javascript
47
44
import * as env from " https://deno.land/x/dinoenv/mod.ts" ;
48
45
49
46
env .config ({ path: " ./environment/.env" , encoding: " utf-8" });
50
-
51
47
```
48
+
52
49
> ** note** : by default use "utf-8"
53
50
54
51
## permissions
55
52
56
- ``` sh
53
+ ``` sh
57
54
--allow-read --allow-env
58
55
```
Original file line number Diff line number Diff line change
1
+ {
2
+ "meta" : {
3
+ "path" : {
4
+ "url" : " https://deno.land/std/path/mod.ts" ,
5
+ "hash" : " 7785d20e2d17f5b217f1f5120bc47adcde3854060e7be740bb8bd539c083020f"
6
+ }
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ export * from "https://deno.land/std/path/mod.ts" ;
Original file line number Diff line number Diff line change 1
1
/* base code from https://github.com/rubiin/deno-env */
2
2
3
+ import { join } from "./imports/path.ts" ;
4
+
3
5
export interface Config {
4
6
path ?: string ;
5
7
encoding ?: string ;
6
8
}
7
9
8
- export type objectGen = {
10
+ type objectGen = {
9
11
[ name : string ] : string ;
10
- }
12
+ } ;
11
13
12
- const defaultPath = Deno . cwd ( ) + "/ .env";
14
+ const defaultPath = join ( Deno . cwd ( ) , " .env") ;
13
15
14
16
const LINE_BREAK = / \r \n | \n | \r / ;
15
17
const DECLARATION = / ^ \s * ( \w + ) \s * \= \s * ( .* ) ? \s * $ / ;
@@ -30,12 +32,18 @@ function parse(source: string) {
30
32
} , { } as objectGen ) ;
31
33
}
32
34
33
- export function config ( { path = defaultPath , encoding = "utf-8" } : Config = { } ) {
35
+ /**
36
+ * load .env file
37
+ */
38
+ export function config ( {
39
+ path = defaultPath ,
40
+ encoding = "utf-8" ,
41
+ } : Config = { } ) {
34
42
const encoder = new TextDecoder ( encoding ) ;
35
- const env = Deno . readFileSync ( path ) ;
43
+ const env = Deno . readFileSync ( join ( Deno . cwd ( ) , path ) ) ;
36
44
const entrie = encoder . decode ( env ) ;
37
45
38
46
for ( const [ key , value ] of Object . entries ( parse ( entrie ) ) ) {
39
47
Deno . env . set ( key , value ) ;
40
48
}
41
- }
49
+ }
You can’t perform that action at this time.
0 commit comments