{"id":18982282,"url":"https://github.com/profusion/validated-env-schema","last_synced_at":"2026-06-30T12:31:26.985Z","repository":{"id":41124584,"uuid":"360968105","full_name":"profusion/validated-env-schema","owner":"profusion","description":"Validate environment variables against JSON Schema7","archived":false,"fork":false,"pushed_at":"2023-05-25T21:42:21.000Z","size":423,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-08-08T21:13:59.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/profusion.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}},"created_at":"2021-04-23T18:06:28.000Z","updated_at":"2023-05-25T11:21:40.000Z","dependencies_parsed_at":"2025-01-01T11:41:57.685Z","dependency_job_id":"f33f969f-dc97-48e0-ac4b-150844f3896e","html_url":"https://github.com/profusion/validated-env-schema","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/profusion/validated-env-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profusion%2Fvalidated-env-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profusion%2Fvalidated-env-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profusion%2Fvalidated-env-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profusion%2Fvalidated-env-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/profusion","download_url":"https://codeload.github.com/profusion/validated-env-schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profusion%2Fvalidated-env-schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34967614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-30T02:00:05.919Z","response_time":92,"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":[],"created_at":"2024-11-08T16:13:02.273Z","updated_at":"2026-06-30T12:31:26.832Z","avatar_url":"https://github.com/profusion.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Validated Environments using JSON Schema\n\nThis script eases the usage of environment variables in your\napplications by using [Ajv](https://ajv.js.org/) in coerce mode.\n\nIt will take care to check the variable in various complex formats,\nincluding arrays and objects, applying all of the\n[JSON Schema](https://json-schema.org/understanding-json-schema/)\nrules, which includes:\n- required properties\n- default values\n- minimum and maximum elements in an array\n- string patterns\n\nThe sanitized values are serialized to strings and are written back to\nthe variable, while the invalid variables are deleted. One can trust\nonly valid variables exist after the process finishes.\n\nThe parse, serialize and post-validate of properties can be customized,\nthis allows non-JSON encoding to be supported (such as comma-separated\nlists, booleans using 'y/n', etc).\n\nThe resulting object will have TypeScript signature based on the\nJSON schema, so `prop: { type: 'number' }` results in `prop: number`.\n\nJSON types can be converted to high-level types with convert functions,\nthey will also define the type of the resulting object. For instance\nthe JSON type can be a `string` (ISO8601 formatted date) while\nthe converted type can be `Date`, this will reflect in the TypeScript\nobject. (Note that the converted values are **NOT** serialized/written\nback to the container/process.env)\n\n## Install\n\n```sh\nyarn add @profusion/validated-env-schema\n```\n\n## Usage\n\n```ts\nimport validateEnvVars from '@profusion/validated-env-schema';\n\nconst values = validateEnvVars({\n  properties: {\n    AUTH_TOKEN: { type: 'string' },\n    TTL: { type: 'number' },\n  },\n  required: ['AUTH_TOKEN'],\n  type: 'object',\n} as const);\nconsole.log('values:', values.AUTH_TOKEN, values.TTL);\n// values.AUTH_TOKEN is type: string\n// values.TTL is type: number | undefined (not int required array)\n```\n\nSee more complete [usage example](./examples/usage.ts).\n\n**NOTE:** This package doesn't load the environment variables from\nfiles, they must be present when the validation call is executed.\n\nDebug messages can be enabled with `VALIDATED_ENV_SCHEMA_DEBUG=true`,\nthis will print out extensive debug.\n\n### JSON Schema String Formats\n\nIn order to use `{ \"type\": \"string\", \"format\": \"...\"}`, one must\ninstall [ajv-formats](https://github.com/ajv-validator/ajv-formats):\n\n```sh\nyarn add ajv-formats\n```\n\n### Usage with dotenv and others\n\nThe packages such as `dotenv` can be used with this software\nwithout any specific configuration, just require those packages,\neither explicit or using `node -r dotenv/config app.js`\n\n\n## Similar Packages\n\nThis package is similar to\n[fastify/env-schema](https://github.com/fastify/env-schema), as it\nuses Ajv in the same way, but the usage interface is different.\n\nThis project's  `validateEnvVars()` takes an optional customize\nobject that can handle parse, serialization, post-validation and\nconversion to native type for each property. It will also\nproperly type the returned object, will remove invalid properties\nand throw errors.\n\n## License\n\nOpen source - [MIT](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofusion%2Fvalidated-env-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprofusion%2Fvalidated-env-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofusion%2Fvalidated-env-schema/lists"}