All Projects → anler → bs-getenv

anler / bs-getenv

Licence: MIT License
ReasonML/BuckleScript PPX for embedding env variables

Programming Languages

shell
77523 projects
reason
219 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to bs-getenv

awesome-ppx-reasonml
curated list of reasonml PPX rewriter
Stars: ✭ 28 (+12%)
Mutual labels:  ppx, reasonml, ppx-rewriter
jsoo-react
js_of_ocaml bindings for ReactJS. Based on ReasonReact.
Stars: ✭ 126 (+404%)
Mutual labels:  ppx, reasonml
ppx string interpolation
PPX rewriter that enables string interpolation in OCaml
Stars: ✭ 34 (+36%)
Mutual labels:  ppx, ppx-rewriter
react-rules-of-hooks-ppx
This ppx validates the rules of React hooks.
Stars: ✭ 40 (+60%)
Mutual labels:  ppx, reasonml
hello-ppx-esy
A simple example of a ppx with Reason and esy
Stars: ✭ 38 (+52%)
Mutual labels:  ppx, reasonml
astro-design
Astro Design Components
Stars: ✭ 20 (-20%)
Mutual labels:  reasonml
flagga
An extensible Go library for handling program configuration using flags.
Stars: ✭ 28 (+12%)
Mutual labels:  environment-variables
cypress-dotenv
Cypress plugin that enables compatability with dotenv
Stars: ✭ 47 (+88%)
Mutual labels:  environment-variables
graphql-reason-server-example
An example project to write a GraphQL server using Reason
Stars: ✭ 19 (-24%)
Mutual labels:  reasonml
env
A lightweight package for loading OS environment variables into structs for Go projects
Stars: ✭ 24 (-4%)
Mutual labels:  environment-variables
aws-export-profile
Export AWS profiles to your shell environment
Stars: ✭ 45 (+80%)
Mutual labels:  environment-variables
ts-dotenv
Strongly-typed environment variables for Node.js
Stars: ✭ 18 (-28%)
Mutual labels:  environment-variables
bs-graphql-bindings
BuckleScript binding for graphql-js
Stars: ✭ 50 (+100%)
Mutual labels:  reasonml
sicher
Sicher is a go module that allows secure storage of encrypted credentials in a version control system.
Stars: ✭ 27 (+8%)
Mutual labels:  environment-variables
bs-most
Reason/BuckleScript bindings for the Most.js reactive toolkit
Stars: ✭ 41 (+64%)
Mutual labels:  reasonml
reason-nodejs
Node bindings for Reason and Bucklescript
Stars: ✭ 105 (+320%)
Mutual labels:  reasonml
ruby-to-michelson
(Secure) Ruby to Liquidity w/ ReasonML Syntax / Michelson (Source-to-Source) Cross-Compiler Cheat Sheet / White Paper
Stars: ✭ 16 (-36%)
Mutual labels:  reasonml
relude-random
Composable random generators based on the PCG paper
Stars: ✭ 15 (-40%)
Mutual labels:  reasonml
gconfigs
gConfigs - Config and Secret parser
Stars: ✭ 42 (+68%)
Mutual labels:  environment-variables
babyenv
Go environment var parsing, for babies
Stars: ✭ 30 (+20%)
Mutual labels:  environment-variables

bs-getenv

bs-getenv pipeline npm version

PPX for ReasonML / BuckleScript for embedding environment variables in the code.

bs-getenv

Installation

Get the package:

# yarn
yarn add bs-getenv
# or npm
npm install --save bs-getenv

Then add it to bsconfig.json:

"ppx-flags": ["bs-getenv/ppx"]

Usage

%getenv ...

With a default value

Usage: [%getenv VAR_NAME; defaultValue], where:

  • The result type will be string
  • defaultValue can be any expression of type string

Without a default value

Usage: [%getenv VAR_NAME], where:

  • The result type will be option(string).

%getenv.exn ...

Usage: [%getenv.exn VAR_NAME], where:

  • The result type will be string
  • Useful in those cases where the application absolutely needs an env variable to exist (e.g.: app secrets)
  • If VAR_NAME env var does not exist, it will fail at compile time with the message: %getenv environment variable not found: VAR_NAME

switch%getenv ...

With a default value (exhaustive pattern matching)

Usage:

switch%getenv (VAR_NAME) {
| "<some value>" => ...
| _ => ...default
}

where:

  • The result type will be the type of the cases

Without a default value (non-exhaustive pattern matching)

Usage:

switch%getenv (VAR_NAME) {
| "<some value>" => ...
}

where:

  • The result type will be option(t) where t is the type of the cases

Example

let getDefaultValue = () => "Some other value";

let var1: string = [%getenv SOME_VAR_THAT_DOESNT_EXIST; getDefaultValue()];

let var2: string = [%getenv USER; "default value"];

let var3: option(string) = [%getenv HOME];

let var4: option(string) = [%getenv SOME_VAR_THAT_DOESNT_EXIST];

let var5: bool =
  switch%getenv (USER) {
  | "anler" => true
  | _ => false
  };

let var6: option(bool) =
  switch%getenv (USER) {
  | "anler" => true
  };

Developing

Clone repo and install deps:

esy install
yarn install

Build ppx:

esy build

To explore generated output, run yarn build and look the compiled file test/Test.bs.js.

TODO

  • Just get env variables
  • Support switch cases
  • Better error reporting
  • Support switch guards and variables
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].