{"id":15481695,"url":"https://github.com/guidsdo/typed-configs","last_synced_at":"2025-04-22T15:25:02.287Z","repository":{"id":37866492,"uuid":"363875611","full_name":"guidsdo/typed-configs","owner":"guidsdo","description":"Typed Config typescript env variables and yml file","archived":false,"fork":false,"pushed_at":"2022-08-30T08:31:51.000Z","size":389,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-19T05:17:18.009Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guidsdo.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}},"created_at":"2021-05-03T09:14:43.000Z","updated_at":"2024-05-07T11:56:34.000Z","dependencies_parsed_at":"2022-08-18T19:02:33.146Z","dependency_job_id":null,"html_url":"https://github.com/guidsdo/typed-configs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidsdo%2Ftyped-configs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidsdo%2Ftyped-configs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidsdo%2Ftyped-configs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidsdo%2Ftyped-configs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guidsdo","download_url":"https://codeload.github.com/guidsdo/typed-configs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250265798,"owners_count":21402170,"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-10-02T05:05:37.002Z","updated_at":"2025-04-22T15:25:02.262Z","avatar_url":"https://github.com/guidsdo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typed Config\n\nLibrary for accessing your config variables in a typed manner, with runtime checking and a definition exporter. Supports .yml and enviroment variables.\n\n# How to use\n\n1. In your `index.ts` of your project, add `import \"reflect-metadata\";`\n1. Create a config file like this:\n\n    ```typescript\n    import { Config, ConfigValue } from \"typed-configs\";\n\n    @Config({ configYmlPath: \"configs/test.yml\" })\n    export class Communicator {\n        @ConfigValue({\n            name: \"GREETING\",\n            description: \"They way you say hi to others\",\n            required: true,\n            recommendedValue: \"Hello\"\n        })\n        greeting!: string;\n\n        @ConfigValue({\n            name: \"GOODBYE_MESSAGE\",\n            description: \"The way you say goodbye. Optional.\",\n            required: false\n        })\n        goodbye: string = \"/me left the chat\";\n\n        @ConfigValue({\n            name: \"IDLE_SOUND\",\n            description: \"What do you say when doing nothing?\",\n            required: false\n        })\n        idleMessage?: string;\n\n        @ConfigValue({\n            name: \"AGE\",\n            description: \"The driver age. should be greater than 18.\",\n            required: false,\n            validate: (age: number) =\u003e age \u003e= 18\n        })\n        age?: number;\n\n        nonConfigProperty = \"I don't need a type because I don't matter.\";\n    }\n    ```\n\n1. Use the config class somewhere in your code so the decorators get a chance to register the class and its properties.\n\n    ```typescript\n    import { Configs } from \"typed-configs\";\n\n    console.log(`User says: ${Configs.get(Communicator).greeting}`);\n    ```\n\n1. Export the config definition to an actual file (optional but kinda the goal of this library to support this). The `Configs.getConfigsDefinitions()` method is to know for sure all the decorators have been processed.\n\n    ```typescript\n    import * as fs from \"fs\";\n    import { Configs } from \"./ConfigManager\";\n\n    Configs.getConfigsDefinitions().then(definitions =\u003e {\n        fs.writeFileSync(\"configDefinitions.json\", JSON.stringify(definitions));\n    });\n    ```\n\n# Important notes:\n\n-   You're required to explicitly set the type of each field with Typescript. This is the only way we can make sure we know the required type before setting any (default) value. Only `string`, `number` and `boolean` are currently supported.\n-   For setting the type of a field, `goodbye?: string;` is allowed, but `goodbye: string | undefined;` isn't. `reflect-metadata` will give the first one type `String` and the latter `Object` (which isn't allowed by the library).\n-   When having a value that's required but doesn't have a default value (like `greeting` in our example), you can use an exclamation mark (like `greeting!: string;`) to make the types still work. The library will prevent your program to start if the value isn't provided.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguidsdo%2Ftyped-configs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguidsdo%2Ftyped-configs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguidsdo%2Ftyped-configs/lists"}