{"id":23535759,"url":"https://github.com/stacksjs/bunfig","last_synced_at":"2025-04-23T07:01:50.416Z","repository":{"id":260033721,"uuid":"875383255","full_name":"stacksjs/bunfig","owner":"stacksjs","description":"⚙️ Lightweight \u0026 smart Bun \u0026 Browser configuration loader.","archived":false,"fork":false,"pushed_at":"2025-04-18T20:58:18.000Z","size":1544,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T21:57:02.306Z","etag":null,"topics":["bun","config","library","loader","typescript"],"latest_commit_sha":null,"homepage":"https://bunfig.netlify.app","language":"TypeScript","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/stacksjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["stacksjs","chrisbbreuer"],"open_collective":"stacksjs"}},"created_at":"2024-10-19T20:32:45.000Z","updated_at":"2025-04-18T20:58:00.000Z","dependencies_parsed_at":"2024-10-29T06:28:27.001Z","dependency_job_id":"4ebaf78a-d065-4ef4-8353-f87b2bf3656b","html_url":"https://github.com/stacksjs/bunfig","commit_stats":{"total_commits":24,"total_committers":2,"mean_commits":12.0,"dds":0.04166666666666663,"last_synced_commit":"39b7300c255bfdc2a49eda3f11507769c3a78ff1"},"previous_names":["stacksjs/bun-config","stacksjs/bunfig"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fbunfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fbunfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fbunfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fbunfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stacksjs","download_url":"https://codeload.github.com/stacksjs/bunfig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250386746,"owners_count":21422026,"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":["bun","config","library","loader","typescript"],"created_at":"2024-12-26T01:44:01.801Z","updated_at":"2025-04-23T07:01:50.401Z","avatar_url":"https://github.com/stacksjs.png","language":"TypeScript","funding_links":["https://github.com/sponsors/stacksjs","https://github.com/sponsors/chrisbbreuer","https://opencollective.com/stacksjs"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/stacksjs/bunfig/blob/main/.github/art/cover.jpg?raw=true\" alt=\"Social Card of this repo\"\u003e\u003c/p\u003e\n\n[![npm version][npm-version-src]][npm-version-href]\n[![GitHub Actions][github-actions-src]][github-actions-href]\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\u003c!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] --\u003e\n\u003c!-- [![Codecov][codecov-src]][codecov-href] --\u003e\n\n# Bunfig\n\n\u003e Smart configuration loader for libraries, apps, and CLIs built utilizing Bun.\n\n## Features\n\n- 🔄 **Smart Config**: _intelligent configuration loading_\n- 🌐 **Universal**: _optimized for both Bun \u0026 browser environments_\n- 🪶 **Lightweight**: _zero dependencies, built on native modules_\n- 💪 **Type-Safe**: _fully typed configurations with generated type definitions_\n- 🛠️ **CLI Tools**: _powerful \u0026 easy-to-use CLI_\n- 📦 **Flexible**: _supports multiple config file formats (.ts, .js, .mjs, .cjs, .json, .mts, .cts)_\n\n## Install\n\n```bash\nbun install -d bunfig\n```\n\n## Get Started\n\n### Server Environment\n\nIf you are building any sort of Bun project, you can use the `loadConfig` function to load your configuration from files:\n\n```ts\nimport type { Config } from 'bunfig'\nimport { loadConfig } from 'bunfig'\n\ninterface MyLibraryConfig {\n  port: number\n  host: string\n}\n\nconst options: Config\u003cMyLibraryConfig\u003e = {\n  name: 'my-app', // required\n  cwd: './', // default: process.cwd()\n  defaultConfig: { // default: {}\n    port: 3000,\n    host: 'localhost',\n  },\n}\n\nconst resolvedConfig = await loadConfig(options)\n\nconsole.log(resolvedConfig) // { port: 3000, host: 'localhost' }, unless a config file is found\n```\n\n\u003e [!TIP]\n\u003e If your `process.cwd()` includes a `$name.config.{ts,js,mjs,cjs,json}` _(or `.$name.config.{ts,js,mjs,cjs,json}`)_ file, it will be loaded and merged with defaults, where file config file values take precedence. For minimalists, it also loads a `.$name.{ts,js,mjs,cjs,json}` and `$name.{ts,js,mjs,cjs,json}` file if present.\n\n### Browser Environment\n\nFor browser environments, use the `loadConfig` function from the browser-specific entry point to load your configuration from an API endpoint:\n\n```ts\nimport type { Config } from 'bunfig'\nimport { loadConfig } from 'bunfig/browser'\n\ninterface MyLibraryConfig {\n  port: number\n  host: string\n}\n\nconst options: Config\u003cMyLibraryConfig\u003e = {\n  name: 'my-app',\n  endpoint: '/api/config', // required for browser environment\n  defaultConfig: {\n    port: 3000,\n    host: 'localhost',\n  },\n  headers: { // optional custom headers\n    'Authorization': 'Bearer token',\n    'X-Custom-Header': 'value',\n  },\n}\n\nconst resolvedConfig = await loadConfig(options)\n```\n\nIn the browser:\n\n- The `endpoint` parameter is required to specify where to fetch the configuration\n- Custom headers can be provided to authenticate or customize the request\n- Default headers (`Accept` and `Content-Type`) are automatically included\n- If the fetch fails, the default configuration is used as a fallback\n\n### Alternative Usage\n\nAlternatively, you can use the `config` function to load your configuration in server environments:\n\n```ts\nimport type { Config } from 'bunfig'\nimport { config } from 'bunfig'\n\ninterface MyAppOrLibraryConfig {\n  port: number\n  host: string\n}\n\nconst options: Config\u003cMyAppOrLibraryConfig\u003e = {\n  name: 'my-app', // required to know which config file to load\n  cwd: './', // default: process.cwd()\n  defaultConfig: { // default: {}\n    port: 3000,\n    host: 'localhost',\n  },\n}\n\nconst resolvedConfig = await config(options)\n```\n\nThe config function is a wrapper around the `loadConfig` function and is useful for loading configuration in a more flexible way. It accepts an options object with the following properties:\n\n- `name`: The name of the config file to load.\n- `cwd`: The current working directory to load the config file from.\n- `defaultConfig`: The default config to use if no config file is found.\n\nFor browser usage, see the [Browser Environment](#browser-environment) section above.\n\n## Testing\n\n```bash\nbun test\n```\n\n## Changelog\n\nPlease see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.\n\n## Contributing\n\nPlease review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.\n\n## Community\n\nFor help, discussion about best practices, or any other conversation that would benefit from being searchable:\n\n[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)\n\nFor casual chit-chat with others using this package:\n\n[Join the Stacks Discord Server](https://discord.gg/stacksjs)\n\n## Postcardware\n\n“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where `bunfig` is being used! We showcase them on our website too.\n\nOur address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎\n\n## Sponsors\n\nWe would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.\n\n- [JetBrains](https://www.jetbrains.com/)\n- [The Solana Foundation](https://solana.com/)\n\n## Credits\n\n- [Chris Breuer](https://github.com/chrisbbreuer)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/bunfig/tree/main/LICENSE.md) for more information.\n\nMade with 💙\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/v/bunfig?style=flat-square\n[npm-version-href]: https://npmjs.com/package/bunfig\n[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/bunfig/ci.yml?style=flat-square\u0026branch=main\n[github-actions-href]: https://github.com/stacksjs/bunfig/actions?query=workflow%3Aci\n\n\u003c!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/bunfig/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/stacksjs/bunfig --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fbunfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstacksjs%2Fbunfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fbunfig/lists"}