diff options
Diffstat (limited to 'app/node_modules/okschema/index.js')
| -rw-r--r-- | app/node_modules/okschema/index.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index d53ed7b..c5a56c4 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -68,6 +68,9 @@ var types = { * OKSchema! * Meant as a thin wrapper around some existing schema validation * module, mostly to allow for the extension of types. + * + * NOTE: Currently just assumes spec is valid. If you give a bad spec + * strange things may or may not happen */ function OKSchema(spec) { if (!(this instanceof OKSchema)) return new OKSchema(spec); @@ -138,11 +141,18 @@ OKSchema.prototype.assertValid = function(data) { var type = spec[prop].type; if (types[type]) { types[type].assertValid(spec[prop], data[prop]); + // Also check if it's a number type and try to cast it + // otherwise pass and let mschema handle + } else if (type === 'number') { + try { + data[prop] = parseFloat(data[prop]); + } catch (err) {} } }); var result = mschema.validate(data, this.toMschema()); - if (!result.valid) + if (!result.valid) { throw result.errors; + } }; /** |
