Socket
Socket
Sign inDemoInstall

convict

Package Overview
Dependencies
Maintainers
7
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convict - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1

17

lib/convict.js

@@ -321,11 +321,20 @@ /**

var rv = {
getProperties: function() {
return JSON.parse(JSON.stringify(this._instance));
},
root: deprecate.function(function() {
return this.getProperties();
}, "Use \"getProperties\" method instead"),
toString: function() {
return JSON.stringify(this._instance, null, 2);
},
toSchemaString: function() {
getSchema: function() {
return JSON.parse(JSON.stringify(this._schema));
},
getSchemaString: function() {
return JSON.stringify(this._schema, null, 2);
},
root: function() {
return JSON.parse(JSON.stringify(this._instance));
},
toSchemaString: deprecate.function(function() {
return this.getSchemaString();
}, "Use \"getSchemaString\" method instead"),
get: function(path) {

@@ -332,0 +341,0 @@ var o = walk(this._instance, path);

@@ -5,3 +5,3 @@ {

"description": "Unruly configuration management for nodejs",
"version": "0.8.0",
"version": "0.8.1",
"homepage": "https://github.com/mozilla/node-convict",

@@ -17,16 +17,17 @@ "repository": {

"dependencies": {
"cjson": "0.3.0",
"depd": "1.0.0",
"moment": "2.9.0",
"cjson": "0.3.1",
"depd": "1.0.1",
"moment": "2.10.3",
"optimist": "0.6.1",
"validator": "3.33.0",
"validator": "3.40.0",
"varify": "0.1.1"
},
"devDependencies": {
"istanbul": "0.3.6",
"jshint": "2.6.3",
"mocha": "2.1.0",
"blanket": "1.1.7",
"coveralls": "2.11.2",
"jshint": "2.8.0",
"mocha": "2.2.5",
"mocha-lcov-reporter": "0.0.2",
"must": "0.12.0",
"obj_diff": "0.3.0",
"blanket": "1.1.6"
"obj_diff": "0.3.0"
},

@@ -43,4 +44,5 @@ "jshintConfig": {

"test": "jshint *.json lib/*.js test/*.js test/cases/*.js test/cases/*.json && mocha --check-leaks -R spec",
"test-cov": "mocha --require blanket -R html-cov > test/coverage.html",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
"test-coverage": "jshint *.json lib/*.js test/*.js && mocha --check-leaks --require blanket -R html-cov > test/coverage.html",
"test-travis": "jshint *.json lib/*.js test/*.js && mocha --check-leaks --require blanket -R mocha-lcov-reporter | coveralls",
"clean": "rm -rf test/coverage.html"
},

@@ -53,6 +55,3 @@ "config": {

"bugs": "https://github.com/mozilla/node-convict/issues",
"licenses": {
"type": "Apache",
"url": "https://raw.github.com/mozilla/node-convict/master/LICENSE"
},
"license": "Apache-2.0",
"browserify": {

@@ -59,0 +58,0 @@ "transform": [

@@ -83,2 +83,3 @@ # Node-convict

## The Schema
A configuration module could look like this:

@@ -109,2 +110,36 @@

Nested configuration settings are also supported:
```javascript
var config = convict({
server: {
ip: {
doc: "IP address to bind",
format: 'ipaddress',
default: '0.0.0.0'
},
port: {
doc: "port to bind",
format: 'port',
default: 8080
}
},
database: {
host: {
doc: "Database host name/IP",
format: String,
default: 'testing'
},
name: {
doc: "Database name",
format: String,
default: 'users'
}
}
});
```
Note: Search for the word "nested" throughout this documentation to find out
more about nested configuration settings.
### Validation

@@ -128,14 +163,38 @@ In order to help detect misconfigurations, convict allows you to define a format for each setting. By default, convict checks if the value of the property has the same type (according to `Object.prototype.toString.call`) as the default value specified in the schema. You can define a custom format checking function in the schema by setting the `format` property.

You can also provide your own format checking function. For example:
```javascript
var check = require('validator').check;
var conf = convict({
key: {
doc: "API key",
format: function check (val) {
if (!/^[a-fA-F0-9]{64}$/.test(val)) {
throw new Error('must be a 64 character hex key')
}
},
default: '3cec609c9bc601c047af917a544645c50caf8cd606806b4e0a23312441014deb'
}
});
```
Or, you can use `convict.addFormat()` to predefine your own validation:
```javascript
convict.addFormat({
name: 'float-percent',
validate: function(val) {
if (val !== 0 && (!val || val > 1 || val < 0)) {
throw new Error('must be a float between 0 and 1, inclusive');
}
},
coerce: function(val) {
return parseFloat(val, 10);
}
});
var conf = convict({
key: {
doc: "API key",
format: function (val) {
check(val, 'should be a 64 character hex key').regex(/^[a-fA-F0-9]{64}$/);
},
default: '3cec609c9bc601c047af917a544645c50caf8cd606806b4e0a23312441014deb'
}
});
percentNumber: {
format: 'float-percent',
default: 0.5
}
});
```

@@ -206,6 +265,28 @@

### config.validate()
### config.validate([{strict: true}])
Validates `config` against the schema used to initialize it. All errors are collected and thrown at once.
If the `{strict: true}` option is passed, any properties specified in config
files that are not declared in the schema will result in errors. This is to
ensure that the schema and the config files are in sync. By default the strict
mode is set to false.
### config.getProperties()
Exports all the properties (that is the keys and their current values) as JSON.
### config.toString()
Exports all the properties (that is the keys and their current values) as a
JSON string.
### config.getSchema()
Exports the schema as JSON.
### config.getSchemaString()
Exports the schema as a JSON string.
## faq

@@ -212,0 +293,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc