config-stack
keep your configurations organized and stacked
Why Config Stack ?
When building a modern application, you don’t want to worry about configuration file formats; you want to focus on building awesome software. config-stack is here to help with that.
Features
- Find, load, and parse a configuration file in JSON, TOML, YAML, HJSON, JSON5.
- Provide a mechanism to set default values for your different configuration options.
- Working with environment variables (This enables 12 factor applications)
- Working with different deployment environments (development, qa, staging, production, etc.).
- Find, load, and parse a command line
- Support both typescript and javascript
- inject configuration using typescript decorator
- Type safety
- Transform configuration value to a specified type
- zero-dependency module
Example
- typescript - load from file
configStack // or to default environment configStack configStack // or any other function
- javascript - load from file
const configStack = configStack // or to default environment configStack configStack // or any other function
- typescript - bind all environment variables
configStack; // ENV will be in lowercase "env" console;
- javascript - bind all environment variables
const configStack = configStack; // ENV will be in lowercase "env" console;
- typescript - bind specific environment variable
configStack; console;
- javascript - bind specific environment variable
const configStack = configStack; console;
- typescript - set target environment
configStack configStack configStack // or from default environment console; // print 2
- javascript - set target environment
const configStack = configStack configStack configStack // or from default environment console; // print 2
- typescript - bind object
const obj = nested: key: "1" ; console // {key: "1"} console // 1 console // '1'
- javascript - bind object
const configStack = const obj = nested: key: "1" ; console // {key: "1"} console // 1 console // '1'
- typescript - working with command line
const flag = configStack; flag; flag; flag; flag; configStack; console; console; console;
- javascript - working with command line
const configStack = const flag = configStack; flag; flag; flag; flag; configStack; console; console; console;
./example.js --help./example.js -b 01-12-2003 --name john --student
- typescript - working with custom binder
implements configStackBinder { }
- javascript - working with custom binder
const configStack = { }configStack
- typescript - decorators
@configStack public name: string; @configStack public _any: any; @configStack public age: number; @configStack public isValid: boolean; @configStack public regex: RegExp; @configStack public date: Date; @configStack public Object: Object; @configStack public array: any; @configStack public boolean_array: boolean; @configStack public string_array: string; @configStack public number_array: number;
Installation
Install using npm:
npm install config-stack
Documentation
- Functions documentation is available right here
- Decorators documentation is available right here
- Caster documentation is available right here
Roadmap
- support remote config like etcd
- laze automatic env
- load config-stack schema
- environment variables prefix
Contributing
I welcome any contributions, features, enhancements, and bug-fixes. File an issue on GitHub and submit a pull request.
License
Type config-stack is 100% free and open-source, under the MIT license. Use it however you want.