{"id":21261522,"url":"https://github.com/chenasraf/unaconfig_dart","last_synced_at":"2025-03-15T07:12:21.243Z","repository":{"id":216745024,"uuid":"742208692","full_name":"chenasraf/unaconfig_dart","owner":"chenasraf","description":"Easiest way to get the user config for your library using Dart. Inspired by NPM's cosmiconfig","archived":false,"fork":false,"pushed_at":"2024-02-17T11:27:01.000Z","size":54,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T22:11:23.694Z","etag":null,"topics":["config","dart"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/unaconfig","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chenasraf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"chenasraf","patreon":null,"open_collective":null,"ko_fi":"casraf","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2024-01-12T01:18:00.000Z","updated_at":"2024-12-02T07:52:07.000Z","dependencies_parsed_at":"2024-02-17T01:24:45.858Z","dependency_job_id":"0df328b7-b623-4db9-87be-0ffbff9a4ec7","html_url":"https://github.com/chenasraf/unaconfig_dart","commit_stats":null,"previous_names":["chenasraf/unaconfig_dart"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Funaconfig_dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Funaconfig_dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Funaconfig_dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Funaconfig_dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenasraf","download_url":"https://codeload.github.com/chenasraf/unaconfig_dart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243695589,"owners_count":20332629,"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":["config","dart"],"created_at":"2024-11-21T04:43:39.119Z","updated_at":"2025-03-15T07:12:21.221Z","avatar_url":"https://github.com/chenasraf.png","language":"Dart","funding_links":["https://github.com/sponsors/chenasraf","https://ko-fi.com/casraf"],"categories":[],"sub_categories":[],"readme":"# unaconfig\n\nIf you are bulding a package or library for dart, you will often need to get the user config from\neither a standalone file or pubspec.yaml.\n\nUnaconfig lets you find files in various formats and get the first config that matches.\n\n## Features\n\n- Just set your config name and search\n- Customizable parsers, so any file type can be supported\n- Default parsers for key under `pubspec.yaml`\n- Fully customizable\n\n## Getting started\n\nInstall into your dependencies using pub:\n\n```bash\ndart pub add unaconfig\n```\n\n## Usage\n\n### Basic Usage\n\nCreate an explorer and search:\n\n```dart\nfinal config = await Unaconfig('my_package').search();\n```\n\n### Providing paths and options\n\nYou can provide several parameters to the `Unaconfig` to change where and how it searches for files.\n\nOnly the first parameter, `name`, is required. Below are the default values:\n\n```dart\nfinal explorer = Unaconfig(\n  // Name to look for in filenames\n  'my_package',\n  // Paths to search in, see \"Paths\" section\n  paths: [currentDirectory, projectRoot, homeDirectory],\n  // Filenames to try in each search path, see \"Filename Patterns\" section\n  filenamePatterns: Unaconfig.defaultFilenamePatterns,\n  // Parsers that resolve config files, see \"ConfigParsers\" section\n  parsers: Unaconfig.defaultParsers,\n  // The filesystem to use for file searching. Can be overridden for tests, or using alternative\n  // filesystems.\n  fs: LocalFileSystem(),\n);\n```\n\n## Paths\n\nUnaconfig searches in several directories, matching on the first matched file \u0026 config.\n\nBy default, the following directories are tried, in order:\n\n- The current directory\n- The project root (closest dir to current that contains `pubspec.yaml`)\n- The user's home dir\n\nPatterns with paths containing directories in the `filenamePatterns` field can be triggered for the\nprovided directories inside any of the above or provided paths. For example, `.config/{name}.yaml`\nwill also try to use both `\u003cprojectRoot\u003e/.config/{name}.yaml` and `$HOME/.config/{name}.yaml`,\nreturning the first successful match.\n\n## Filename Patterns\n\nFilename patterns patterns define what files to look for in each searched directory.\n\n- Each string will eventually become a `RegExp` pattern, so be sure to escape as necessary.\n- `{name}` inside the patterns is replaced by the name provided to the `Unaconfig`.\n\nA successful match will start going through the ConfigParsers until a config map is returned from\nit.\n\nBy default, Unaconfig checks the for the following config files in every matched dir:\n\n- A property in `pubspec.yaml`\n- `{name}.yaml`\n- `{name}.json`\n- `.{name}.yaml`\n- `.{name}.json`\n- `.config/{name}.yaml`\n- `.config/{name}.json`\n\n## ConfigParsers\n\nA config parser takes the file and its contents, along with the name to lookup, and produces a final\nconfig map.\n\nEach parser takes a pattern, which is tested against the file name to decide that this parser will\nbe used on it.\n\nIt also takes a function, which given the config name, path and string contents should return a\n`Map\u003cString, dynamic\u003e` which represents the config that you want to load.\n\nFor example, this is the `ConfigParser` for `json` files, you can use this example to implement your\nown:\n\n```dart\nConfigParser(\n  RegExp(r'.*\\.json$'),\n  (name, path, contents) =\u003e json.decode(contents),\n)\n```\n\nThe current parsers are:\n\n- `pubspec.yaml` - Fetches the `name` from the config, and only loads that subsection of the map\n- Any `yaml` file - parse yaml file entirely\n- Any `json` file - parse json file entirely\n\nYou can create your own parsers easily by implementing an instance of this class (or extend to a\nsubclass) and putting it in the `parsers` parameter of `Unaconfig`.\n\n**Note:** if you supply your own parsers, they will replace the defaults. Make sure to include them\nmanually from `Unaconfig.defaultparsers` if you so desire.\n\n## Notes\n\nThe package is inspired by [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) and follows\nsimilar, but not identical, conventions. It is not aimed to reach full symmetry, as the NPM and Dart\necosystems are different (for example, `.dart` files cannot be dynamically loaded, and `.{name}rc`\nfiles are not usually used in the Dart/Pub ecosystem). However, you are free to implement your own\nConfigParsers, paths and name patterns to modify the behaviors as you wish.\n\n## Contributing\n\nI am developing this package on my free time, so any support, whether code, issues, or just stars is\nvery helpful to sustaining its life. If you are feeling incredibly generous and would like to donate\njust a small amount to help sustain this project, I would be very very thankful!\n\n\u003ca href=\"https://ko-fi.com/casraf\" target=\"_blank\"\u003e\n  \u003cimg height=\"36\"\n    src=\"https://cdn.ko-fi.com/cdn/kofi1.png?v=3\"\n    alt=\"Buy Me a Coffee at ko-fi.com\" /\u003e\n\u003c/a\u003e\n\nI welcome any issues or pull requests on GitHub. If you find a bug, or would like a new feature,\ndon't hesitate to open an appropriate issue and I will do my best to reply promptly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenasraf%2Funaconfig_dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenasraf%2Funaconfig_dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenasraf%2Funaconfig_dart/lists"}