-
Notifications
You must be signed in to change notification settings - Fork 0
/
jassi.min.js
1 lines (1 loc) · 4.17 KB
/
jassi.min.js
1
/*! Jassi v0.1.2 */!function(a,b){"use strict";function c(a){return null!==a&&"object"==typeof a&&!g(a)}function d(a){return c(a)&&"object"||g(a)&&"array"||null===a&&"null"||typeof a}function e(a,b){var c,f,g,i,j,k=d(a),l=d(b);if(k!=l)return!1;if("array"==k){if(a.length!==b.length)return!1;for(c=0,f=a.length;f>c;c++)if(!e(a[c],b[c]))return!1;return!0}if("object"==k){if(g=h(a),i=h(b),g.length!==i.length)return!1;for(c=0,f=g.length;f>c;c++)if(j=g[c],!b.hasOwnProperty(j)||!e(a[j],b[j]))return!1;return!0}return a===b}function f(a,c){return b!==a?a:c}var g=Array.isArray,h=Object.keys,i=function(a,j,k){function l(a){return y.push({property:k,message:a}),y}var m,n,o,p,q,r,s,t,u,v,w,x,y=[];if(b===k&&(k=""),!c(j))return l("Invalid schema.");if(m=d(a),j.type&&(q=g(j.type)?j.type:[j.type],~q.indexOf(m)||"number"==m&&~q.indexOf("integer")&&a%1==0||l("Invalid type. Was expecting "+j.type+" but found "+m+".")),"array"==m){if(n=a.length,j.items||j.additionalItems)if(q=j.items||{},r=g(j.items),s=j.additionalItems,t=c(j.additionalItems),r&&!1===s&&n>(p=q.length))l("The instance can only have up to "+p+" items.");else for(o=0;n>o;o++)y=y.concat(i(a[o],r?q[o]||t&&s||{}:q,k+"["+o+"]"));if(j.maxItems&&n>j.maxItems&&l("There must be a maximum of "+j.maxItems+" item(s) in the array."),j.minItems&&n<j.minItems&&l("There must be a minimum of "+j.minItems+" item(s) in the array."),j.uniqueItems)a:for(o=0;n>o;o++)for(p=o+1;n>p;p++)if(e(a[o],a[p])){l("The items in the array must be unique.");break a}}if("object"==m&&(j.maxProperties&&h(a).length>j.maxProperties&&l("The instance must have at most "+j.maxProperties+" members."),j.minProperties&&h(a).length<j.minProperties&&l("The instance must have at least "+j.minProperties+" members."),j.required&&j.required.forEach(function(b){a.hasOwnProperty(b)||l('Required property "'+b+'" is missing.')}),(j.properties||j.additionalProperties||j.patternProperties)&&(v=f(j.properties,{}),w=f(j.patternProperties,{}),s=f(j.additionalProperties,{}),x=h(w)),h(a).forEach(function(b){var c,d;j.dependencies&&(d=j.dependencies[b])&&(g(d)?d.forEach(function(c){a.hasOwnProperty(c)||l('Property "'+b+'" requires "'+c+'" to also be present.')}):y=y.concat(i(a,d,k))),!v||!1!==s||v.hasOwnProperty(b)||x&&x.some(function(a){return b.match(a)})?(c=[],v&&v.hasOwnProperty(b)&&c.push(v[b]),x&&x.forEach(function(a){b.match(a)&&w[a]&&c.push(w[a])}),!c.length&&s&&c.push(s),c.forEach(function(c){y=y.concat(i(a[b],c,k?k+"."+b:b))})):l('The key "'+b+'" is not allowed to be set.')})),"string"==m&&(j.maxLength&&a.length>j.maxLength&&l("The instance must not be more than "+j.maxLength+" character(s) long."),j.minLength&&a.length<j.minLength&&l("The instance must be at least "+j.minLength+" character(s) long."),j.pattern&&!a.match(j.pattern)&&l("Regex pattern /"+j.pattern+"/ is a mismatch.")),"number"==m&&(j.multipleOf!==b&&a/j.multipleOf%1!=0&&l("The instance is required to be a multiple of "+j.multipleOf+"."),j.maximum!==b&&(!j.exclusiveMaximum&&j.maximum<a&&l("The instance must have a maximum value of "+j.maximum+"."),j.exclusiveMaximum&&j.maximum<=a&&l("The instance must be lower than "+j.maximum+".")),j.minimum!==b&&(!j.exclusiveMinimum&&j.minimum>a&&l("The instance must have a minimum value of "+j.minimum+"."),j.exclusiveMinimum&&j.minimum>=a&&l("The instance must be greater than "+j.minimum+"."))),j["enum"]){for(q=j["enum"],n=q.length,o=0,u=0;n>o&&!u;o++)e(q[o],a)&&(u=1);u||l("The instance must have one of the following values: "+q.join(", ")+".")}if(j.allOf&&j.allOf.forEach(function(b){y=y.concat(i(a,b,k))}),j.anyOf){for(q=j.anyOf,n=q.length,o=0,u=0;n>o&&!u;o++)i(a,q[o],k).length||(u=1);u||l('The instance must validate against at least one schema defined by the "anyOf" keyword.')}if(j.oneOf){for(q=j.oneOf,n=q.length,o=0,u=0;n>o;o++)if(!i(a,q[o],k).length){if(u){l('The instance must validate against exactly one schema defined by the "oneOf" keyword.');break}u=1}u||l('The instance must validate against one schema defined by the "oneOf" keyword.')}return j.not&&!i(a,j.not,k).length&&l('The instance must not validate against the schema defined by the "not" keyword.'),y};"undefined"!=typeof module&&module.exports?module.exports=i:"function"==typeof define&&define.amd?define(function(){return i}):a.jassi=i}(this);