Skip to content

Commit

Permalink
(chore) update example links and add files to customize section (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
disizali authored Jul 8, 2020
1 parent 5f25e61 commit aa9d1d4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,11 @@ coffee.set("requests.limit" , 100);
coffee.has("requests.limit"); // true
```

## Customize Coffee Load
coffee can read the configurations from the desired directory.
```
- coffee.ts
- custom
- default.json
```
```ts
// coffee.ts
import coffee from "https://deno.land/x/coffee/mod.ts";
coffee.load({
configDir: "./custom", // specify the custom config directory
customEnvVarFileName: "cev", // specify the desired custom environment variable config file name
env: "production" // force relative environment variables to loads from this env
},);
const dbName: string = coffee.get("database.name").string();
```

## Custom Environment Variables
If you want to use environment variables, just create a file called `custom-environment-variable` and give it values that you want to read from environment variables.
```json
ENV_NAME=coffee

- coffee.ts
- config
- custom-environment-variables.json
Expand All @@ -82,7 +66,7 @@ If you want to use environment variables, just create a file called `custom-envi
```ts
// coffee.ts
import coffee from "https://deno.land/x/coffee/mod.ts";
const name: string = coffee.get("database.name").string();
const name: string = coffee.get("database.name").string(); // coffee, reads from ENV_NAME environment variable
```

## Related Environment Variables
Expand All @@ -105,6 +89,26 @@ import coffee from "https://deno.land/x/coffee/mod.ts";
const name: string = coffee.get("something").string();
```

## Customize Coffee Load
coffee can read the configurations from the desired directory.
```
- coffee.ts
- custom
- default.json
- cev.json
- production.json
```
```ts
// coffee.ts
import coffee from "https://deno.land/x/coffee/mod.ts";
coffee.load({
configDir: "./custom", // specify the custom config directory
customEnvVarFileName: "cev", // specify the desired custom environment variable config file name
env: "production" // force relative environment variables to loads from this env
},);
const dbName: string = coffee.get("database.name").string();
```

## Error Handling
coffee tries to make a specific Error for each situation.
```ts
Expand Down
2 changes: 1 addition & 1 deletion examples/coffee.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import coffee from "../mod.ts";
import coffee from "https://deno.land/x/coffee/mod.ts";

// if coffee.load() is not called, coffee automatically loads the configs from the './config' folder

Expand Down
2 changes: 1 addition & 1 deletion examples/errorHandling.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import coffee, { errors } from "../mod.ts";
import coffee, { errors } from "https://deno.land/x/coffee/mod.ts";

// No Config Dir :

Expand Down

0 comments on commit aa9d1d4

Please sign in to comment.