Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "typology", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A data validation library for Node.js and the browser.", | ||
@@ -5,0 +5,0 @@ "main": "typology.js", |
/** | ||
* typology.js - A data validation library for Node.js and the browser, | ||
* | ||
* Version: 1.1.0 | ||
* Version: 1.2.0 | ||
* Sources: http://github.com/jacomyal/typology | ||
@@ -635,2 +635,6 @@ * Doc: http://github.com/jacomyal/typology#readme | ||
false; | ||
else if (typeOf === 'function') | ||
return true; | ||
else | ||
@@ -679,3 +683,3 @@ return false; | ||
Object.defineProperty(types, 'version', { | ||
value: '1.1.0' | ||
value: '1.2.0' | ||
}); | ||
@@ -682,0 +686,0 @@ |
/** | ||
* typology - A data validation library for Node.js and the browser. | ||
* @version v1.1.0 | ||
* @version v1.2.0 | ||
* @link https://github.com/jacomyal/typology | ||
* @license MIT | ||
*/ | ||
!function(e){"use strict";function t(e){var t=this,i={};if(this.scan=function(e,o){var a,d,u,p,s,c,f,l,h,y,g=!1,v=!1,b=null===o||void 0===o?String(o):r[Object.prototype.toString.call(o)]||"object",x=null===e||void 0===e?String(e):r[Object.prototype.toString.call(e)]||"object";if("string"===x){for(a=e.replace(/^[\?\!]/,"").split(/\|/),u=a.length,d=0;u>d;d++)if(!n[a[d]]&&"undefined"==typeof i[a[d]])throw new Error("Invalid type.");for("?"===e.charAt(0)?g=!0:"!"===e.charAt(0)&&(v=!0),u=a.length,d=0;u>d;d++)if("undefined"!=typeof i[a[d]]&&("function"==typeof i[a[d]].type?i[a[d]].type.call(t,o)===!0:!this.scan(i[a[d]].type,o).error))return v?{error:'Expected a "'+e+'" but found a "'+a[d]+'".',expected:e,type:a[d],value:o}:{expected:e,type:a[d],value:o};return null===o||void 0===o?v||g?{nully:!0,expected:e,type:b,value:o}:{error:'Expected a "'+e+'" but found a "'+b+'".',expected:e,type:b,value:o}:(h=~a.indexOf("*"),y=~a.indexOf(b),v&&(h||y)?{error:'Expected a "'+e+'" but found a "'+(y?b:"*")+'".',expected:e,type:y?b:"*",value:o}:v||h||y?{expected:e,type:b,value:o}:{error:'Expected a "'+e+'" but found a "'+b+'".',expected:e,type:b,value:o})}if("object"===x){if("object"!==b)return{error:'Expected an object but found a "'+b+'".',expected:e,type:b,value:o};for(l=Object.keys(e),u=l.length,c=0,p=0;u>p;p++){if(s=this.scan(e[l[p]],o[l[p]]),s.error)return s.path=s.path?[l[p]].concat(s.path):[l[p]],s;s.nully&&c++}if(f=Object.keys(o),f.length>u-c)for(u=f.length,p=0;u>p;p++)if("undefined"==typeof e[f[p]])return{error:'Unexpected key "'+f[p]+'".',expected:e,type:b,value:o};return{expected:e,type:b,value:o}}if("function"===x){var w={expected:e,type:b,value:o};return e(o)||(w.error="The target did not pass the given test (function)."),w}if("array"===x){if(1!==e.length)throw new Error("Invalid type.");if("array"!==b)return{error:'Expected an array but found a "'+b+'".',expected:e,type:b,value:o};for(u=o.length,d=0;u>d;d++)if(s=this.scan(e[0],o[d]),s.error)return s.path=s.path?[d].concat(s.path):[d],s;return{expected:e,type:b,value:o}}throw new Error("Invalid type.")},this.add=function(e,t){var r,o,a,d,u,p;if(1===arguments.length){if("object"!==this.get(e))throw new Error("If types.add is called with one argument, this one has to be an object.");r=e,d=r.id,p=r.type}else{if(2!==arguments.length)throw new Error("types.add has to be called with one or two arguments.");if("string"!=typeof e||!e)throw new Error("If types.add is called with more than one argument, the first one must be the string id.");d=e,p=t}if("string"!==this.get(d)||0===d.length)throw new Error("A type requires an string id.");if(void 0!==i[d]&&"proto"!==i[d])throw new Error('The type "'+d+'" already exists.');if(n[d])throw new Error('"'+d+'" is a reserved type name.');i[d]=1,a=(r||{}).proto||[],a=Array.isArray(a)?a:[a],u={};for(o in a)void 0===i[a[o]]&&(i[a[o]]=1,u[a[o]]=1);if("function"!==this.get(p)&&!this.isValid(p))throw new Error("A type requires a valid definition. This one can be a preexistant type or else a function testing given objects.");if(i[d]=void 0===r?{id:d,type:p}:{},void 0!==r)for(o in r)i[d][o]=r[o];for(o in u)o!==d&&delete i[o];return this},this.has=function(e){return!!i[e]},this.get=function(e){return null===e||void 0===e?String(e):r[Object.prototype.toString.call(e)]||"object"},this.check=function(e,t){return!this.scan(e,t).error},this.isValid=function(e){var t,o,a,d,u,p,s=null===e||void 0===e?String(e):r[Object.prototype.toString.call(e)]||"object";if("string"===s){for(t=e.replace(/^[\?\!]/,"").split(/\|/),u=Object.keys(t),d=u.length,a=0;d>a;a++)if(!n[t[u[a]]]&&"undefined"==typeof i[t[u[a]]])return!1;return!0}if("object"===s){for(p=Object.keys(e),d=p.length,o=0;d>o;o++)if(!this.isValid(e[p[o]]))return!1;return!0}return"array"===s&&1===e.length?this.isValid(e[0]):!1},this.add("type",function(e){return this.isValid(e)}.bind(this)),this.add("primitive",function(e){return e!==Object(e)}),e=e||{},"object"!==this.get(e))throw Error("Invalid argument.");for(var o in e)this.add(o,e[o])}var r={},n={"*":!0};!function(){var e,t,i=["Boolean","Number","String","Object","Array","Function","Arguments","RegExp","Date","Map","Set","WeakMap","WeakSet","Symbol"];for(e in i)t=i[e],n[t.toLowerCase()]=!0,r["[object "+t+"]"]=t.toLowerCase()}();var i=t;t.call(i),Object.defineProperty(i,"version",{value:"1.1.0"}),"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.types=i):"function"==typeof define&&define.amd?define("typology",[],function(){return i}):e.types=i}(this); | ||
!function(e){"use strict";function t(e){var t=this,i={};if(this.scan=function(e,o){var a,u,d,p,c,s,f,l,h,y,g=!1,v=!1,b=null===o||void 0===o?String(o):r[Object.prototype.toString.call(o)]||"object",x=null===e||void 0===e?String(e):r[Object.prototype.toString.call(e)]||"object";if("string"===x){for(a=e.replace(/^[\?\!]/,"").split(/\|/),d=a.length,u=0;d>u;u++)if(!n[a[u]]&&"undefined"==typeof i[a[u]])throw new Error("Invalid type.");for("?"===e.charAt(0)?g=!0:"!"===e.charAt(0)&&(v=!0),d=a.length,u=0;d>u;u++)if("undefined"!=typeof i[a[u]]&&("function"==typeof i[a[u]].type?i[a[u]].type.call(t,o)===!0:!this.scan(i[a[u]].type,o).error))return v?{error:'Expected a "'+e+'" but found a "'+a[u]+'".',expected:e,type:a[u],value:o}:{expected:e,type:a[u],value:o};return null===o||void 0===o?v||g?{nully:!0,expected:e,type:b,value:o}:{error:'Expected a "'+e+'" but found a "'+b+'".',expected:e,type:b,value:o}:(h=~a.indexOf("*"),y=~a.indexOf(b),v&&(h||y)?{error:'Expected a "'+e+'" but found a "'+(y?b:"*")+'".',expected:e,type:y?b:"*",value:o}:v||h||y?{expected:e,type:b,value:o}:{error:'Expected a "'+e+'" but found a "'+b+'".',expected:e,type:b,value:o})}if("object"===x){if("object"!==b)return{error:'Expected an object but found a "'+b+'".',expected:e,type:b,value:o};for(l=Object.keys(e),d=l.length,s=0,p=0;d>p;p++){if(c=this.scan(e[l[p]],o[l[p]]),c.error)return c.path=c.path?[l[p]].concat(c.path):[l[p]],c;c.nully&&s++}if(f=Object.keys(o),f.length>d-s)for(d=f.length,p=0;d>p;p++)if("undefined"==typeof e[f[p]])return{error:'Unexpected key "'+f[p]+'".',expected:e,type:b,value:o};return{expected:e,type:b,value:o}}if("function"===x){var w={expected:e,type:b,value:o};return e(o)||(w.error="The target did not pass the given test (function)."),w}if("array"===x){if(1!==e.length)throw new Error("Invalid type.");if("array"!==b)return{error:'Expected an array but found a "'+b+'".',expected:e,type:b,value:o};for(d=o.length,u=0;d>u;u++)if(c=this.scan(e[0],o[u]),c.error)return c.path=c.path?[u].concat(c.path):[u],c;return{expected:e,type:b,value:o}}throw new Error("Invalid type.")},this.add=function(e,t){var r,o,a,u,d,p;if(1===arguments.length){if("object"!==this.get(e))throw new Error("If types.add is called with one argument, this one has to be an object.");r=e,u=r.id,p=r.type}else{if(2!==arguments.length)throw new Error("types.add has to be called with one or two arguments.");if("string"!=typeof e||!e)throw new Error("If types.add is called with more than one argument, the first one must be the string id.");u=e,p=t}if("string"!==this.get(u)||0===u.length)throw new Error("A type requires an string id.");if(void 0!==i[u]&&"proto"!==i[u])throw new Error('The type "'+u+'" already exists.');if(n[u])throw new Error('"'+u+'" is a reserved type name.');i[u]=1,a=(r||{}).proto||[],a=Array.isArray(a)?a:[a],d={};for(o in a)void 0===i[a[o]]&&(i[a[o]]=1,d[a[o]]=1);if("function"!==this.get(p)&&!this.isValid(p))throw new Error("A type requires a valid definition. This one can be a preexistant type or else a function testing given objects.");if(i[u]=void 0===r?{id:u,type:p}:{},void 0!==r)for(o in r)i[u][o]=r[o];for(o in d)o!==u&&delete i[o];return this},this.has=function(e){return!!i[e]},this.get=function(e){return null===e||void 0===e?String(e):r[Object.prototype.toString.call(e)]||"object"},this.check=function(e,t){return!this.scan(e,t).error},this.isValid=function(e){var t,o,a,u,d,p,c=null===e||void 0===e?String(e):r[Object.prototype.toString.call(e)]||"object";if("string"===c){for(t=e.replace(/^[\?\!]/,"").split(/\|/),d=Object.keys(t),u=d.length,a=0;u>a;a++)if(!n[t[d[a]]]&&"undefined"==typeof i[t[d[a]]])return!1;return!0}if("object"===c){for(p=Object.keys(e),u=p.length,o=0;u>o;o++)if(!this.isValid(e[p[o]]))return!1;return!0}return"array"===c?1===e.length?this.isValid(e[0]):!1:"function"===c?!0:!1},this.add("type",function(e){return this.isValid(e)}.bind(this)),this.add("primitive",function(e){return e!==Object(e)}),e=e||{},"object"!==this.get(e))throw Error("Invalid argument.");for(var o in e)this.add(o,e[o])}var r={},n={"*":!0};!function(){var e,t,i=["Boolean","Number","String","Object","Array","Function","Arguments","RegExp","Date","Map","Set","WeakMap","WeakSet","Symbol"];for(e in i)t=i[e],n[t.toLowerCase()]=!0,r["[object "+t+"]"]=t.toLowerCase()}();var i=t;t.call(i),Object.defineProperty(i,"version",{value:"1.2.0"}),"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.types=i):"function"==typeof define&&define.amd?define("typology",[],function(){return i}):e.types=i}(this); |
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
33263
686