Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "typology", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A data validation library for Node.js and the browser.", | ||
@@ -5,0 +5,0 @@ "main": "typology.js", |
@@ -199,3 +199,3 @@ # Typology | ||
To setup the project, just install npm dependencies with `npm install` and run tests with `npm tests`. | ||
To setup the project, just install npm dependencies with `npm install` and run tests with `npm test`. | ||
@@ -202,0 +202,0 @@ ## License |
/** | ||
* typology.js - A data validation library for Node.js and the browser, | ||
* | ||
* Version: 0.2.0 | ||
* Version: 0.2.1 | ||
* Sources: http://github.com/jacomyal/typology | ||
@@ -97,3 +97,3 @@ * Doc: http://github.com/jacomyal/typology#readme | ||
throw new Error('types.add has to be called ' + | ||
'with one or three arguments.'); | ||
'with one or two arguments.'); | ||
@@ -189,3 +189,3 @@ if (this.get(id) !== 'string' || id.length === 0) | ||
(typeof customTypes[a[i]].type === 'function') ? | ||
(customTypes[a[i]].type(obj) === true) : | ||
(customTypes[a[i]].type.call(this, obj) === true) : | ||
this.check(obj, customTypes[a[i]].type) | ||
@@ -289,3 +289,3 @@ ) | ||
Object.defineProperty(types, 'version', { | ||
value: '0.2.0' | ||
value: '0.2.1' | ||
}); | ||
@@ -292,0 +292,0 @@ |
/** | ||
* typology - A data validation library for Node.js and the browser. | ||
* @version v0.2.0 | ||
* @version v0.2.1 | ||
* @link https://github.com/jacomyal/typology | ||
* @license MIT | ||
*/ | ||
!function(){"use strict";function t(t){t=t||{};var e={};if(this.add=function(t,r){var i,n,s,f,a,h;if(1===arguments.length){if("object"!==this.get(t))throw new Error("If types.add is called with one argument, this one has to be an object.");i=t,f=i.id,h=i.type}else{if(2!==arguments.length)throw new Error("types.add has to be called with one or three arguments.");if("string"!=typeof t||!t)throw new Error("If types.add is called with more than one argument, the first one must be the string id.");f=t,h=r}if("string"!==this.get(f)||0===f.length)throw new Error("A type requires an string id.");if(void 0!==e[f]&&"proto"!==e[f])throw new Error('The type "'+f+'" already exists.');if(~o.indexOf(f))throw new Error('"'+f+'" is a reserved type name.');e[f]=1,s=(i||{}).proto||[],s=Array.isArray(s)?s:[s],a={};for(n in s)void 0===e[s[n]]&&(e[s[n]]=1,a[s[n]]=1);if("function"!==this.get(h)&&!this.isValid(h))throw new Error("A type requires a valid definition. This one can be a preexistant type or else a function testing given objects.");if(e[f]=void 0===i?{id:f,type:h}:{},void 0!==i)for(n in i)e[f][n]=i[n];for(n in a)n!==f&&delete e[n];return this},this.has=function(t){return!!e[t]},this.get=function(t){return null===t||void 0===t?String(t):n[Object.prototype.toString.call(t)]||"object"},this.check=function(t,r){var i,n,s,f=!1,a=!1,h=this.get(t);if("string"===this.get(r)){i=r.replace(/^[?!]/,"").split(/\|/);for(n in i)if(o.indexOf(i[n])<0&&!(i[n]in e))throw new Error("Invalid type.");r.match(/^\?/)&&(f=!0,r=r.replace(/^\?/,"")),r.match(/^!/)&&(a=!0,r=r.replace(/^!/,""));for(n in i)if(e[i[n]]&&("function"==typeof e[i[n]].type?e[i[n]].type(t)===!0:this.check(t,e[i[n]].type)))return!a;return null===t||void 0===t?a?!f:f:a?!(~i.indexOf("*")||~i.indexOf(h)):!(!~i.indexOf("*")&&!~i.indexOf(h))}if("object"===this.get(r)){if("object"!==h)return!1;for(s in r)if(!this.check(t[s],r[s]))return!1;for(s in t)if(void 0===r[s])return!1;return!0}if("array"===this.get(r)){if("array"!==h)return!1;if(1!==r.length)throw new Error("Invalid type.");for(s in t)if(!this.check(t[s],r[0]))return!1;return!0}return!1},this.isValid=function(t){var r,i,n;if("string"===this.get(t)){r=t.replace(/^[?!]/,"").split(/\|/);for(n in r)if(o.indexOf(r[n])<0&&!(r[n]in e))return!1;return!0}if("object"===this.get(t)){for(i in t)if(!this.isValid(t[i]))return!1;return!0}return"array"===this.get(t)&&1===t.length?this.isValid(t[0]):!1},this.add("type",function(t){return this.isValid(t)}.bind(this)),this.add("primitive",function(t){return!t||!(t instanceof Object||"object"==typeof t)}),"object"!==this.get(t))throw Error("Invalid argument.");for(var r in t)this.add(r,t[r])}var e,r,i=["Arguments","Boolean","Number","String","Function","Array","Date","RegExp","Object"],n={},o=["*"];for(e in i)r=i[e],o.push(r.toLowerCase()),n["[object "+r+"]"]=r.toLowerCase();var s=t;t.call(s),Object.defineProperty(s,"version",{value:"0.1.1"}),"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=s),exports.types=s):"function"==typeof define&&define.amd?define("typology",[],function(){return s}):this.types=s}(this); | ||
!function(){"use strict";function t(t){t=t||{};var e={};if(this.add=function(t,r){var i,n,s,f,a,h;if(1===arguments.length){if("object"!==this.get(t))throw new Error("If types.add is called with one argument, this one has to be an object.");i=t,f=i.id,h=i.type}else{if(2!==arguments.length)throw new Error("types.add has to be called with one or two arguments.");if("string"!=typeof t||!t)throw new Error("If types.add is called with more than one argument, the first one must be the string id.");f=t,h=r}if("string"!==this.get(f)||0===f.length)throw new Error("A type requires an string id.");if(void 0!==e[f]&&"proto"!==e[f])throw new Error('The type "'+f+'" already exists.');if(~o.indexOf(f))throw new Error('"'+f+'" is a reserved type name.');e[f]=1,s=(i||{}).proto||[],s=Array.isArray(s)?s:[s],a={};for(n in s)void 0===e[s[n]]&&(e[s[n]]=1,a[s[n]]=1);if("function"!==this.get(h)&&!this.isValid(h))throw new Error("A type requires a valid definition. This one can be a preexistant type or else a function testing given objects.");if(e[f]=void 0===i?{id:f,type:h}:{},void 0!==i)for(n in i)e[f][n]=i[n];for(n in a)n!==f&&delete e[n];return this},this.has=function(t){return!!e[t]},this.get=function(t){return null===t||void 0===t?String(t):n[Object.prototype.toString.call(t)]||"object"},this.check=function(t,r){var i,n,s,f=!1,a=!1,h=this.get(t);if("string"===this.get(r)){i=r.replace(/^[?!]/,"").split(/\|/);for(n in i)if(o.indexOf(i[n])<0&&!(i[n]in e))throw new Error("Invalid type.");r.match(/^\?/)&&(f=!0,r=r.replace(/^\?/,"")),r.match(/^!/)&&(a=!0,r=r.replace(/^!/,""));for(n in i)if(e[i[n]]&&("function"==typeof e[i[n]].type?e[i[n]].type.call(this,t)===!0:this.check(t,e[i[n]].type)))return!a;return null===t||void 0===t?a?!f:f:a?!(~i.indexOf("*")||~i.indexOf(h)):!(!~i.indexOf("*")&&!~i.indexOf(h))}if("object"===this.get(r)){if("object"!==h)return!1;for(s in r)if(!this.check(t[s],r[s]))return!1;for(s in t)if(void 0===r[s])return!1;return!0}if("array"===this.get(r)){if("array"!==h)return!1;if(1!==r.length)throw new Error("Invalid type.");for(s in t)if(!this.check(t[s],r[0]))return!1;return!0}return!1},this.isValid=function(t){var r,i,n;if("string"===this.get(t)){r=t.replace(/^[?!]/,"").split(/\|/);for(n in r)if(o.indexOf(r[n])<0&&!(r[n]in e))return!1;return!0}if("object"===this.get(t)){for(i in t)if(!this.isValid(t[i]))return!1;return!0}return"array"===this.get(t)&&1===t.length?this.isValid(t[0]):!1},this.add("type",function(t){return this.isValid(t)}.bind(this)),this.add("primitive",function(t){return!t||!(t instanceof Object||"object"==typeof t)}),"object"!==this.get(t))throw Error("Invalid argument.");for(var r in t)this.add(r,t[r])}var e,r,i=["Arguments","Boolean","Number","String","Function","Array","Date","RegExp","Object"],n={},o=["*"];for(e in i)r=i[e],o.push(r.toLowerCase()),n["[object "+r+"]"]=r.toLowerCase();var s=t;t.call(s),Object.defineProperty(s,"version",{value:"0.2.1"}),"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=s),exports.types=s):"function"==typeof define&&define.amd?define("typology",[],function(){return s}):this.types=s}(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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
19454
0