File tree 2 files changed +27
-3
lines changed
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -484,10 +484,10 @@ const convict = function convict(def, opts) {
484
484
485
485
/**
486
486
* Exports all the properties (that is the keys and their current values) as
487
- * a JSON string , with sensitive values masked. Sensitive values are masked
487
+ * a JSON object , with sensitive values masked. Sensitive values are masked
488
488
* even if they aren't set, to avoid revealing any information.
489
489
*/
490
- toString : function ( ) {
490
+ toJson : function ( ) {
491
491
const clone = cloneDeep ( this . _instance )
492
492
this . _sensitive . forEach ( function ( key ) {
493
493
const path = key . split ( '.' )
@@ -496,7 +496,16 @@ const convict = function convict(def, opts) {
496
496
const parent = walk ( clone , parentKey )
497
497
parent [ childKey ] = '[Sensitive]'
498
498
} )
499
- return JSON . stringify ( clone , null , 2 )
499
+ return clone
500
+ } ,
501
+
502
+ /**
503
+ * Exports all the properties (that is the keys and their current values) as
504
+ * a JSON string, with sensitive values masked. Sensitive values are masked
505
+ * even if they aren't set, to avoid revealing any information.
506
+ */
507
+ toString : function ( ) {
508
+ return JSON . stringify ( this . toJson ( ) , null , 2 )
500
509
} ,
501
510
502
511
/**
Original file line number Diff line number Diff line change @@ -102,6 +102,21 @@ describe('convict schema', function() {
102
102
} , null , 2 ) )
103
103
} )
104
104
105
+ test ( 'must export all its properties as a json object' , function ( ) {
106
+ const res = conf . toJson ( )
107
+ expect ( res ) . toEqual ( {
108
+ foo : {
109
+ bar : 7 ,
110
+ baz : {
111
+ bing : 'foo' ,
112
+ 'name with spaces' : {
113
+ name_with_underscores : true
114
+ }
115
+ }
116
+ }
117
+ } )
118
+ } )
119
+
105
120
test ( 'must throw if `_cvtProperties` (reserved keyword) is used' , function ( ) {
106
121
expect ( function ( ) {
107
122
conf = convict ( {
You can’t perform that action at this time.
0 commit comments