summaryrefslogtreecommitdiff
path: root/app/node_modules/okschema/index.js
diff options
context:
space:
mode:
authorSean Fridman <fridman@mail.sfsu.edu>2015-04-03 02:27:43 -0400
committerSean Fridman <fridman@mail.sfsu.edu>2015-04-03 02:27:43 -0400
commit6fbccc554b2ab51f683718334338eae2b7b06200 (patch)
tree8990bcb4f6afc1a3eb8a742fda0dbbc9763648f5 /app/node_modules/okschema/index.js
parent8c995a7a57e08cabb0da0158aa42ec5ba60b80f5 (diff)
Add OKSchema
Diffstat (limited to 'app/node_modules/okschema/index.js')
-rw-r--r--app/node_modules/okschema/index.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js
new file mode 100644
index 0000000..c601a07
--- /dev/null
+++ b/app/node_modules/okschema/index.js
@@ -0,0 +1,25 @@
+var mschema = require('mschema');
+
+/**
+ * OKSchema!
+ * Meant as a thin wrapper around some existing schema validation
+ * module, mostly to allow for the extension of types.
+ */
+function OKSchema(spec) {
+ if (!(this instanceof OKSchema)) return new OKSchema(spec);
+ if (!spec)
+ throw new Error('No spec provided to OKSchema');
+ this._spec = spec;
+}
+
+OKSchema.prototype.assertValid = function(data) {
+ var result = mschema.validate(data, this._spec);
+ if (!result.valid)
+ throw result.errors;
+};
+
+OKSchema.prototype.getMschema = function() {
+ return this._spec;
+};
+
+module.exports = OKSchema;