Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

convict

Package Overview
Dependencies
Maintainers
9
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 4.4.0 to 4.4.1

10

CHANGELOG.md

@@ -8,2 +8,12 @@ # Change Log

## [4.4.1] - 2018-12-15
### Fixed
- Fix README for addFormats #268, #275 (Walter Rumsby @wrumsby, Sebastian Yandun
@svyandun, Eray Hanoglu @erayhanoglu, Marc-Aurèle Darche @madarche)
### Changed
- Update deps (yargs-parser, validator) (Marc-Aurèle Darche @madarche)
## [4.4.0] - 2018-09-22

@@ -10,0 +20,0 @@ ### Fixed

6

package.json

@@ -13,3 +13,3 @@ {

],
"version": "4.4.0",
"version": "4.4.1",
"license": "Apache-2.0",

@@ -48,4 +48,4 @@ "homepage": "https://github.com/mozilla/node-convict",

"moment": "2.22.2",
"validator": "10.4.0",
"yargs-parser": "10.1.0"
"validator": "10.8.0",
"yargs-parser": "11.0.0"
},

@@ -52,0 +52,0 @@ "devDependencies": {

@@ -317,10 +317,52 @@ # Node-convict

### convict.addFormat(format)
### convict.addFormat(format) or convict.addFormat(name, validate, coerce)
Adds a new custom format.
Adds a new custom format, `format` being an object, see example below.
### config.addFormats(formatArray)
```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);
}
});
```
Adds new custom formats.
### convict.addFormats(formats)
Adds new custom formats, `formats` being an object whose keys are the new custom
format names, see example below.
```javascript
convict.addFormats({
prime: {
validate: function(val) {
function isPrime(n) {
if (n <= 1) return false; // zero and one are not prime
for (let i=2; i*i <= n; i++) {
if (n % i === 0) return false;
}
return true;
}
if (!isPrime(val)) throw new Error('must be a prime number');
},
coerce: function(val) {
return parseInt(val, 10);
}
},
'hex-string': {
validate: function(val) {
if (/^[0-9a-fA-F]+$/.test(val)) {
throw new Error('must be a hexidecimal string');
}
}
}
});
```
### config.get(name)

@@ -327,0 +369,0 @@

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