Comparing version 0.5.3 to 0.5.4
34
index.js
@@ -18,5 +18,13 @@ var mschema = {}; | ||
return true; | ||
}, | ||
"file": function (val) { | ||
// TODO: add binary file detection | ||
return true; | ||
} | ||
}; | ||
mschema.define = function (_schema) { | ||
return new Schema(_schema); | ||
}; | ||
var validate = mschema.validate = function (_data, _schema, options) { | ||
@@ -111,4 +119,10 @@ | ||
if (typeof property.regex === 'object') { | ||
var re = property.regex | ||
var result = re.exec(value); | ||
var re = property.regex, | ||
result; | ||
if (property.required === false && value.length === 0) { | ||
return; | ||
} | ||
result = re.exec(value); | ||
if (result === null) { | ||
@@ -253,3 +267,2 @@ errors.push({ | ||
// create a clone of the schema so the original schema passed is not modifed by _parse() | ||
@@ -259,4 +272,4 @@ var schemaCopy = {}; | ||
// if the incoming data is not an object, create a single key object to represent it | ||
if (typeof _data !== "object") { | ||
// if the incoming data is not an object or function, assume its a single value and create a single keyed object to represent it | ||
if (typeof _data !== "object" && typeof _data !== 'function') { | ||
_data = { | ||
@@ -394,2 +407,13 @@ key: _data | ||
function Schema (_schema) { | ||
if (!(this instanceof Schema)) { | ||
return new Schema(_schema); | ||
} | ||
this._schema = _schema; | ||
} | ||
Schema.prototype.validate = function (_data, options) { | ||
return mschema.validate(_data, this._schema, options); | ||
}; | ||
module['exports'] = mschema; |
{ | ||
"name": "mschema", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"keywords": ["schema", "mschema", "validator", "json", "json-schema"], | ||
@@ -5,0 +5,0 @@ "description": "A schema language for defining the structure of JSON data", |
# mschema | ||
<img src="https://travis-ci.org/mschema/mschema.svg?branch=master"/> | ||
A concise schema language for describing the structure of JSON data | ||
@@ -4,0 +6,0 @@ |
@@ -56,2 +56,22 @@ var tap = require("tap"), | ||
}); | ||
}); | ||
test("mschema.validate - empty value - constrained property - string - regex - required false", function (t) { | ||
var user = { | ||
"name": { | ||
"type": "string", | ||
"regex": /^[\w|\-|\.]+$/, | ||
"required": false | ||
} | ||
}; | ||
var data = { "name": "" }; | ||
var result = mschema.validate(data, user); | ||
t.equal(result.valid, true); | ||
t.ok(result, "data is valid"); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73562
36
2343
213