{"id":20050050,"url":"https://github.com/kldzj/env","last_synced_at":"2026-04-11T22:47:45.671Z","repository":{"id":62461379,"uuid":"560623589","full_name":"kldzj/env","owner":"kldzj","description":"A simple and type-safe env parser","archived":false,"fork":false,"pushed_at":"2023-10-18T12:42:39.000Z","size":198,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-08T21:17:17.024Z","etag":null,"topics":["env","environment-variables","node","parser","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/@kldzj/env","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/kldzj.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}},"created_at":"2022-11-01T22:42:05.000Z","updated_at":"2025-02-12T21:11:07.000Z","dependencies_parsed_at":"2023-12-14T08:46:42.565Z","dependency_job_id":null,"html_url":"https://github.com/kldzj/env","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.10526315789473684","last_synced_commit":"fb33dfac9a4b40cb5f65b299dd014ef3fb33957b"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/kldzj/env","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kldzj%2Fenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kldzj%2Fenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kldzj%2Fenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kldzj%2Fenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kldzj","download_url":"https://codeload.github.com/kldzj/env/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kldzj%2Fenv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27283994,"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-11-26T02:00:06.075Z","response_time":193,"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":["env","environment-variables","node","parser","typescript"],"created_at":"2024-11-13T11:53:53.147Z","updated_at":"2025-11-27T22:02:18.799Z","avatar_url":"https://github.com/kldzj.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"A simple environment variable parser with type safety and validation out of the box.\n\n## Installation\n\nUsing yarn:\n\n```sh-session\n$ yarn add @kldzj/env\n```\n\nUsing npm:\n\n```sh-session\n$ npm i -S @kldzj/env\n```\n\n## Features\n\n- Type safety\n- Custom parsers\n- Optional (and default) values\n- Passing a custom environment object\n\n## Example usage\n\n```typescript\nimport { parseEnv } from '@kldzj/env';\n\nconst env = parseEnv({\n  PORT: {\n    type: 'number',\n    optional: true,\n    default: 3000,\n  },\n  NODE_ENV: {\n    type: 'string',\n    optional: true,\n  },\n  DB_URL: {\n    type: 'string',\n  },\n});\n\nconsole.log(env.PORT); // typed as number\nconsole.log(env.NODE_ENV); // typed as string | undefined\nconsole.log(env.DB_URL); // typed as string, an error is thrown in case it's missing\n```\n\n## Parser\n\nThe parser is a function that takes a string and returns a value of any type. It can be used to parse environment variables that are not strings.\n\nIf a parser is present, the type of the variable is ignored and instead the return type of the parser is used.\n\n```typescript\nimport { parseEnv } from '@kldzj/env';\n\nconst env = parseEnv({\n  DATE: {\n    parser: (value) =\u003e new Date(value),\n  },\n});\n\nconsole.log(env.DATE); // typed as Date\n```\n\n## Options\n\n```typescript\nconst env = parseEnv(\n  {\n    PORT: {\n      type: 'number',\n    },\n  },\n  {\n    env: {\n      ...process.env,\n      ...someOtherEnv,\n    },\n    throwOnNaN: true,\n    defaultParser: (value, item) =\u003e {\n      // The default parser must honor the type of the variable (item.type) if it is present\n      // ...\n      return newValue;\n    },\n  }\n);\n```\n\n### `env`\n\nAn object that contains the environment variables. If not provided, `process.env` is used.\n\n### `throwOnNaN`\n\nIf `true`, an error is thrown if a variable type is number and is parsed as `NaN`. Defaults to `false`.\n\n### `defaultParser`\n\nAllows you to override the default parser. The default parser is used when a variable does not have a custom parser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkldzj%2Fenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkldzj%2Fenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkldzj%2Fenv/lists"}