Skip to content

uwu/configmasher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

configmasher

configmasher is a config aggregator, it will reunite all your configs from different locations and different formats into a single object.

it was heavily inspired by unjs's c12 project.

Install

npm i @uwu/configmasher

Example

The config files used in this example are available here

configs
├─── .env
├─── hello.env
└─── jsonfile.json
import loadConfig from "configmasher";

const { config, layers } = await loadConfig({
  environmentFile: true,
  processEnvironment: true,

  name: "myprogram",

  configs: [
    { "jsonobject": "hello from a json object" },
    "jsonfile.json",
    "hello.env"
  ],

  defaults: {
    "defaultEntry": "this is a default item",
    "helloenvfile": "this is a default entry that will be overwritten"
  }
});

console.log(config);
/*
{
  "helloprocessenv": "this will be config.helloprocessenv",
  "envfile": "hello from the .env file",
  "envfile2": "helo",
  "helloenvfile": "this will be config.helloenvfile",
  "nested": {
    "entry": "this will be config.nested.entry"
  },
  "jsonobject": "hello from a json object"
}
*/