https://github.com/scull7/reason-nconf
ReasonML bindings to the nconf library.
https://github.com/scull7/reason-nconf
Last synced: over 1 year ago
JSON representation
ReasonML bindings to the nconf library.
- Host: GitHub
- URL: https://github.com/scull7/reason-nconf
- Owner: scull7
- License: mit
- Created: 2018-01-18T22:25:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-27T23:29:20.000Z (almost 8 years ago)
- Last Synced: 2024-12-28T02:03:28.399Z (over 1 year ago)
- Language: OCaml
- Size: 107 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://nodei.co/npm/reason-nconf/)
[](https://www.travis-ci.org/scull7/reason-nconf)
[](https://coveralls.io/github/scull7/reason-nconf?branch=master)
# reason-nconf
ReasonML bindings to the [nconf][node-nconf] library.
This is a very rough implementation that will enable very simple use cases.
## Usage
```reason
type config = {
..
"THING1": string,
"THING2": int
};
let baseDir = "/path/to/somewhere"
let appConfig: config =
Nconf.(
make()
|> argv()
|> env()
|> filePathNamed("locals", {j|$baseDir/config/locals.json|j})
|> filePathNamed("defaults", {j|$baseDir/config/defaults.json|j})
|> get()
);
```
### Load a JavaScript file
This is accomplished from an internal module written in ReasonML. The internal
module is a near 1-to-1 copy of [nconf-js]
```reason
let appConfig =
Nconf.(
make()
|> jsFilePathNamed("example", {j|/path/to/file.js|j})
|> get()
);
```
### Set a value
#### String Literal
```reason
let appConfig =
Nconf.(
make()
|> setLiteral("some:key:path", `Str("foo"))
|> get()
)
```
#### Integer Literal
```reason
let appConfig =
Nconf.(
make()
|> setLiteral("some:key:path", `Int(42))
|> get()
)
```
#### Object Literal
```reason
let appConfig =
Nconf.(
make()
|> setObject("some:key:path", { "foo": "bar" })
|> get()
)
```
### Get a value
```reason
let appConfig =
Nconf.(
make()
|> jsFilePathNamed("example", {j|./__tests__/assets/data.js|j})
)
let username =
switch(Nconf.getKey(appConfig, "obj:auth:username") |> Js.Nullable.to_opt) {
| None => Js.Exn.raiseError("Could not retrieve username")
| Some(x) => x
};
```
## How do I install it?
Inside of a BuckleScript project:
```shell
yarn install --save reason-nconf
```
Then add `reason-nconf` to your `bs-dependencies` in `bsconfig.json`:
```json
{
"bs-dependencies": [
"reason-nconf"
]
}
```
## How do I use it?
See the [Usage](#usage) section above...
## What's missing?
Mostly everything...
[node-nconf]: https://www.npmjs.com/package/nconf
[nconf-js]: https://github.com/yoneal/nconf-js