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 1.2.0 to 1.3.0

npm-shrinkwrap.json

82

lib/convict.js

@@ -8,3 +8,4 @@ /**

const deprecate = require('depd')('node-convict');
const cjson = require('cjson');
const json5 = require('json5');
const fs = require('fs');
const validator = require('validator');

@@ -64,3 +65,3 @@ const moment = require('moment');

function validate (instance, schema, errors,strictValidation) {
function validate(instance, schema, errors,strictValidation) {
Object.keys(instance).reduce(function(previousErrors, name) {

@@ -92,3 +93,3 @@ var p = schema.properties[name];

// helper for asserting that a value is in the list of valid options
function contains (options, x) {
function contains(options, x) {
assert(validator.isIn(x, options), 'must be one of the possible values: ' +

@@ -106,7 +107,7 @@ JSON.stringify(options));

var BUILT_IN_NAMES = Object.keys(BUILT_INS_BY_NAME);
var BUILT_INS = BUILT_IN_NAMES.map(function (name) {
var BUILT_INS = BUILT_IN_NAMES.map(function(name) {
return BUILT_INS_BY_NAME[name];
});
function normalizeSchema (name, node, props, fullName, env, argv) {
function normalizeSchema(name, node, props, fullName, env, argv) {
// If the current schema node is not a config property (has no "default"), recursively normalize it.

@@ -196,3 +197,3 @@ if (typeof node === 'object' && !Array.isArray(node) && !('default' in node)) {

o._format = function (x) {
o._format = function(x) {
try {

@@ -323,2 +324,11 @@ newFormat(x);

function loadJSON(path) {
// TODO Get rid of the sync call
// eslint-disable-next-line no-sync
return json5.parse(fs.readFileSync(path, 'utf-8'));
}
/**
* @returns a config object
*/
var convict = function convict(def) {

@@ -344,2 +354,5 @@ function walk(obj, path) {

var rv = {
/**
* Exports all the properties (that is the keys and their current values) as JSON
*/
getProperties: function() {

@@ -351,8 +364,21 @@ return JSON.parse(JSON.stringify(this._instance));

}, 'Use "getProperties" method instead'),
/**
* Exports all the properties (that is the keys and their current values) as
* a JSON string
*/
toString: function() {
return JSON.stringify(this._instance, null, 2);
},
/**
* Exports the schema as JSON.
*/
getSchema: function() {
return JSON.parse(JSON.stringify(this._schema));
},
/**
* Exports the schema as a JSON string
*/
getSchemaString: function() {

@@ -364,2 +390,7 @@ return JSON.stringify(this._schema, null, 2);

}, 'Use "getSchemaString" method instead'),
/**
* @returns the current value of the name property. name can use dot
* notation to reference nested values
*/
get: function(path) {

@@ -371,2 +402,7 @@ var o = walk(this._instance, path);

},
/**
* @returns the default value of the name property. name can use dot
* notation to reference nested values
*/
default: function(path) {

@@ -381,2 +417,6 @@ // The default value for FOO.BAR.BAZ is stored in `_schema.properties` at:

},
/**
* @returns true if the property name is defined, or false otherwise
*/
has: function(path) {

@@ -391,2 +431,8 @@ try {

},
/**
* Sets the value of name to value. name can use dot notation to reference
* nested values, e.g. "database.port". If objects in the chain don't yet
* exist, they will be initialized to empty objects
*/
set: function(k, v) {

@@ -405,2 +451,6 @@ v = coerce(k, v, this._schema, this);

},
/**
* Loads and merges a JavaScript object into config
*/
load: function(conf) {

@@ -413,2 +463,6 @@ overlay(conf, this._instance, this._schema);

},
/**
* Loads and merges one or multiple JSON configuration files into config
*/
loadFile: function(paths) {

@@ -418,3 +472,3 @@ var self = this;

paths.forEach(function(path) {
overlay(cjson.load(path), self._instance, self._schema);
overlay(loadJSON(path), self._instance, self._schema);
});

@@ -426,2 +480,6 @@ // environment and arguments always overrides config files

},
/**
* Validates config against the schema used to initialize it
*/
validate: function(options) {

@@ -458,3 +516,3 @@ options = options || {};

if (typeof def === 'string') {
rv._def = cjson.load(def);
rv._def = loadJSON(def);
} else {

@@ -484,4 +542,5 @@ rv._def = def;

// Add a type with a validatino function
// A converter function is optional
/**
* Adds a new custom format
*/
convict.addFormat = function(name, validate, coerce) {

@@ -503,2 +562,5 @@ if (typeof name === 'object') {

/**
* Adds new custom formats
*/
convict.addFormats = function(formats) {

@@ -505,0 +567,0 @@ Object.keys(formats).forEach(function(type) {

9

package.json

@@ -12,3 +12,3 @@ {

],
"version": "1.2.0",
"version": "1.3.0",
"license": "Apache-2.0",

@@ -34,3 +34,3 @@ "homepage": "https://github.com/mozilla/node-convict",

"clean": "rm -rf test/coverage",
"safefreeze": "rm -rf node_modules npm-shrinkwrap.json && npm install && npm dedupe && npm test && npm shrinkwrap && touch package.json npm-shrinkwrap.json",
"safefreeze": "rm -rf node_modules npm-shrinkwrap.json && npm install --production --registry https://registry.npmjs.org/ && npm dedupe && npm shrinkwrap && npm install && npm test && touch package.json npm-shrinkwrap.json",
"preversion": "./assert_shrinkwrap_ready",

@@ -40,8 +40,9 @@ "version": "./assert_changelog_ready $npm_package_version"

"files": [
"lib"
"lib",
"npm-shrinkwrap.json"
],
"main": "lib/convict.js",
"dependencies": {
"cjson": "0.3.3",
"depd": "1.1.0",
"json5": "0.5.0",
"moment": "2.12.0",

@@ -48,0 +49,0 @@ "optimist": "0.6.1",

@@ -24,4 +24,5 @@ # Node-convict

all errors that are found
* **Comments allowed**: JSON files are loaded with the `cjson` module, so
comments are welcome
* **Comments allowed**: Configuration and schema files can be either be in the
JSON format or in the newer [JSON5](https://www.npmjs.com/package/json5)
format, so comments are welcome

@@ -284,3 +285,5 @@

`convict()` takes a schema object and returns a convict configuration object. The configuration object has an API for getting and setting values, described below.
`convict()` takes a schema object or a path to a schema file and returns a
convict configuration object. The configuration object has an API for getting
and setting values, described below.

@@ -329,3 +332,3 @@ ### config.addFormat(format)

This will load and merge a JavaScript object into `config`. E.g.:
Loads and merges a JavaScript object into `config`. E.g.:
```javascript

@@ -340,3 +343,3 @@ config.load({

This will load and merge one or multiple JSON configuration files into `config`. JSON files are loaded using `cjson`, so they can contain comments. E.g.:
Loads and merges one or multiple JSON configuration files into `config`. JSON files are loaded using `cjson`, so they can contain comments. E.g.:
```javascript

@@ -343,0 +346,0 @@ conf.loadFile('./config/' + conf.get('env') + '.json');

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