Permalink
Browse files

Enable return of parsed RegExp objects

  • Loading branch information...
1 parent 1bd4b5a commit dce2cc41d23e6ee8c3430efd10c2874ae48fe043 @philbooth philbooth committed Sep 23, 2016
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/convict.js
View
@@ -243,6 +243,7 @@ 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) {
@@ -351,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 JSON.parse(JSON.stringify(this._instance));
+ return this._instance;
},
root: deprecate.function(function() {
return this.getProperties();
@@ -388,6 +389,7 @@ 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)) :
void 0;
@@ -402,6 +404,7 @@ 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)) :
void 0;

0 comments on commit dce2cc4

Please sign in to comment.