1.3.2 • Published 6 years ago

reason-nconf v1.3.2

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

NPM Build Status Coverage Status

reason-nconf

ReasonML bindings to the nconf library.

This is a very rough implementation that will enable very simple use cases.

Usage

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

let appConfig =
  Nconf.(
    make()
    |> jsFilePathNamed("example", {j|/path/to/file.js|j})
    |> get()
  );

Set a value

String Literal

let appConfig =
  Nconf.(
    make()
    |> setLiteral("some:key:path", `Str("foo"))
    |> get()
  )

Integer Literal

let appConfig =
  Nconf.(
    make()
    |> setLiteral("some:key:path", `Int(42))
    |> get()
  )

Object Literal

let appConfig =
  Nconf.(
    make()
    |> setObject("some:key:path", { "foo": "bar" })
    |> get()
  )

Get a value

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:

yarn install --save reason-nconf

Then add reason-nconf to your bs-dependencies in bsconfig.json:

{
  "bs-dependencies": [
    "reason-nconf"
  ]
}

How do I use it?

See the Usage section above...

What's missing?

Mostly everything...

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.5.0

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago