{"id":28855937,"url":"https://github.com/iamflowz/safe-ts-env","last_synced_at":"2026-05-04T12:35:47.145Z","repository":{"id":293846215,"uuid":"985295074","full_name":"IamFlowZ/safe-ts-env","owner":"IamFlowZ","description":"Helper function to parse environment variables from JSON files","archived":false,"fork":false,"pushed_at":"2025-06-19T22:33:02.000Z","size":12237,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-21T07:53:04.524Z","etag":null,"topics":["awscdk","cdk","environment","environment-variables","npm","npm-package","react","typescript","typescript-library","vue","zod","zod-validation"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/safe-ts-env","language":"HTML","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/IamFlowZ.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2025-05-17T13:14:57.000Z","updated_at":"2025-09-02T19:45:01.000Z","dependencies_parsed_at":"2025-06-19T22:47:49.098Z","dependency_job_id":null,"html_url":"https://github.com/IamFlowZ/safe-ts-env","commit_stats":null,"previous_names":["iamflowz/type-safe-cdk-env","iamflowz/safe-ts-env","iamflowz/type-safe-env"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/IamFlowZ/safe-ts-env","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamFlowZ%2Fsafe-ts-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamFlowZ%2Fsafe-ts-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamFlowZ%2Fsafe-ts-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamFlowZ%2Fsafe-ts-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IamFlowZ","download_url":"https://codeload.github.com/IamFlowZ/safe-ts-env/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamFlowZ%2Fsafe-ts-env/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31449838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T15:22:31.103Z","status":"ssl_error","status_checked_at":"2026-04-05T15:22:00.205Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["awscdk","cdk","environment","environment-variables","npm","npm-package","react","typescript","typescript-library","vue","zod","zod-validation"],"created_at":"2025-06-20T00:09:29.749Z","updated_at":"2026-04-05T21:03:37.270Z","avatar_url":"https://github.com/IamFlowZ.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# safe-ts-env\n\nA TypeScript library that provides type-safe environment configuration.\n\n## Installation\n\n```bash\nnpm install safe-ts-env\n```\n\n## Features\n\n- **Type Safety**: Leverage TypeScript's type system to ensure your environment configurations are correctly typed\n- **Runtime Validation**: Use Zod schemas to validate environment configurations at runtime\n- **Flexible Path Handling**: Support for both string and array path formats\n- **Error Handling**: Built-in error handling with optional debug logging\n- **Zero Configuration**: Simple API that works out of the box\n\n## Usage\n\n### Basic Example\n\n```typescript\nimport { getEnv } from 'safe-ts-env';\nimport { z } from 'zod';\n\n// Define your environment schema using Zod\nconst envSchema = z.object({\n  name: z.string(),\n  region: z.string(),\n  stage: z.enum(['dev', 'staging', 'prod']),\n  instanceCount: z.number().int().positive(),\n});\n\n// Load and validate your environment configuration\nconst checkedEnv = getEnv('path/to/env/file.json', envSchema);\n\n// TypeScript knows the exact shape of checkedEnv\nconsole.log(checkedEnv.name); // string\nconsole.log(checkedEnv.region); // string\nconsole.log(checkedEnv.stage); // 'dev' | 'staging' | 'prod'\nconsole.log(checkedEnv.instanceCount); // number\n```\n\n### Using Array Path\n\nYou can also provide the path as an array of path segments:\n\n```typescript\nconst checkedEnv = getEnv(['path', 'to', 'env', 'file.json'], envSchema);\n```\n\n### Using with `process.env`\n\n```typescript\nconst checkedEnv = getEnv('path/to/env/file.json', envSchema);\n\nprocess.env = {\n  ...process.env,\n  ...Object.fromEntries(\n    Object.entries(checkedEnv).map(([key, value]) =\u003e [key, String(value)]),\n  ),\n};\n```\n\n### Using with CDK\n\n```typescript\n// Define your environment schema using Zod\nconst envSchema = z.object({\n  name: z.string(),\n  region: z.string(),\n  stage: z.enum(['dev', 'staging', 'prod']),\n  instanceCount: z.number().int().positive(),\n});\nconst checkedEnv = getEnv('path/to/env/file.json', envSchema);\n\nconst stackProps = {\n  ...process.env,\n  ...Object.fromEntries(\n    Object.entries(checkedEnv).map(([key, value]) =\u003e [key, String(value)]),\n  ),\n};\n\n// Use in your CDK stack\nnew MyStack(app, 'MyStack', stackProps);\n```\n\n### Error Handling\n\nThe library will throw an error if:\n\n- The environment file cannot be found or read\n- The file content doesn't match the provided schema\n\nYou can enable debug logging by setting the `DEBUG` environment variable:\n\n```bash\nDEBUG=true npm run start\n```\n\n## API Reference\n\n### `getEnv\u003cT\u003e`\n\nLoads and validates environment configuration from a file.\n\n#### Parameters\n\n- `pathOfEnvFile`: `string | Array\u003cstring\u003e` - Path to the environment file\n- `envSchema`: `z.ZodObject\u003cany\u003e` - Zod schema for validating the environment configuration\n\n#### Returns\n\n- `z.infer\u003cT\u003e` - The validated environment configuration with inferred types from the schema\n\n#### Throws\n\n- `Error` - If the file cannot be found or read\n- `z.ZodError` - If the file content doesn't match the provided schema\n\n## Contributing\n\nContributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamflowz%2Fsafe-ts-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamflowz%2Fsafe-ts-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamflowz%2Fsafe-ts-env/lists"}