Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stacksjs/bunfig

💡 Lightweight & smart Bun configuration loader.
https://github.com/stacksjs/bunfig

bun config library loader typescript

Last synced: 1 day ago
JSON representation

💡 Lightweight & smart Bun configuration loader.

Awesome Lists containing this project

README

        

Social Card of this repo

[![npm version][npm-version-src]][npm-version-href]
[![GitHub Actions][github-actions-src]][github-actions-href]
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

## Features

- Smart configuration loader
- Lightweight & zero-dependency
- Fully typed

## Install

```bash
bun install -d bun-config
```

## Get Started

If you are building any sort of Bun project, you can use the `loadConfig` function to load your configuration.

```ts
import type { Config } from 'bunfig'
import { loadConfig } from 'bunfig'

interface MyLibraryConfig {
port: number
host: string
}

const options: Config = {
name: 'my-app', // required
cwd: './', // default: process.cwd()
defaults: { // default: {}
port: 3000,
host: 'localhost',
},
}

const resolvedConfig = await loadConfig(options)

console.log(resolvedConfig) // { port: 3000, host: 'localhost' }, unless a config file is found
```

> [!TIP]
> If your process.cwd() includes a `$name.config.{ts,js,mjs,cjs}` file, it will be loaded and merged with the defaults, with file config file values taking precedence.

## Testing

```bash
bun test
```

## Changelog

Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.

## Contributing

Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.

## Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)

For casual chit-chat with others using this package:

[Join the Stacks Discord Server](https://discord.gg/stacksjs)

## Postcardware

Two things are true: Stacks OSS will always stay open-source, and we do love to receive postcards from wherever Stacks is used! 🌍 _We also publish them on our website. And thank you, Spatie_

Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094

## Sponsors

We 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.

- [JetBrains](https://www.jetbrains.com/)
- [The Solana Foundation](https://solana.com/)

## Credits

- [Chris Breuer](https://github.com/chrisbbreuer)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/bun-config/tree/main/LICENSE.md) for more information.

Made with 💙

[npm-version-src]: https://img.shields.io/npm/v/bun-config?style=flat-square
[npm-version-href]: https://npmjs.com/package/bun-config
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/bun-config/ci.yml?style=flat-square&branch=main
[github-actions-href]: https://github.com/stacksjs/bun-config/actions?query=workflow%3Aci