Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Always return cloned data
- Loading branch information
Showing
with
10 additions
and
6 deletions.
-
+4
−6
lib/convict.js
-
+5
−0
npm-shrinkwrap.json
-
+1
−0
package.json
|
@@ -10,6 +10,7 @@ const fs = require('fs'); |
|
|
const validator = require('validator'); |
|
|
const moment = require('moment'); |
|
|
const minimist = require('minimist'); |
|
|
const cloneDeep = require('lodash/cloneDeep'); |
|
|
|
|
|
function assert(assertion, err_msg) { |
|
|
if (!assertion) { |
|
@@ -243,7 +244,6 @@ function addDefaultValues(schema, c, instance) { |
|
|
} |
|
|
|
|
|
function isObj(o) { return (typeof o === 'object' && o !== null); } |
|
|
function isRegExp(r) { return Object.prototype.toString.call(r) === '[object RegExp]'; } |
|
|
|
|
|
function overlay(from, to, schema) { |
|
|
Object.keys(from).forEach(function(k) { |
|
@@ -352,7 +352,7 @@ var convict = function convict(def) { |
|
|
* Exports all the properties (that is the keys and their current values) as JSON |
|
|
*/ |
|
|
getProperties: function() { |
|
|
return this._instance; |
|
|
return cloneDeep(this._instance); |
|
|
}, |
|
|
root: deprecate.function(function() { |
|
|
return this.getProperties(); |
|
@@ -389,9 +389,8 @@ var convict = function convict(def) { |
|
|
*/ |
|
|
get: function(path) { |
|
|
var o = walk(this._instance, path); |
|
|
if (isRegExp(o)) return o; |
|
|
return typeof o !== 'undefined' ? |
|
|
JSON.parse(JSON.stringify(o)) : |
|
|
cloneDeep(o) : |
|
|
void 0; |
|
|
}, |
|
|
|
|
@@ -404,9 +403,8 @@ var convict = function convict(def) { |
|
|
// FOO.properties.BAR.properties.BAZ.default |
|
|
path = (path.split('.').join('.properties.')) + '.default'; |
|
|
var o = walk(this._schema.properties, path); |
|
|
if (isRegExp(o)) return o; |
|
|
return typeof o !== 'undefined' ? |
|
|
JSON.parse(JSON.stringify(o)) : |
|
|
cloneDeep(o) : |
|
|
void 0; |
|
|
}, |
|
|
|
|
|
Some generated files are not rendered by default. Learn more.
Oops, something went wrong.
|
@@ -43,6 +43,7 @@ |
|
|
"dependencies": { |
|
|
"depd": "1.1.0", |
|
|
"json5": "0.5.0", |
|
|
"lodash": "4.16.2", |
|
|
"minimist": "1.2.0", |
|
|
"moment": "2.12.0", |
|
|
"validator": "4.6.1" |
|
|