diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-04-08 23:04:56 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-04-08 23:04:56 -0400 |
| commit | bae6a32b83209846b2a6a757c0c414d537c157b2 (patch) | |
| tree | fc905624ccb53b853d54946ac8cc4b7ce8415a7c /app/node_modules/okschema | |
| parent | 3943bbc8346d4ff58f725db2e5e4de9622d89fab (diff) | |
adding enum validation
Diffstat (limited to 'app/node_modules/okschema')
| -rw-r--r-- | app/node_modules/okschema/index.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index 51783a1..0829807 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -19,7 +19,15 @@ var types = { 'text': { parent: {type: 'string'}, // Let parent handle validation - assertValid: function(s) {} + assertValid: function(spec, value) {} + }, + 'enum': { + parent: {type: 'string'}, + assertValid: function(spec, value) { + if (~spec.options.indexOf(value)) { + throw [] + } + } } } @@ -59,7 +67,7 @@ OKSchema.prototype.assertValid = function(data) { Object.keys(data).forEach(function(prop) { var type = spec[prop].type; if (types[type]) { - types[type].assertValid(data[prop]); + types[type].assertValid(spec[prop], data[prop]); } }); var result = mschema.validate(data, this.toMschema()); |
