Skip to content

Commit

Permalink
Update Docs 📚
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-essam committed Aug 8, 2019
1 parent 7c0e2ad commit f0fdce2
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,52 @@ const config = envoose.getConfig(configSchema)

module.exports = config
```

## Docs

### envoose.getConfig(configSchema)

Validate and load configs object using configSchema

### ConfigSchema

A configSchema is an object that tells envoose which env vars to load and how to load them, in its most basic form, it's just a set of keys to load

```js
const configSchema = {
FIRST_KEY: {},
SECOND_KEY: {}
}
```

#### Options

##### required
A required key must be supplied through env vars. If the value is not available in `process.env`, `getConfig` will throw `ConfigValidationError`.

Note that `default` and `required` can't be combined.

##### default
A value to fallback to if the env var is not set.

##### env
By default the config is read from env var with the same name as the config name. If `env` is supplied, it will read from that env var instead.

##### type
Env vars are strings by default, however envoose allows you to cast them to different data types.

###### Supported Types
- `String` (default)
- `Number`
- `Date`
- `Boolean` ('true', 'yes', '1' evaluate to true, while 'false', 'no', '0' evaluate to false, `CastError` will be thrown otherwise)
- Custom types by supplying a mapping function (ex: array of numbers `s => s.split(',').map(Number)`)

##### enum
Built in validator that checks whether the value falls in one of the values in the list. Throws `ConfigValidationError` if not found in enum.

##### match
Built in validator that checks whether the value matches this regex or not. Throws `ConfigValidationError` if not matched.

##### validator
Accepts custom validation function that should return true if valid and false otherwise.

0 comments on commit f0fdce2

Please sign in to comment.