{"id":15408968,"url":"https://github.com/rojvv/envalid","last_synced_at":"2025-12-11T21:07:04.579Z","repository":{"id":62422321,"uuid":"451171425","full_name":"rojvv/envalid","owner":"rojvv","description":" Environment variable validation for Deno.","archived":false,"fork":false,"pushed_at":"2024-02-24T06:40:44.000Z","size":49,"stargazers_count":13,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-13T11:55:24.270Z","etag":null,"topics":["deno","dotenv","env"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rojvv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2022-01-23T17:01:16.000Z","updated_at":"2022-09-06T01:42:02.000Z","dependencies_parsed_at":"2024-07-07T10:25:37.178Z","dependency_job_id":"38a89387-84cd-4c92-ab13-5b5222b77767","html_url":"https://github.com/rojvv/envalid","commit_stats":null,"previous_names":["rojvv/envalid","roj1512/envalid"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/rojvv/envalid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rojvv%2Fenvalid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rojvv%2Fenvalid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rojvv%2Fenvalid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rojvv%2Fenvalid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rojvv","download_url":"https://codeload.github.com/rojvv/envalid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rojvv%2Fenvalid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271230596,"owners_count":24722948,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["deno","dotenv","env"],"created_at":"2024-10-01T16:36:16.481Z","updated_at":"2025-12-11T21:06:59.197Z","avatar_url":"https://github.com/rojvv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. --\u003e\n\n# envalid\n\nValidate environment variables.\n\n## Usage\n\n```ts\n// You can also use it with dotenv:\n// import \"https://deno.land/std/dotenv/load.ts\";\nimport { bool, cleanEnv, num, str } from \"https://deno.land/x/envalid/mod.ts\";\n\n// You can also do\n// export default cleanEnv(\n// to be importable from other locations.\nconst env = cleanEnv(Deno.env.toObject(), {\n  TEXT: str(),\n  IS_X: bool(),\n  APP_ID: num(),\n  SOMETHING: str({\n    default: \"default value\",\n    example: \"some string\",\n    desc: \"description\",\n    docs: \"https://example.com/configuration#SOMETHING\",\n  }),\n  CHOICE: str({ choices: [\"can be this\", \"or this\"] }),\n});\n```\n\n## Validators\n\n- `url()` - Requires the value to be a URL.\n- `email()` - Requires the value to be an email address.\n- `num()` - Parses values like \"42\", \"0.23\", and \"1e5\" into numbers.\n- `json()` - Requires the value to be JSON, and calls `JSON.parse()` on it.\n- `str()` - Requires the value to be set if a default value was not provided.\n- `port()` - Requires the value to be a port (1-6553), and converts it to\n  number.\n- `host()` - Requires the value to be either a fully-qualified domain name or a\n  v4/v6 IP address.\n- `bool()` - Requires the value to be one of \"1\", \"0\", \"true\", \"false\", \"t\", or\n  \"f\", and converts it to boolean.\n\n## Custom Validators\n\nYou can create your own validators with `makeValidator()`. It takes a single\nparameter which should be a function that returns either the cleaned value, or\nthrows if the value is not acceptable.\n\n```ts\nimport { cleanEnv, makeValidator } from \"https://deno.land/x/envalid/mod.ts\";\n\nconst twoUppercaseLetters = makeValidator((x) =\u003e {\n  if (/^[A-Za-z]{2}$/.test(x)) {\n    return x.toUpperCase();\n  } else {\n    throw new Error(\"Expected two letters\");\n  }\n});\n\nconst env = cleanEnv(Deno.env.toObject(), {\n  TWO_UPPERCASE_LETTERS: twoUppercaseLetters(),\n});\n```\n\n## Reporting Errors\n\nBy default, if any variable is missing or has an invalid value, an error message\nwill be displayed and the process exits with 1. You can override this behavior\nby using your own reporter:\n\n```ts\nimport { cleanEnv } from \"https://deno.land/x/envalid/mod.ts\";\n\nconst report = (error: string) =\u003e {\n  //\n};\n\nconst env = cleanEnv(Deno.env.toObject(), {}, {\n  reporter: ({ errors, env }) =\u003e {\n    report(\"Invalid environment variables: \" + Object.keys(errors));\n  },\n});\n```\n\nThe error classes `EnvError` and `EnvMissingError` can also be used to examine\nthe errors:\n\n```ts\nimport {\n  cleanEnv,\n  EnvError,\n  EnvMissingError,\n} from \"https://deno.land/x/envalid/mod.ts\";\n\nconst env = cleanEnv(Deno.env.toObject(), {}, {\n  reporter: ({ errors, env }) =\u003e {\n    for (const [envVar, err] of Object.entries(errors)) {\n      if (err instanceof EnvError) {\n        //\n      } else if (err instanceof EnvMissingError) {\n        //\n      } else {\n        //\n      }\n    }\n  },\n});\n```\n\n## Custom Middleware (Advanced)\n\nThe `customCleanEnv()` function allows you to completely override the\npreprocessing and validations. Its arguments are similar to `cleanEnv()` except\nfor the third one being the custom middleware function.\n\nThe custom middleware function can modify the variables after they have been\ncleaned and validated. The default middleware function,\n`applyDefaultMiddleware()` can also be combined with it.\n\n## Credits\n\n- [af/envalid](https://github.com/af/envalid).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frojvv%2Fenvalid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frojvv%2Fenvalid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frojvv%2Fenvalid/lists"}