diff --git a/src/index.js b/src/index.js index ebace82..b6b0e2f 100644 --- a/src/index.js +++ b/src/index.js @@ -38,7 +38,15 @@ function makeValidator(validatorName, validatorFunc) { if((validatorFunc.hasChildValidators == 'array' && Array.isArray(arg)) || (typeof arg === validatorFunc.hasChildValidators)) { if(Object.keys(arg).every(function(k) { - return arg[k].hasOwnProperty('$validators'); + let t = arg[k]; + let _v = t ? validators[t.name] : null; + if(_v) { + let v = _v(); + t = v; + arg[k] = v; + return true; + } + return t.hasOwnProperty('$validators'); })) { childValidators = arg; continue; diff --git a/test-src/validator.js b/test-src/validator.js index 8035427..5314838 100644 --- a/test-src/validator.js +++ b/test-src/validator.js @@ -496,4 +496,28 @@ describe("Validator", function() { }); + describe("Primitives", function() { + + it("should allow passing primitives as object key values", function() { + + let schema = s.Object({ + bool: Boolean, + string: String, + num: Number + }); + + schema.validate({ + bool: true, + string: "hello world", + num: 5 + }); + + assert.equal(schema.$validators.bool.$name, 'FastBoolean'); + assert.equal(schema.$validators.string.$name, 'FastString'); + assert.equal(schema.$validators.num.$name, 'FastNumber'); + + }); + + }); + }); \ No newline at end of file