{"id":19014445,"url":"https://github.com/anler/bs-getenv","last_synced_at":"2025-04-23T00:44:02.878Z","repository":{"id":142117573,"uuid":"263917898","full_name":"anler/bs-getenv","owner":"anler","description":"ReasonML/BuckleScript PPX for embedding env variables","archived":false,"fork":false,"pushed_at":"2024-12-04T21:26:06.000Z","size":900,"stargazers_count":25,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T00:43:57.100Z","etag":null,"topics":["environment-variables","ppx","ppx-rewriter","reasonml"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-14T13:08:04.000Z","updated_at":"2024-12-04T21:26:06.000Z","dependencies_parsed_at":"2025-04-17T07:18:59.122Z","dependency_job_id":null,"html_url":"https://github.com/anler/bs-getenv","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.125,"last_synced_commit":"a083e28fdd56120fe88565d35569f55e38095ff7"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anler%2Fbs-getenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anler%2Fbs-getenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anler%2Fbs-getenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anler%2Fbs-getenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anler","download_url":"https://codeload.github.com/anler/bs-getenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250348883,"owners_count":21415907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["environment-variables","ppx","ppx-rewriter","reasonml"],"created_at":"2024-11-08T19:29:31.411Z","updated_at":"2025-04-23T00:44:02.857Z","avatar_url":"https://github.com/anler.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bs-getenv\n\n![bs-getenv pipeline](https://github.com/anler/bs-getenv/workflows/bs-getenv%20pipeline/badge.svg) [![npm version](https://img.shields.io/npm/v/bs-getenv.svg)](https://www.npmjs.com/package/bs-getenv)\n\nPPX for [ReasonML](https://reasonml.github.io) / [BuckleScript](https://bucklescript.github.io) for embedding\nenvironment variables in the code.\n\n![bs-getenv](./.assets/example.png)\n\n## Installation\n\nGet the package:\n\n```shell\n# yarn\nyarn add bs-getenv\n# or npm\nnpm install --save bs-getenv\n```\n\nThen add it to `bsconfig.json`:\n\n```json\n\"ppx-flags\": [\"bs-getenv/ppx\"]\n```\n\n## Usage\n\n### `%getenv ...`\n\n#### With a default value\n\nUsage: `[%getenv VAR_NAME; defaultValue]`, where:\n\n- The result type will be `string`\n- `defaultValue` can be any expression of type `string`\n\n#### Without a default value\n\nUsage: `[%getenv VAR_NAME]`, where:\n\n- The result type will be `option(string)`.\n\n### `%getenv.exn ...`\n\nUsage: `[%getenv.exn VAR_NAME]`, where:\n\n- The result type will be `string`\n- Useful in those cases where the application absolutely needs an env variable to exist (e.g.: app secrets)\n- If `VAR_NAME` env var does not exist, it will fail **at compile time** with the message: `%getenv environment variable not found: VAR_NAME`\n\n### `switch%getenv ...`\n\n#### With a default value (exhaustive pattern matching)\n\nUsage:\n\n```reason\nswitch%getenv (VAR_NAME) {\n| \"\u003csome value\u003e\" =\u003e ...\n| _ =\u003e ...default\n}\n```\n\nwhere:\n\n- The result type will be the type of the cases\n\n#### Without a default value (non-exhaustive pattern matching)\n\nUsage:\n\n```reason\nswitch%getenv (VAR_NAME) {\n| \"\u003csome value\u003e\" =\u003e ...\n}\n```\n\nwhere:\n\n- The result type will be `option(t)` where `t` is the type of the cases\n\n## Example\n\n```reason\nlet getDefaultValue = () =\u003e \"Some other value\";\n\nlet var1: string = [%getenv SOME_VAR_THAT_DOESNT_EXIST; getDefaultValue()];\n\nlet var2: string = [%getenv USER; \"default value\"];\n\nlet var3: option(string) = [%getenv HOME];\n\nlet var4: option(string) = [%getenv SOME_VAR_THAT_DOESNT_EXIST];\n\nlet var5: bool =\n  switch%getenv (USER) {\n  | \"anler\" =\u003e true\n  | _ =\u003e false\n  };\n\nlet var6: option(bool) =\n  switch%getenv (USER) {\n  | \"anler\" =\u003e true\n  };\n```\n\n## Developing\n\nClone repo and install deps:\n\n```shell\nesy install\nyarn install\n```\n\nBuild ppx:\n\n```shell\nesy build\n```\n\nTo explore generated output, run `yarn build` and look the compiled file `test/Test.bs.js`.\n\n## TODO\n\n- [x] Just get env variables\n- [x] Support switch cases\n- [x] Better error reporting\n- [ ] Support switch guards and variables\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanler%2Fbs-getenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanler%2Fbs-getenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanler%2Fbs-getenv/lists"}