c11 v0.1.0
c11
Smart Config Loader
Features
- JSON, CJS, Typescript and ESM config loader with unjs/jiti
- RC config support with unjs/rc9
- Multiple sources merged with unjs/defu
.env
support with dotenv
Usage
Install package:
# npm
npm install c11
# yarn
yarn install c11
# pnpm
pnpm install c11
Import:
// ESM
import { loadConfig } from 'c11'
// CommonJS
const { loadConfig } = require('c11')
Load configuration:
const { config } = await loadConfig({})
Loading priority
c11 merged config sources with unjs/defu by below order:
- config overrides passed by options
- config file in CWD
- RC file in CWD
- global RC file in user's home directory
- default config passed by options
Options
cwd
Resolve configuration from this working directory. Default is process.cwd()
name
Configuration base name. Default is config
.
configName
Configuration file name without extension . Default is generated from name
(name=foo => foo.config
).
Set to false
to avoid loading config file.
rcFile
RC Config file name. Default is generated from name
(name=foo => .foorc
).
Set to false
to disable loading RC config.
globalRC
Load RC config from the user's home directory. Only enabled when rcFile
is provided. Set to false
to disable this functionality.
dotenv
Loads .env
file if enabled. It is disabled by default.
defaults
Specify default configuration. It has the lowest priority.
overides
Specify override configuration. It has the highest priority.
💻 Development
- Clone this repository
- Enable Corepack using
corepack enable
(usenpm i -g corepack
for Node.js < 16.10) - Install dependencies using
yarn install
- Run interactive tests using
yarn dev
License
Made with 💛 Published under MIT License.