{"id":21480480,"url":"https://github.com/paperhive/envfefe","last_synced_at":"2025-07-15T12:32:08.954Z","repository":{"id":27096214,"uuid":"112120172","full_name":"paperhive/envfefe","owner":"paperhive","description":"Parses, sanitizes, and validates environment variables – despite the constant negative press envfefe","archived":false,"fork":false,"pushed_at":"2023-03-04T02:29:15.000Z","size":454,"stargazers_count":10,"open_issues_count":3,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-09T19:19:13.495Z","etag":null,"topics":["docker","environment-variables","javascript","nodejs","parse","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/paperhive.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}},"created_at":"2017-11-26T22:02:06.000Z","updated_at":"2021-04-17T15:15:49.000Z","dependencies_parsed_at":"2023-01-14T05:58:44.334Z","dependency_job_id":null,"html_url":"https://github.com/paperhive/envfefe","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paperhive%2Fenvfefe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paperhive%2Fenvfefe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paperhive%2Fenvfefe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paperhive%2Fenvfefe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paperhive","download_url":"https://codeload.github.com/paperhive/envfefe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226038783,"owners_count":17564046,"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":["docker","environment-variables","javascript","nodejs","parse","typescript"],"created_at":"2024-11-23T12:15:26.102Z","updated_at":"2024-11-23T12:15:27.861Z","avatar_url":"https://github.com/paperhive.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# envfefe\n\n[![npm version](https://badge.fury.io/js/envfefe.svg)](https://badge.fury.io/js/envfefe)\n[![Test](https://github.com/paperhive/envfefe/actions/workflows/test.yaml/badge.svg)](https://github.com/paperhive/envfefe/actions/workflows/test.yaml)\n[![codecov](https://codecov.io/gh/paperhive/envfefe/branch/main/graph/badge.svg?token=ASCyvDGYAx)](https://codecov.io/gh/paperhive/envfefe)\n\n\u003e This typescript/javascript package parses environment variables – despite the constant negative press envfefe\n\n![jai030md_19ijj80_q88qdg](https://user-images.githubusercontent.com/1874116/33260253-8be1a670-d35f-11e7-9337-988b4286ed84.png)\n\nDisclaimer: the author of this package opposes Trump and other racists and misogynists.\n\n`envfefe` makes extensive use of the [fefe](https://github.com/paperhive/fefe) module that provides type-safe and purely functional validation, sanitization and transformation.\n\n## Usage\n\nImagine you use the following environment variables, e.g., in a Docker `.env` file:\n\n```bash\nELASTIC_HOST=elasticsearch\nELASTIC_PORT=9200\nENABLE_CACHE=true\nLAUNCH_DATE=2017-12-08T10:00:00.000Z\nGCLOUD_CREDENTIALS={\"apiKey\": \"XYZ\"}\nWHITELIST=ada,john\n```\n\nThen you can use `envfefe` for parsing and sanitizing these into an object\nthat you can use in your application:\n\n```typescript\nimport { parseEnv } from 'envfefe'\nimport { parseBoolean, parseDate, parseJson, parseNumber, pipe, string, success } from 'fefe'\n\nconst config = parseEnv({\n  elasticHost: string(),\n  elasticPort: pipe(string()).pipe(parseNumber()),\n  enableCache: pipe(string()).pipe(parseBoolean()),\n  launchDate: pipe(string()).pipe(parseDate()),\n  gcloudCredentials: pipe(string()).pipe(parseJson()),\n  whitelist: pipe(string()).pipe(value =\u003e success(value.split(','))),\n})\n```\n\nIf validation passes (check via `isSuccess(config)`) then `config.right` will equal:\n```typescript\n{\n  elasticHost: 'elasticsearch',\n  elasticPort: 9000,\n  enableCache: true,\n  launchDate: Date('2017-12-08T10:00:00.000Z'),\n  gcloudCredentials: {apiKey: 'XYZ'},\n  whitelist: ['ada', 'john']\n}\n```\n\nThis module comes with full TypeScript support so if you are using\nTypeScript then `config.right` will have the correct types automatically:\n```typescript\n{\n  elasticHost: string\n  elasticPort: number\n  enableCache: boolean\n  launchDate: Date\n  gcloudCredentials: unknown\n  whitelist: string[]\n}\n```\n\nNote:\n * `camelCase` keys are automatically translated to\n   `SNAKE_CASE` environment variable names.\n * By default all variables are mandatory. See below for\n   optional variables and default values.\n * Values in the resulting object have proper types. If it can't be\n   sanitized because of a wrong type (like providing `foo` for a number)\n   then `isSuccess(config)` will be `false` and `config.left` contains\n   the `FefeError` (see [FefeError docs](https://github.com/paperhive/fefe#fefeerror)).\n\n## Advanced usage\n\n### Optional variables\n\n```javascript\nconst config = parse({\n  elasticHost: optional(string())\n});\n```\n\n### Default values\n\n```javascript\nconst config = parse({\n  elasticHost: defaultTo(string())\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaperhive%2Fenvfefe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaperhive%2Fenvfefe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaperhive%2Fenvfefe/lists"}