{"id":14156013,"url":"https://github.com/pitininja/envious","last_synced_at":"2025-08-06T02:31:15.520Z","repository":{"id":215144570,"uuid":"667443222","full_name":"pitininja/envious","owner":"pitininja","description":"Environment variable parsing using Dotenv \u0026 Typebox","archived":false,"fork":false,"pushed_at":"2024-11-25T19:14:24.000Z","size":355,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-27T09:06:27.649Z","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":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pitininja.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":"2023-07-17T14:10:33.000Z","updated_at":"2024-11-25T19:14:26.000Z","dependencies_parsed_at":"2024-01-04T17:49:38.804Z","dependency_job_id":"2443656d-793f-45cc-898f-77255f9849dc","html_url":"https://github.com/pitininja/envious","commit_stats":null,"previous_names":["pitininja/envious"],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitininja%2Fenvious","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitininja%2Fenvious/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitininja%2Fenvious/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitininja%2Fenvious/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pitininja","download_url":"https://codeload.github.com/pitininja/envious/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228829028,"owners_count":17978136,"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":[],"created_at":"2024-08-17T08:05:09.447Z","updated_at":"2024-12-09T03:30:55.793Z","avatar_url":"https://github.com/pitininja.png","language":"TypeScript","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"# Envious\n\n\u003e Environment variable parsing using Dotenv \u0026 Typebox\n\n## Install\n\n```shell\nnpm i @pitininja/envious\n```\n\n## Usage\n\nEnvironment variables are automatically loaded using [Dotenv](https://github.com/motdotla/dotenv).\n\nRefer to the [official Typebox documentation](https://github.com/sinclairzx81/typebox) for how to write a Typebox schema.\n\n```typescript\nimport { envious } from '@pitininja/envious';\nimport { Type } from '@sinclair/typebox';\n\nconst env = envious(\n    Type.Object({\n        STRING_VAR: Type.String(),\n        NUMBER_VAR: Type.Integer(),\n        BOOLEAN_VAR_WITH_DEFAULT: Type.Boolean({ default: false }),\n        OPTIONAL_VAR: Type.Optional(Type.String())\n    })\n);\n```\n\n## Formats\n\nString formats can be loaded in the `formats` property of the options parameter, as an object with the format name as key and a regex or a validation function as value.\n\n```typescript\nimport { envious } from '@pitininja/envious';\nimport { Type } from '@sinclair/typebox';\nimport dayjs from 'dayjs';\n\nconst env = envious(\n    Type.Object({\n        EXAMPLE_URI: Type.String({ format: 'uri' }),\n        EXAMPLE_DATE: Type.String({ format: 'date' })\n    }),\n    {\n        formats: {\n            uri: /^(?:[a-z][a-z0-9+\\-.]*:)(?:\\/?\\/)?[^\\s]*$/i,\n            date: (val) =\u003e dayjs(val).isValid()\n        }\n    }\n);\n```\n\n## Errors\n\nIf something goes wrong, Envious will throw an error of class `EnviousError`.\n\nAn `EnviousError` error contains a message and a list of `ValueError` (an error class taken from Typebox).\n\nHere is a simple example of how to handle Envious errors :\n\n```typescript\nimport { envious, EnviousError } from '@pitininja/envious';\nimport { Type } from '@sinclair/typebox';\n\ntry {\n    const env = envious(\n        Type.Object({\n            STRING_VAR: Type.String()\n        })\n    );\n} catch (err: unknown) {\n    if (err instanceof EnviousError) {\n        console.log('Message:', err.message); // Error message\n        console.log('Errors:', err.errors); // Typebox's ValueError array\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpitininja%2Fenvious","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpitininja%2Fenvious","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpitininja%2Fenvious/lists"}