From 6fbccc554b2ab51f683718334338eae2b7b06200 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Fri, 3 Apr 2015 02:27:43 -0400 Subject: Add OKSchema --- app/node_modules/okschema/index.js | 25 +++++++++++++++++++++++++ app/node_modules/okschema/package.json | 14 ++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 app/node_modules/okschema/index.js create mode 100644 app/node_modules/okschema/package.json (limited to 'app/node_modules') 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; diff --git a/app/node_modules/okschema/package.json b/app/node_modules/okschema/package.json new file mode 100644 index 0000000..795f057 --- /dev/null +++ b/app/node_modules/okschema/package.json @@ -0,0 +1,14 @@ +{ + "name": "okschema", + "version": "1.0.0", + "description": "schemin", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "OKFocus", + "license": "None", + "dependencies": { + "mschema": "^0.5.5" + } +} -- cgit v1.2.3-70-g09d2