{"id":19134015,"url":"https://github.com/umbrellio/cofman","last_synced_at":"2025-05-06T19:27:41.374Z","repository":{"id":57168857,"uuid":"377547015","full_name":"umbrellio/cofman","owner":"umbrellio","description":"Node.js configuration engine","archived":false,"fork":false,"pushed_at":"2021-06-16T16:52:52.000Z","size":74,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-06T19:27:34.854Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/umbrellio.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}},"created_at":"2021-06-16T15:41:32.000Z","updated_at":"2024-09-25T14:32:25.000Z","dependencies_parsed_at":"2022-09-13T04:50:36.472Z","dependency_job_id":null,"html_url":"https://github.com/umbrellio/cofman","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fcofman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fcofman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fcofman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fcofman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/umbrellio","download_url":"https://codeload.github.com/umbrellio/cofman/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252752178,"owners_count":21798743,"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-11-09T06:24:48.369Z","updated_at":"2025-05-06T19:27:41.335Z","avatar_url":"https://github.com/umbrellio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cofman\n\n[![Coverage Status](https://coveralls.io/repos/github/umbrellio/cofman/badge.svg?branch=master)](https://coveralls.io/github/umbrellio/cofman?branch=master)\n[![Build Status](https://github.com/umbrellio/cofman/actions/workflows/ci.yml/badge.svg)](https://github.com/umbrellio/cofman)\n\nNode.js configuration engine\n\n```js\nconst { Cofman, FileSource, EnvSourc, ObjectSource } = require(\"@umbrellio/cofman\")\n\nconst instance = new Cofman()\n\ninstance.use(new FileSource({ path: \"/path/to/file.yml\" }))\ninstance.use(new FileSource({ path: \"/path/to/file.json\" }))\ninstance.use(new ObjectSource({ custom: \"value\" }))\ninstance.use(new EnvSource({ prefix: \"APP\" }))\n\nconst config = instance.parse()\n\nconfig.get(\"database.url\")\n```\n\n## Install\n\n```sh\n$ yarn add @umbrellio/cofman\n```\n\n## Usage\n\n```js\nconst instance = new Cofman()\n```\n\n**Methods**\n\n- `.use(source)` – setup a config source (see [sources](#sources) docs)\n- `.parse()` – parse sources and return [`Config`](#config-object) object\n\n### Config object\n\n**Methods**\n\n- `.get(key: string, default: any)` – returns a value by corresponding key or default value\n\n  `key` can be nested by using `.` . For example – `database.password`\n\n- `.asObject()` – returns config as a plain object\n\n## Sources\n\nCofman supports multiple sources for getting values in different ways.\n\n- [EnvSource](#envsource)\n- [FileSource](#filesource)\n- [ObjectSource](#objectsource)\n\n### EnvSource\n\nGet values from env variables. All keys becomes camelCase.\n\n```js\nnew EnvSource(options)\n```\n\n**Options**\n\n- `prefix: string` (optional, default: `\"\"`) – prefix for filtering env vars\n  eg. if `prefix: \"APP\"` cofman will only get vars starts with `APP_` (`APP_DATABASE_URL`, `APP_NAME`, etc.)\n- `tryParse: boolean` (optional, default: `true`) – try to parse value as a json\n- `nestingDelitemer: string` (optional, default: `__`) – delimeter for getting nesting values\n  eg. `SOME__NESTING_VALUE=1` becomes `some: { nestingValue: 1 }`\n\n### FileSource\n\nReads config from `json` and `yaml` files.\n\n```js\nnew FileSource(options)\n```\n\n**Options**\n\n- `path: string` (required)  – path to config file\n- `parser: Parser` (optional, determinites by file extension) – parser to use for this file content\n- `failMissing: boolean` (optional, default: `false`) – fail when file missing or not\n\nYou can use custom file parsers using following interface:\n\n```ts\ninterface Parser {\n  extensions: string[] // supported file extensions\n\n  parse(content: string): Object // takes file content and returns parsed object\n}\n```\n\n### ObjectSource\n\nJust your custom object\n\n```js\nnew ObjectSource(object)\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/cofman.\n\n## License\n\nReleased under MIT License.\n\n## Authors\n\nCreated by [Aleksei Bespalov](https://github.com/nulldef).\n\n\u003ca href=\"https://github.com/umbrellio/\"\u003e\n\u003cimg style=\"float: left;\" src=\"https://umbrellio.github.io/Umbrellio/supported_by_umbrellio.svg\" alt=\"Supported by Umbrellio\" width=\"439\" height=\"72\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumbrellio%2Fcofman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumbrellio%2Fcofman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumbrellio%2Fcofman/lists"}