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

convict

Package Overview
Dependencies
Maintainers
3
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.2.1 to 0.2.2

27

lib/convict.js

@@ -49,3 +49,3 @@ /*

var coerceTypes = {};
var converters = {};

@@ -243,4 +243,4 @@ function validate (instance, schema, errors) {

if (typeof v === 'string') {
if (coerceTypes.hasOwnProperty(format)) {
return coerceTypes[format](v);
if (converters.hasOwnProperty(format)) {
return converters[format](v);
}

@@ -385,5 +385,10 @@ switch (format) {

// Add a type with a validatino function
// A coerce function is optional
convict.addType = function(name, validator, coerce) {
if (typeof validator !== 'function') {
// A converter function is optional
convict.addFormat = function(name, validate, coerce) {
if (typeof name === 'object') {
name = name.name;
validate = name.validate;
coerce = name.coerce;
}
if (typeof validate !== 'function') {
throw new Error('Validation function for ' + name + ' must be a function.');

@@ -394,9 +399,9 @@ }

}
types[name] = validator;
if (coerce) coerceTypes[name] = coerce;
types[name] = validate;
if (coerce) converters[name] = coerce;
};
convict.addTypes = function(newTypes) {
Object.keys(newTypes).forEach(function(type) {
convict.addType(type, newTypes[type].validate, newTypes[type].coerce);
convict.addFormats = function(formats) {
Object.keys(formats).forEach(function(type) {
convict.addFormat(type, formats[type].validate, formats[type].coerce);
});

@@ -403,0 +408,0 @@ };

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

"description": "Unruly configuration management for nodejs",
"version": "0.2.1",
"version": "0.2.2",
"homepage": "https://github.com/lloyd/node-convict",

@@ -8,0 +8,0 @@ "repository": {

@@ -9,3 +9,3 @@ const should = require('should');

it('should parse a config specification', function() {
convict.addTypes({
convict.addFormats({
prime: {

@@ -12,0 +12,0 @@ validate: function(val) {

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