twconf
Attention: this is beta version. Use it in production with caution.
NodeJS module for strictly configuration from environment variables.
; const conf = 'database.mongodb.uri': comment: 'MongoDB connection URI' simple: 'mongodb://localhost/test1' type: allowed: /mongodb\:/ required: true preTransforms: /* function(value: string).<any> */ postTransforms: /* function(value: any).<any> */ validators: value !== 'mongodb://localhost/test' ; conf; // get config valueconf; // get JSON version of config
String-defined type
nodeEnv:type: 'string'allowed: 'development' 'test' 'production'default: 'development';
Object-defined type
nodeEnv:type:name: 'string'allowed: 'development' 'test' 'production'default: 'development';
Available types:
- Boolean
- no options
- Float
- min: number - minimal value for field
- max: number - maximum value for field
- precision: number - count of number after dot
- Int
- min: number - minimal value for field
- max: number - maximum value for field
- IpAddress
- version: number (4|6) - IP address standard version
- Number
- min: number - minimal value for field
- max: number - maximum value for field
- String
- minLength: number - mininal length of string
- maxLength: number - maximum length of string
- allowed: Array.<(string|RegExp)> - allowed values of this field
Roadmap
- Add a typification by string
- Add a typification by object with options and name
- Increase the percentage of code coverage
- Fix incorrect throwing invalid values
- Add typescript definitions
- Migrate tests to Ava