Skip to content
Browse files

Fix boilerplate

  • Loading branch information...
1 parent fdb5d48 commit f664d58f8db331f2c99de5413c305bb53f1bdbe5 @kriszyp committed
Showing with 22 additions and 19 deletions.
  1. +7 −3 lib/extend-error.js
  2. +15 −16 lib/json-schema.js
View
10 lib/extend-error.js
@@ -1,5 +1,7 @@
-// Creates a custom error that extends JS's Error
-exports.ErrorConstructor = function(name, superError){
+({define:typeof define!="undefined"?define:function(factory){module.exports=factory(require)}}).
+define(function(require){
+ // Creates a custom error that extends JS's Error
+function ErrorConstructor(name, superError){
superError = superError || Error;
function ExtendedError(message){
var e = new Error(message);
@@ -13,4 +15,6 @@ exports.ErrorConstructor = function(name, superError){
ExtendedError.prototype = Object.create(superError.prototype);
ExtendedError.prototype.name = name;
return ExtendedError;
-};
+};
+return ErrorConstructor.ErrorConstructor = ErrorConstructor;
+});
View
31 lib/json-schema.js
@@ -1,19 +1,9 @@
/**
- * JSONSchema Validator - Validates JavaScript objects using JSON Schemas
- * (http://www.json.com/json-schema-proposal/)
- *
- * Copyright (c) 2007 Kris Zyp SitePen (www.sitepen.com)
- * Licensed under the MIT (MIT-LICENSE.txt) license.
-To use the validator call JSONSchema.validate with an instance object and an optional schema object.
-If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
-that schema will be used to validate and the schema parameter is not necessary (if both exist,
-both validations will occur).
-The validate method will return an array of validation errors. If there are no errors, then an
-empty list will be returned. A validation error will have two properties:
-"property" which indicates which property had the error
-"message" which indicates what the error was
+The current recommended version of this validator has moved to http://github.com/kriszyp/json-schema
*/
-
+({define:typeof define!="undefined"?define:function(deps, factory){module.exports = factory()}}).
+define([], function(){
+var exports = validate;
// setup primitive classes to be JSON Schema types
String.type = "string";
Boolean.type = "boolean";
@@ -23,7 +13,8 @@ Object.type = "object";
Array.type = "array";
Date.type = "date";
-exports.validate = function(/*Any*/instance,/*Object*/schema) {
+exports.validate = validate;
+function validate(/*Any*/instance,/*Object*/schema) {
// Summary:
// To use the validator call JSONSchema.validate with an instance object and an optional schema object.
// If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
@@ -192,6 +183,9 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*B
if(value === undefined && propDef["default"]){
value = instance[i] = propDef["default"];
}
+ if(exports.coerce){
+ value = instance[i] = exports.coerce(value, propDef);
+ }
checkProp(value,propDef,path,i);
}
}
@@ -207,6 +201,9 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*B
}
value = instance[i];
if(additionalProp && (!(objTypeDef && typeof objTypeDef == 'object') || !(i in objTypeDef))){
+ if(exports.coerce){
+ value = instance[i] = exports.coerce(value, additionalProp);
+ }
checkProp(value,additionalProp,path,i);
}
if(!_changing && value && value.$schema){
@@ -277,4 +274,6 @@ exports.substitute = function(linkTemplate, instance){
}
return value;
});
-};
+};
+return exports;
+});

0 comments on commit f664d58

Please sign in to comment.
Something went wrong with that request. Please try again.