blueconfig-format-with-validator
v6.2.2
Published
Format 'email', 'ipaddress' and 'url' for blueconfig
Downloads
4
Maintainers
Readme
Blueconfig-format-with-validator
Format 'email', 'ipaddress' and 'url' for blueconfig with validatorjs.
Install
npm install blueconfig-format-with-validator
Usage
An example config.js
file:
const blueconfig = require('blueconfig');
blueconfig.addFormats([
require('blueconfig-format-with-validator').email,
require('blueconfig-format-with-validator').ipaddress,
require('blueconfig-format-with-validator').url
]);
// or :
// blueconfig.addFormats(require('blueconfig-format-with-validator'));
// Define a schema
var config = blueconfig({
ip: {
doc: 'The IP address to bind',
format: 'ipaddress',
default: '127.0.0.1',
env: 'IP_ADDRESS',
},
port: {
doc: 'The port to bind',
format: 'port',
default: 8080,
env: 'PORT',
arg: 'port'
},
email: {
doc: 'Server mail',
format: 'email',
default: '[email protected]'
},
url: {
doc: 'Server url',
format: 'url',
default: 'http://example.com'
}
});
Validation
This package uses validator.js to validate:
email
ipaddress
- IPv4 and IPv6 addressesurl
Coercion
Blueconfig will automatically coerce strings variables to their proper types when importing them.