Attention: this is beta version. Use it in production with caution.
NodeJS module for strictly configuration from environment variables.
import TwConf from 'twconf';
const conf = new TwConf({
'database.mongodb.uri': {
comment: 'MongoDB connection URI',
simple: 'mongodb://localhost/test1',
type: new TwConf.Types.StringType({ allowed: [ /mongodb\:/ ] }),
required: true,
preTransforms: [ /* function(value: string).<any> */ ],
postTransforms: [ /* function(value: any).<any> */ ],
validators: [
value => value !== 'mongodb://localhost/test',
],
},
});
conf.get('database.mongodb.hostname'); // get config value
conf.toString(); // get JSON version of config
new TwConf({
nodeEnv: {
type: 'string',
allowed: ['development', 'test', 'production'],
default: 'development',
},
});
new TwConf({
nodeEnv: {
type: {
name: 'string',
allowed: ['development', 'test', 'production'],
},
default: 'development',
},
});
- 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
- 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