Skip to content

Commit cdb8e99

Browse files
committed
docs: various small tweaks
1 parent 2d52149 commit cdb8e99

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

README.md

+39-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h1 align="center">
22
<img src="https://raw.githubusercontent.com/ngryman/artworks/master/fauda/heading/[email protected]" alt="Fauda" with="600">
33
</h1>
4-
<h4 align="center">Don't worry about configuration anymore.</h4>
4+
<h4 align="center">Configuration made simple.</h4>
55

66
<p align="center">
77
<a href="https://www.npmjs.com/package/fauda">
@@ -26,14 +26,14 @@
2626

2727
Fauda does two things for you:
2828

29-
1. It **loads** your configuration from files, command-line options, and environment variables; giving flexibility to adapt to your users' workflow.
29+
1. It **loads** your configuration from files, CLI options, and environment variables; giving flexibility to adapt to your users' workflow.
3030
2. It **validates** your configuration using a JSON schema, applying defaults when available; abstracting the hard things for you providing auto-completion to your users.
3131

3232
## Features
3333

3434
- **One dependency** to load and validate your configuration.
35-
- **Load from multiple sources** such as JSON, YAML, JavaScript, Typescript, command-line arguments, and environment variables.
36-
- **Validate your configuration** with a JSON schema. BONUS: Your configuration files have auto-completion in VSCode!
35+
- **Load from multiple sources** such as JSON / YAML / JS / TS files, CLI options, and environment variables.
36+
- **Validate your configuration** with a JSON schema (bonus: auto-completion in VSCode!)
3737
- **Generate types** for your Typescript code and for Typescript configuration files.
3838
- **Expand environment variables** in any configuration value.
3939

@@ -91,9 +91,7 @@ Create a `schema.json` file:
9191
}
9292
```
9393

94-
Fauda relies on a [JSON schema](https://json-schema.org/) to load and validate your configuration, but also to generate types.
95-
96-
For more information on how to creat this schema, please take a look at the [Getting Started](https://json-schema.org/learn/getting-started-step-by-step.html) guide.
94+
Fauda uses a [JSON schema](https://json-schema.org/) to load and normalize your configuration. For more information on JSON schemas, you can take a look at their [Getting Started](https://json-schema.org/learn/getting-started-step-by-step.html) guide.
9795

9896
</details>
9997

@@ -106,7 +104,7 @@ Generate a `src/configuration.ts` file:
106104
$ npx fauda types
107105
```
108106

109-
For more information, please take a look at [CLI](#cli).
107+
This will generate the following file:
110108

111109
```ts
112110
export interface Configuration {
@@ -117,6 +115,10 @@ export interface Configuration {
117115
}
118116
```
119117

118+
Types will allow you manipulate a strongly typed configuration object in your code. As a bonus it also enables autocompletion for TS configuration files!
119+
120+
For more information about generating types, please take a look at the [CLI](#cli) section.
121+
120122
</details>
121123

122124
<details>
@@ -141,28 +143,39 @@ async function loadConfiguration() {
141143

142144
## How does it work?
143145

144-
Fauda loads your configuration from several sources using the following order of precedence: `environment variables > command-line arguments > configuration files`.
146+
Fauda loads your configuration from several sources using the following order of precedence: `environment variables > CLI options > configuration files`.
145147

146148
Option names are inflected according the source's typical naming convention:
147149

148-
| Source | Casing | Example |
149-
| --------------------- | ------------- | --------------------- |
150-
| Configuration file | `camel` | `publicPages` |
151-
| Command-line argument | `kebab` | `--public-pages` |
152-
| Environment variable | `upper+snake` | `MY_APP_PUBLIC_PAGES` |
150+
| Source | Casing | Example |
151+
| -------------------- | ------------- | --------------------- |
152+
| Configuration file | `camel` | `publicPages` |
153+
| CLI options | `kebab` | `--public-pages` |
154+
| Environment variable | `upper+snake` | `MY_APP_PUBLIC_PAGES` |
153155

154-
Once your configuration loaded, it is normalized into a valid configuration object that your library / application can use safely. The normalization process validates your configuration using the provided JSON schema. It checks that the type of options are valid, required options are specified, sets default values, and also expand environment variables that are referenced!
156+
Once your configuration is loaded, Fauda normalizes it into a valid configuration object that your library / application can use. The normalization process validates your configuration using the provided JSON schema. It checks that the type of options are valid, required options are specified, sets default values, and also expand environment variables references!
155157

156158
<details>
157159
<summary>🙋🏻‍♂️ <i>What is environment variable expansion?</i></summary><br>
158160

159-
You can reference an environment variable's name as your option's value. Fauda will replace it by the variable's value when loading the configuration.
161+
You can reference an environment variable name's as your option's value. Fauda will replace its value at runtime, giving you the opportunity to depend on any environment variable in your configuration.
160162

161-
Here's an example of an option referencing a environment variable:
163+
For instance, if you have a `mode` option that varies depending on the `NODE_ENV`'s value, you can do it like this:
162164

163165
```json
164-
{
165-
"mode": "${NODE_ENV}"
166+
"mode": {
167+
"default": "${NODE_ENV}"
168+
}
169+
```
170+
171+
Note that you can also reference environment variables in your JSON schema using the `default` value:
172+
173+
```json
174+
"mode": {
175+
"description": "Mode of the app.",
176+
"type": "string",
177+
"enum": ["development", "production"],
178+
"default": "${NODE_ENV}"
166179
}
167180
```
168181

@@ -172,11 +185,9 @@ Here's an example of an option referencing a environment variable:
172185

173186
### Configuration files
174187

175-
Fauda first tries to find a `config.${myApp}` property in the `package.json` of your users.
176-
177-
It then searches for a configuration file starting from the current directory up to the root.
188+
Fauda first searches for a `config.${myApp}` property in the `package.json` file of your users. If not found, it then searches for a various configuration files, starting from the current directory up to the root.
178189

179-
Several configuration file names and formats are supported:
190+
Here is a list of the configuration file names and formats that are supported:
180191

181192
| File | Format |
182193
| ---------------------------------- | ------ |
@@ -193,11 +204,11 @@ Several configuration file names and formats are supported:
193204
| `.config/${myPackage}.config.yaml` | `yaml` |
194205
| `.config/\${myPackage}.config.yml` | `yaml` |
195206

196-
### Command-line arguments
207+
### CLI options
197208

198-
Fauda parses command-line arguments as you can expect from any other argument parsers!
209+
Fauda parses CLI options as you can expect from any other argument parsers!
199210

200-
Options are "kebab-"cased. For instance, the `publicPages` option is transposed as the `--public-pages` command-line argument.
211+
Options are "kebab-"cased. For instance, the `publicPages` option is transposed as the `--public-pages` CLI argument.
201212

202213
<details>
203214
<summary>🙋🏻‍♂️ <i>What about arrays?</i></summary><br>
@@ -259,9 +270,9 @@ const configuration = await fauda('my-app', 'schema.json')
259270

260271
| Option | Type | Default | Description |
261272
| ------ | ------------------- | --------------- | ------------------------------------------------------------------------------ |
262-
| `args` | `string[]` | `process.argv` | Array of command-line arguments, used by the command-line arguments loader. |
273+
| `args` | `string[]` | `process.argv` | Array of CLI options, used by the CLI options loader. |
263274
| `env` | `NodeJS.ProcessEnv` | `process.env` | Dictionary of environment variables, used by the environment variables loader. |
264-
| `cwd` | `string` | `process.cwd()` | Array of command-line arguments, used by the configuration files loader. |
275+
| `cwd` | `string` | `process.cwd()` | Array of CLI options, used by the configuration files loader. |
265276

266277
### [generateTypes](src/generator.ts)
267278

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fauda",
33
"version": "0.1.0-0",
4-
"description": "Don't worry about configuration anymore.",
4+
"description": "Configuration made simple.",
55
"author": "Nicolas Gryman <[email protected]> (https://ngryman.sh)",
66
"license": "MIT",
77
"repository": "ngryman/fauda",

0 commit comments

Comments
 (0)