You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h4align="center">Don't worry about configuration anymore.</h4>
4
+
<h4align="center">Configuration made simple.</h4>
5
5
6
6
<palign="center">
7
7
<ahref="https://www.npmjs.com/package/fauda">
@@ -26,14 +26,14 @@
26
26
27
27
Fauda does two things for you:
28
28
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.
30
30
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.
31
31
32
32
## Features
33
33
34
34
-**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!)
37
37
-**Generate types** for your Typescript code and for Typescript configuration files.
38
38
-**Expand environment variables** in any configuration value.
39
39
@@ -91,9 +91,7 @@ Create a `schema.json` file:
91
91
}
92
92
```
93
93
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.
97
95
98
96
</details>
99
97
@@ -106,7 +104,7 @@ Generate a `src/configuration.ts` file:
106
104
$ npx fauda types
107
105
```
108
106
109
-
For more information, please take a look at [CLI](#cli).
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
+
120
122
</details>
121
123
122
124
<details>
@@ -141,28 +143,39 @@ async function loadConfiguration() {
141
143
142
144
## How does it work?
143
145
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`.
145
147
146
148
Option names are inflected according the source's typical naming convention:
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!
155
157
156
158
<details>
157
159
<summary>🙋🏻♂️ <i>What is environment variable expansion?</i></summary><br>
158
160
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.
160
162
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:
162
164
163
165
```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}"
166
179
}
167
180
```
168
181
@@ -172,11 +185,9 @@ Here's an example of an option referencing a environment variable:
172
185
173
186
### Configuration files
174
187
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.
178
189
179
-
Several configuration file names and formats are supported:
190
+
Here is a list of the configuration file names and formats that are supported:
180
191
181
192
| File | Format |
182
193
| ---------------------------------- | ------ |
@@ -193,11 +204,11 @@ Several configuration file names and formats are supported:
193
204
|`.config/${myPackage}.config.yaml`|`yaml`|
194
205
|`.config/\${myPackage}.config.yml`|`yaml`|
195
206
196
-
### Command-line arguments
207
+
### CLI options
197
208
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!
199
210
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.
201
212
202
213
<details>
203
214
<summary>🙋🏻♂️ <i>What about arrays?</i></summary><br>
0 commit comments