Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed async dependency.

  • Loading branch information...
commit e1d01af6bae5064b883a8ab58146502dfac51952 1 parent 69aeb13
@kumatch authored
View
1  .gitignore
@@ -0,0 +1 @@
+node_modules
View
2  datagate.min.js
@@ -1 +1 @@
-(function(){function b(){return b}function c(b,d){var e=c.resolve(b),f=c.modules[e];if(!f)throw new Error('failed to require "'+b+'" from '+d);return f.exports||(f.exports={},f.call(f.exports,f,f.exports,c.relative(e),a)),f.exports}var a=this;c.modules={},c.resolve=function(a){var b=a,d=a+".js",e=a+"/index.js";return c.modules[d]&&d||c.modules[e]&&e||b},c.register=function(a,b){c.modules[a]=b},c.relative=function(a){return function(d){if("debug"==d)return b;if("."!=d.charAt(0))return c(d);var e=a.split("/"),f=d.split("/");e.pop();for(var g=0;g<f.length;g++){var h=f[g];".."==h?e.pop():"."!=h&&e.push(h)}return c(e.join("/"),a)}},c.register("array.js",function(a,b,c,d){var e=c("./utils"),f=c("./error").ArrayError,g=e._,h=e.async;a.exports=function(a,b){return b===undefined&&(b="Invalid value in array."),function(c,d){var e=[],i=[];if(!g.isArray(c)){d(new f({message:b,origin:c,result:e,errors:i}),e);return}h.forEachSeries(c,function(b,c){typeof a=="function"?a(b,function(a,b){e.push(b),a&&i.push(a),c()}):(e.push(b),c())},function(a){if(i.length){var g=new f({message:b,origin:c,result:e,errors:i});d(g,e)}else d(null,e)})}}}),c.register("datagate.js",function(a,b,c,d){function i(a,b){b===undefined&&(b=function(a,b){return"Invalid value / origin: "+a+", result: "+b});var c=g.map(a,function(a){var c,d;g.isArray(a)?(c=a[0],d=a[1]||b):(c=a,d=b);if(!g.isFunction(c))throw Error("Invalid datagate filter.");return function(a,b,e){c(b,function(c,h){if(!c)e(null,a,h);else{var i=d;g.isFunction(d)&&(i=d(a,b)),e(new f({message:i,origin:a,result:b}))}})}});return function(a,b){var d=c.slice(0);d.unshift(function(b){b(null,a,a)}),h.waterfall(d,function(a,c,d){a?b(a,a.result):b(null,d)})}}var e=c("./utils"),f=c("./error").VariableError,g=e._,h=e.async;b=a.exports=i,b.array=c("./array"),b.object=c("./object"),b.union=c("./union"),b.filter=c("./filter"),b.validator=c("./validator")}),c.register("error.js",function(a,b,c,d){function f(a){Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name="DatagateVariableError",this.message=a.message,this.origin=a.origin,this.result=a.result}function g(a){Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name="DatagateArrayError",this.message=a.message,this.origin=a.origin,this.result=a.result,this.errors=a.errors,this.errors_message=k(this.errors)}function h(a){Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name="DatagateObjectError",this.message=a.message,this.origin=a.origin,this.result=a.result,this.properties=a.properties,this.properties_message=j(this.properties)}function i(a){Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name="DatagateUnionError",this.message=a.message,this.origin=a.origin,this.result=a.result,this.errors=a.errors,this.errors_message=k(this.errors)}function j(a){var b=e.keys(a),c=b.length,d={};for(var f=0;f<c;f++){var g=b[f],h=a[g];h.name==="DatagateObjectError"?d[g]=h.properties_message:h.name==="DatagateArrayError"?d[g]=h.errors_message:d[g]=h.message}return d}function k(a){return e.map(a,function(a){return a.name==="DatagateObjectError"?a.properties_message:a.name==="DatagateArrayError"||a.name==="DatagateUnionError"?a.errors_message:a.message})}var e=c("./utils")._;b.VariableError=f,b.ArrayError=g,b.ObjectError=h,b.UnionError=i,f.prototype=new Error,g.prototype=new Error,h.prototype=new Error,i.prototype=new Error}),c.register("filter.js",function(a,b,c,d){b.trim=function(a,b){typeof a=="string"&&a+""&&(a=String.prototype.trim.call(a)),b(null,a)},b.toLowerCase=function(a,b){typeof a=="string"&&a+""&&(a=String.prototype.toLowerCase.call(a)),b(null,a)},b.toUpperCase=function(a,b){typeof a=="string"&&a+""&&(a=String.prototype.toUpperCase.call(a)),b(null,a)},b.toStringType=function(a,b){b(null,a+"")},b.toNumberType=function(a,b){a===undefined||a===null||a===""?b(null,NaN):b(null,Number(a))},b.toBooleanType=function(a,b){!a||a==="0"||a===null||a===undefined?b(null,!1):b(null,!0)},b.replace=function(a,b){return function(c,d){typeof c=="string"&&c+""&&(c=String.prototype.replace.call(c,a,b)),d(null,c)}},b.toDefault=function(a){return function(b,c){b===undefined||b===null||b===""?c(null,a):c(null,b)}},b.custom=function(a){if(typeof a!="function")throw Error("Argument must be function in datagate custom filter.");return a}}),c.register("object.js",function(a,b,c,d){var e=c("./utils"),f=c("./error").ObjectError,g=e._,h=e.async;a.exports=function(a,b){b===undefined&&(b="Invalid object value.");var c=a?g.keys(a):[];return function(d,e){var i={},j={},k=!1;g.isObject(d)||(k=!0),h.forEach(c,function(b,c){var e=a[b],f=d?d[b]:undefined;e(f,function(a,d){i[b]=d,a&&(j[b]=a,k=!0),c()})},function(a){if(a)e(a);else if(k){var c=new f({message:b,origin:d,result:i,properties:j});e(c,i)}else e(null,i)})}}}),c.register("union.js",function(a,b,c,d){var e=c("./utils").async,f=c("./error").UnionError;a.exports=function(a,b){return b===undefined&&(b="Invalid value in union."),function(c,d){if(!a)return d(null,c);var g=[],h;e.forEachSeries(a,function(a,b){a(c,function(a,c){h=c,a?(g.push(a),b()):d(null,c)})},function(a){if(a)d(a);else{var e=new f({message:b,origin:c,result:h,errors:g});d(e,h)}})}}}),c.register("utils.js",function(a,b,c,d){typeof _!="undefined"&&_.VERSION?b._=_:b._=c("underscore"),typeof async!="undefined"?b.async=async:b.async=c("async"),b.chain=function(a,b){function c(d){if(d)b(d);else{var e=a.shift(),f=Array.prototype.slice.call(arguments);a.length>0?f=f.slice(1).concat(c):f=f.slice(1).concat(b),e.apply(null,f)}}c()}}),c.register("validator.js",function(a,b,c,d){var e=c("./utils")._,f={};a.exports=f;var g={NumberType:function(a,b){e.isNumber(a)?b(null,a):b(Error())},StringType:function(a,b){e.isString(a)?b(null,a):b(Error())},BooleanType:function(a,b){e.isBoolean(a)?b(null,a):b(Error())},FunctionType:function(a,b){e.isFunction(a)?b(null,a):b(Error())},ArrayType:function(a,b){e.isArray(a)?b(null,a):b(Error())},ObjectType:function(a,b){Object.prototype.toString.call(a)==="[object Object]"?b(null,a):b(Error())},DateType:function(a,b){e.isDate(a)?b(null,a):b(Error())},RegExpType:function(a,b){e.isRegExp(a)?b(null,a):b(Error())},Empty:function(a,b){a===null||a===undefined||a===""?b(null,a):b(Error())},Null:function(a,b){a===null?b(null,a):b(Error())},Undefined:function(a,b){a===undefined?b(null,a):b(Error())},NaN:function(a,b){e.isNaN(a)?b(null,a):b(Error())},Integer:function(a,b){(e.isNumber(a)||e.isString(a))&&(a+"").match(/^-?[0-9]+$/)?b(null,a):b(Error())},Alphabet:function(a,b){e.isString(a)&&(a+"").match(/^[a-zA-Z]+$/)?b(null,a):b(Error())},Alphanumeric:function(a,b){e.isString(a)&&(a+"").match(/^[a-zA-Z0-9]+$/)||e.isNumber(a)&&(a+"").match(/^[0-9]+$/)?b(null,a):b(Error())},Decimal:function(a,b){(e.isNumber(a)||e.isString(a))&&(a+"").match(/^\-?[0-9]+(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/)?b(null,a):b(Error())},Ascii:function(a,b){!e.isNaN(a)&&(e.isNumber(a)||e.isString(a))&&(a+"").match(/^[!-~]+$/)?b(null,a):b(Error())},Url:function(a,b){var c=/^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[\-\w\d{1-3}]+\.)+(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2}))|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[\-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[\-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[\-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[\-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[\-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[\-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/;c.test(a)?b(null,a):b(Error())},Email:function(a,b){var c=/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/;c.test(a)?b(null,a):b(Error())},Date:function(a,b){var c=/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/,d=Date.parse(a);c.test(a)&&!e.isNaN(d)?b(null,a):b(Error())},Time:function(a,b){if(!e.isString(a)){b(Error());return}var c=/^(\d{2}):(\d{2}):(\d{2})$/,d=a.match(c);if(!d){b(Error());return}var f=d[1],g=d[2],h=d[3];f>=0&&f<24&&g>=0&&g<60&&h>=0&&h<60?b(null,a):b(Error())}};e.each(g,function(a,b){var c="is"+b,d="not"+b;f[c]=a,f[d]=function(b,c){a(b,function(a,d){a?c(null,b):c(Error())})}}),f.required=f.notUndefined,f.max=f.maximum=function(a){return function(b,c){f.isDecimal(b,function(d,e){d?c(d):parseFloat(b)>a?c(Error()):c(null,b)})}},f.min=f.minimum=function(a){return function(b,c){f.isDecimal(b,function(d,e){d?c(d):parseFloat(b)<a?c(Error()):c(null,b)})}},f.maxLength=function(a){return function(b,c){e.isString(b)&&b.length<=a?c(null,b):e.isNumber(b)&&!e.isNaN(b)&&(b+"").length<=a?c(null,b):c(Error())}},f.minLength=function(a){return function(b,c){e.isString(b)&&b.length>=a?c(null,b):e.isNumber(b)&&!e.isNaN(b)&&(b+"").length>=a?c(null,b):c(Error())}},f.isPattern=function(a){if(!e.isRegExp(a))throw Error("Argument must be regexp type in datagate pattern validator.");return function(b,c){a.test(b)?c(null,b):c(Error())}},f.notPattern=function(a){if(!e.isRegExp(a))throw Error("Argument must be regexp type in datagate pattern validator.");return function(b,c){a.test(b)?c(Error()):c(null,b)}},f.isIn=function(a){return function(b,c){e.indexOf(a,b)<0?c(Error()):c(null,b)}},f.notIn=function(a){return function(b,c){e.indexOf(a,b)<0?c(null,b):c(Error())}},f.custom=function(a){if(typeof a!="function")throw Error("Argument must be function in datagate custom validator.");return a}}),datagate=c("datagate")})();
+(function(){function b(){return b}function c(b,d){var e=c.resolve(b),f=c.modules[e];if(!f)throw new Error('failed to require "'+b+'" from '+d);return f.exports||(f.exports={},f.call(f.exports,f,f.exports,c.relative(e),a)),f.exports}var a=this;c.modules={},c.resolve=function(a){var b=a,d=a+".js",e=a+"/index.js";return c.modules[d]&&d||c.modules[e]&&e||b},c.register=function(a,b){c.modules[a]=b},c.relative=function(a){return function(d){if("debug"==d)return b;if("."!=d.charAt(0))return c(d);var e=a.split("/"),f=d.split("/");e.pop();for(var g=0;g<f.length;g++){var h=f[g];".."==h?e.pop():"."!=h&&e.push(h)}return c(e.join("/"),a)}},c.register("array.js",function(a,b,c,d){var e=c("./utils"),f=c("./error").ArrayError,g=e._,h=e.plow;a.exports=function(a,b){return b===undefined&&(b="Invalid value in array."),function(c,d){var e=[],i=[];if(!g.isArray(c)){d(new f({message:b,origin:c,result:[],errors:e}),[]);return}h.map(c,function(b,c,d){typeof a=="function"?a(b,function(a,b){a&&(e[c]=a),i[c]=b,d(null)}):(i[c]=b,d())},function(a){if(a){d(a);return}e=g.compact(e);if(e.length){var h=new f({message:b,origin:c,result:i,errors:e});d(h,i)}else d(null,i)})}}}),c.register("datagate.js",function(a,b,c,d){function i(a,b){b===undefined&&(b=function(a,b){return"Invalid value / origin: "+a+", result: "+b});var c=g.map(a,function(a){var c,d;g.isArray(a)?(c=a[0],d=a[1]||b):(c=a,d=b);if(!g.isFunction(c))throw Error("Invalid datagate filter.");return function(a,b,e){c(b,function(c,h){if(!c)e(null,a,h);else{var i=d;g.isFunction(d)&&(i=d(a,b)),e(new f({message:i,origin:a,result:b}))}})}});return function(a,b){var d=c.slice(0);d.unshift(function(b){b(null,a,a)}),h.sequential(d,function(a,c,d){a?b(a,a.result):b(null,d)})}}var e=c("./utils"),f=c("./error").VariableError,g=e._,h=e.plow;b=a.exports=i,b.array=c("./array"),b.object=c("./object"),b.union=c("./union"),b.filter=c("./filter"),b.validator=c("./validator")}),c.register("error.js",function(a,b,c,d){function f(a){Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name="DatagateVariableError",this.message=a.message,this.origin=a.origin,this.result=a.result}function g(a){Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name="DatagateArrayError",this.message=a.message,this.origin=a.origin,this.result=a.result,this.errors=a.errors,this.errors_message=k(this.errors)}function h(a){Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name="DatagateObjectError",this.message=a.message,this.origin=a.origin,this.result=a.result,this.properties=a.properties,this.properties_message=j(this.properties)}function i(a){Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name="DatagateUnionError",this.message=a.message,this.origin=a.origin,this.result=a.result,this.errors=a.errors,this.errors_message=k(this.errors)}function j(a){var b=e.keys(a),c=b.length,d={};for(var f=0;f<c;f++){var g=b[f],h=a[g];h.name==="DatagateObjectError"?d[g]=h.properties_message:h.name==="DatagateArrayError"?d[g]=h.errors_message:d[g]=h.message}return d}function k(a){return e.map(a,function(a){return a.name==="DatagateObjectError"?a.properties_message:a.name==="DatagateArrayError"||a.name==="DatagateUnionError"?a.errors_message:a.message})}var e=c("./utils")._;b.VariableError=f,b.ArrayError=g,b.ObjectError=h,b.UnionError=i,f.prototype=new Error,g.prototype=new Error,h.prototype=new Error,i.prototype=new Error}),c.register("filter.js",function(a,b,c,d){b.trim=function(a,b){typeof a=="string"&&a+""&&(a=String.prototype.trim.call(a)),b(null,a)},b.toLowerCase=function(a,b){typeof a=="string"&&a+""&&(a=String.prototype.toLowerCase.call(a)),b(null,a)},b.toUpperCase=function(a,b){typeof a=="string"&&a+""&&(a=String.prototype.toUpperCase.call(a)),b(null,a)},b.toStringType=function(a,b){b(null,a+"")},b.toNumberType=function(a,b){a===undefined||a===null||a===""?b(null,NaN):b(null,Number(a))},b.toBooleanType=function(a,b){!a||a==="0"||a===null||a===undefined?b(null,!1):b(null,!0)},b.replace=function(a,b){return function(c,d){typeof c=="string"&&c+""&&(c=String.prototype.replace.call(c,a,b)),d(null,c)}},b.toDefault=function(a){return function(b,c){b===undefined||b===null||b===""?c(null,a):c(null,b)}},b.custom=function(a){if(typeof a!="function")throw Error("Argument must be function in datagate custom filter.");return a}}),c.register("object.js",function(a,b,c,d){var e=c("./utils"),f=c("./error").ObjectError,g=e._,h=e.plow;a.exports=function(a,b){b===undefined&&(b="Invalid object value.");var c=a?g.keys(a):[];return function(d,e){var i={},j={},k=!1;g.isObject(d)||(k=!0),h.map(c,function(b,c){var e=a[b],f=d?d[b]:undefined;e(f,function(a,d){i[b]=d,a&&(j[b]=a,k=!0),c()})},function(a){if(a)e(a);else if(k){var c=new f({message:b,origin:d,result:i,properties:j});e(c,i)}else e(null,i)})}}}),c.register("plow.js",function(a,b,c,d){function f(a,c){var d=Array.prototype.slice.call(a);c=c||function(){};if(!d.length){c();return}(function e(a){if(a)c(a);else{var f=d.shift(),g=Array.prototype.slice.call(arguments);d.length>0?g=g.slice(1).concat(e):g=g.slice(1).concat(c),b.nextTick(function(){try{f.apply(null,g)}catch(a){c(a)}})}})(null)}function g(a,b){var c=0,d=!1,e=k(a),f,g;e?(f=[],g=a.length):(f={},g=l(a).length),b=b||function(){};if(!g){b(null,f);return}var h=function(a,b,c){a(function(a,d){a?c(a):c(null,{index:b,value:d})})},j=1,m=0;i(j,a,h,m,function(a,d){return a?(b(a),!1):(c+=1,f[d.index]=d.value,c===g&&b(null,f),!0)})}function h(a,b,c){var d=a.length,f=[],g=!1;c=c||function(){},d?i(e,a,b,0,function(a,b){return a?(c(a,f),!1):(f.push(b),f.length===d&&c(null,f),!0)}):c(null,[])}function i(a,c,d,e,f){function n(a,b){f(a,b)||(g=!0)}var g=!1,h=k(c),j,m;h?m=c.length:(j=l(c),m=j.length),b.nextTick(function(){for(var b=e;b<m&&b<e+a;b++)if(!g)try{var k,l;h?(l=b,k=c[l]):(l=j[b],k=c[l]),d.length>2?d(k,l,n):d(k,n)}catch(o){g=!0,f(o)}!g&&b<m&&i(a,c,d,b,f)})}function j(a){typeof process=="undefined"||!process.nextTick?setTimeout(a,0):process.nextTick(a)}function k(a){return Object.prototype.toString.call(a)==="[object Array]"}function l(a){if(typeof Object.keys!="function")return Object.keys(a);var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}b.sequential=f,b.parallel=g,b.map=h,b.nextTick=j;var e=10}),c.register("union.js",function(a,b,c,d){var e=c("./utils").plow,f=c("./error").UnionError;a.exports=function(a,b){return b===undefined&&(b="Invalid value in union."),function(c,d){if(!a)return d(null,c);var g=[],h;e.map(a,function(a,b){a(c,function(a,c){h=c,a?(g.push(a),b()):d(null,c)})},function(a){if(a)d(a);else{var e=new f({message:b,origin:c,result:h,errors:g});d(e,h)}})}}}),c.register("utils.js",function(a,b,c,d){typeof _!="undefined"&&_.VERSION?b._=_:b._=c("underscore"),b.plow=c("./plow")}),c.register("validator.js",function(a,b,c,d){var e=c("./utils")._,f={};a.exports=f;var g={NumberType:function(a,b){e.isNumber(a)?b(null,a):b(Error())},StringType:function(a,b){e.isString(a)?b(null,a):b(Error())},BooleanType:function(a,b){e.isBoolean(a)?b(null,a):b(Error())},FunctionType:function(a,b){e.isFunction(a)?b(null,a):b(Error())},ArrayType:function(a,b){e.isArray(a)?b(null,a):b(Error())},ObjectType:function(a,b){Object.prototype.toString.call(a)==="[object Object]"?b(null,a):b(Error())},DateType:function(a,b){e.isDate(a)?b(null,a):b(Error())},RegExpType:function(a,b){e.isRegExp(a)?b(null,a):b(Error())},Empty:function(a,b){a===null||a===undefined||a===""?b(null,a):b(Error())},Null:function(a,b){a===null?b(null,a):b(Error())},Undefined:function(a,b){a===undefined?b(null,a):b(Error())},NaN:function(a,b){e.isNaN(a)?b(null,a):b(Error())},Integer:function(a,b){(e.isNumber(a)||e.isString(a))&&(a+"").match(/^-?[0-9]+$/)?b(null,a):b(Error())},Alphabet:function(a,b){e.isString(a)&&(a+"").match(/^[a-zA-Z]+$/)?b(null,a):b(Error())},Alphanumeric:function(a,b){e.isString(a)&&(a+"").match(/^[a-zA-Z0-9]+$/)||e.isNumber(a)&&(a+"").match(/^[0-9]+$/)?b(null,a):b(Error())},Decimal:function(a,b){(e.isNumber(a)||e.isString(a))&&(a+"").match(/^\-?[0-9]+(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/)?b(null,a):b(Error())},Ascii:function(a,b){!e.isNaN(a)&&(e.isNumber(a)||e.isString(a))&&(a+"").match(/^[!-~]+$/)?b(null,a):b(Error())},Url:function(a,b){var c=/^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[\-\w\d{1-3}]+\.)+(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2}))|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[\-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[\-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[\-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[\-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[\-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[\-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/;c.test(a)?b(null,a):b(Error())},Email:function(a,b){var c=/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/;c.test(a)?b(null,a):b(Error())},Date:function(a,b){var c=/^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/,d=Date.parse(a);c.test(a)&&!e.isNaN(d)?b(null,a):b(Error())},Time:function(a,b){if(!e.isString(a)){b(Error());return}var c=/^(\d{2}):(\d{2}):(\d{2})$/,d=a.match(c);if(!d){b(Error());return}var f=d[1],g=d[2],h=d[3];f>=0&&f<24&&g>=0&&g<60&&h>=0&&h<60?b(null,a):b(Error())}};e.each(g,function(a,b){var c="is"+b,d="not"+b;f[c]=a,f[d]=function(b,c){a(b,function(a,d){a?c(null,b):c(Error())})}}),f.required=f.notUndefined,f.max=f.maximum=function(a){return function(b,c){f.isDecimal(b,function(d,e){d?c(d):parseFloat(b)>a?c(Error()):c(null,b)})}},f.min=f.minimum=function(a){return function(b,c){f.isDecimal(b,function(d,e){d?c(d):parseFloat(b)<a?c(Error()):c(null,b)})}},f.maxLength=function(a){return function(b,c){e.isString(b)&&b.length<=a?c(null,b):e.isNumber(b)&&!e.isNaN(b)&&(b+"").length<=a?c(null,b):c(Error())}},f.minLength=function(a){return function(b,c){e.isString(b)&&b.length>=a?c(null,b):e.isNumber(b)&&!e.isNaN(b)&&(b+"").length>=a?c(null,b):c(Error())}},f.isPattern=function(a){if(!e.isRegExp(a))throw Error("Argument must be regexp type in datagate pattern validator.");return function(b,c){a.test(b)?c(null,b):c(Error())}},f.notPattern=function(a){if(!e.isRegExp(a))throw Error("Argument must be regexp type in datagate pattern validator.");return function(b,c){a.test(b)?c(Error()):c(null,b)}},f.isIn=function(a){return function(b,c){e.indexOf(a,b)<0?c(Error()):c(null,b)}},f.notIn=function(a){return function(b,c){e.indexOf(a,b)<0?c(null,b):c(Error())}},f.custom=function(a){if(typeof a!="function")throw Error("Argument must be function in datagate custom validator.");return a}}),datagate=c("datagate")})();
View
27 lib/array.js
@@ -2,7 +2,7 @@ var utils = require('./utils');
var ArrayError = require('./error').ArrayError;
var _ = utils._;
-var async = utils.async;
+var plow = utils.plow;
module.exports = function createNewArrayGate(gate, error_message) {
if (error_message === undefined) {
@@ -10,34 +10,41 @@ module.exports = function createNewArrayGate(gate, error_message) {
}
return function (values, callback) {
- var results = [];
var errors = [];
+ var results = [];
if (!_.isArray(values)) {
callback(new ArrayError({
message: error_message,
origin: values,
- result: results,
+ result: [],
errors: errors
- }), results);
+ }), []);
+
return;
}
-
- async.forEachSeries(values, function (value, next) {
+ plow.map(values, function (value, index, next) {
if (typeof gate === 'function') {
gate(value, function (err, result) {
- results.push(result);
if (err) {
- errors.push(err);
+ errors[index] = err;
}
- next();
+ results[index] = result;
+ next(null);
});
} else {
- results.push(value);
+ results[index] = value;
next();
}
}, function (err) {
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ errors = _.compact(errors);
+
if (errors.length) {
var total_err = new ArrayError({
message: error_message,
View
4 lib/datagate.js
@@ -2,7 +2,7 @@ var utils = require('./utils');
var VariableError = require('./error').VariableError;
var _ = utils._;
-var async = utils.async;
+var plow = utils.plow;
exports = module.exports = datagate;
@@ -64,7 +64,7 @@ function datagate(entries, root_error_message) {
next(null, value, value);
});
- async.waterfall(tasks, function (err, origin, result) {
+ plow.sequential(tasks, function (err, origin, result) {
if (!err) {
callback(null, result);
} else {
View
6 lib/object.js
@@ -2,7 +2,7 @@ var utils = require('./utils');
var ObjectError = require('./error').ObjectError;
var _ = utils._;
-var async = utils.async;
+var plow = utils.plow;
module.exports = function createNewObjectGate(entries, error_message) {
if (error_message === undefined) {
@@ -21,8 +21,8 @@ module.exports = function createNewObjectGate(entries, error_message) {
has_error = true;
}
- async.forEach(properties, function (property, next) {
- var gate = entries[property];
+ plow.map(properties, function (property, next) {
+ var gate = entries[property];
var value = object ? object[property] : undefined;
gate(value, function (err, result) {
View
211 lib/plow.js
@@ -0,0 +1,211 @@
+// plow.js 0.1.1
+// (c) 2012 Yosuke Kumakura
+// https://github.com/kumatch/plow
+//
+// Licensed under the MIT license:
+// http://www.opensource.org/licenses/MIT
+
+exports.sequential = _sequential;
+exports.parallel = _parallel;
+exports.map = _map;
+exports.nextTick = _nextTick;
+
+var DEFAULT_CONCURRENCY = 10;
+
+function _sequential(list, end) {
+ var tasks = Array.prototype.slice.call(list);
+
+ end = end || function () {};
+
+ if (!tasks.length) {
+ end();
+ return;
+ }
+
+ (function next(err) {
+ if (err) {
+ end(err);
+ } else {
+ var task = tasks.shift();
+ var args = Array.prototype.slice.call(arguments);
+
+ if (tasks.length > 0) {
+ args = args.slice(1).concat(next);
+ } else {
+ args = args.slice(1).concat(end);
+ }
+
+ exports.nextTick(function () {
+ try {
+ task.apply(null, args);
+ } catch (e) {
+ end(e);
+ }
+ });
+ }
+ })(null);
+}
+
+
+
+function _parallel(tasks, end) {
+ var completed = 0;
+ var failed = false;
+ var is_array = _isArray(tasks);
+ var results, length;
+
+ if (is_array) {
+ results = [];
+ length = tasks.length;
+ } else {
+ results = {};
+ length = _keys(tasks).length;
+ }
+
+ end = end || function () {};
+
+ if (!length) {
+ end(null, results);
+ return;
+ }
+
+
+
+ var worker = function (task, index, next) {
+ task(function (err, value) {
+ if (err) {
+ next(err);
+ } else {
+ next(null, {
+ index: index,
+ value: value
+ });
+ }
+ });
+ };
+
+ var concurrency = 1;
+ var index = 0;
+
+ _doWork(concurrency, tasks, worker, index, function(err, result) {
+
+ if (err) {
+ end(err);
+ return false;
+ } else {
+ completed += 1;
+ results[result.index] = result.value;
+
+ if (completed === length) {
+ end(null, results);
+ }
+ return true;
+ }
+ });
+}
+
+
+function _map(list, worker, end) {
+ var length = list.length;
+ var results = [];
+ var failed = false;
+
+ end = end || function () {};
+
+ if (!length) {
+ end(null, []);
+ } else {
+ _doWork(DEFAULT_CONCURRENCY, list, worker, 0, function(err, result) {
+ if (err) {
+ end(err, results);
+ return false;
+ } else {
+ results.push(result);
+
+ if (results.length === length) {
+ end(null, results);
+ }
+ return true;
+ }
+ });
+ }
+}
+
+
+function _doWork(concurrency, list, worker, currentIndex, callback) {
+ var failed = false;
+ var is_array = _isArray(list);
+ var keys, length;
+
+ if (is_array) {
+ length = list.length;
+ } else {
+ keys = _keys(list);
+ length = keys.length;
+ }
+
+ function workerCallback (err, result) {
+ if (!callback(err, result)) {
+ failed = true;
+ }
+ }
+
+ exports.nextTick(function () {
+ for (var i = currentIndex; (i < length && i < (currentIndex + concurrency)); i++) {
+ if (!failed) {
+ try {
+ var value, index;
+
+ if (is_array) {
+ index = i;
+ value = list[index];
+ } else {
+ index = keys[i];
+ value = list[index];
+ }
+
+ if (worker.length > 2) {
+ worker(value, index, workerCallback);
+ } else {
+ worker(value, workerCallback);
+ }
+ } catch (e) {
+ failed = true;
+ callback(e);
+ }
+ }
+ }
+
+ if (!failed && i < length) {
+ _doWork(concurrency, list, worker, i, callback);
+ }
+ });
+}
+
+
+function _nextTick(func) {
+ if (typeof process === 'undefined' || !(process.nextTick)) {
+ setTimeout(func, 0);
+ } else {
+ process.nextTick(func);
+ }
+}
+
+
+function _isArray(array) {
+ return (Object.prototype.toString.call(array) === '[object Array]');
+}
+
+function _keys(obj) {
+ if (typeof Object.keys !== 'function') {
+ return Object.keys(obj);
+ }
+
+ var keys = [];
+ for (var k in obj) {
+ if (obj.hasOwnProperty(k)) {
+ keys.push(k);
+ }
+ }
+ return keys;
+}
View
32 lib/union.js
@@ -1,4 +1,4 @@
-var async = require('./utils').async;
+var plow = require('./utils').plow;
var UnionError = require('./error').UnionError;
module.exports = function createNewUnionGate(gates, error_message) {
@@ -14,7 +14,7 @@ module.exports = function createNewUnionGate(gates, error_message) {
var errors = [];
var last_result;
- async.forEachSeries(gates, function (gate, next) {
+ plow.map(gates, function (gate, next) {
gate(value, function (err, result) {
last_result = result;
@@ -23,21 +23,21 @@ module.exports = function createNewUnionGate(gates, error_message) {
next();
} else {
callback(null, result);
- }
- });
- }, function (err) {
- if (err) {
- callback(err);
- } else {
- var union_err = new UnionError({
- message: error_message,
- origin: value,
- result: last_result,
- errors: errors
- });
-
- callback(union_err, last_result);
}
});
+ }, function (err) {
+ if (err) {
+ callback(err);
+ } else {
+ var union_err = new UnionError({
+ message: error_message,
+ origin: value,
+ result: last_result,
+ errors: errors
+ });
+
+ callback(union_err, last_result);
+ }
+ });
};
};
View
29 lib/utils.js
@@ -4,31 +4,4 @@ if (typeof _ !== 'undefined' && _.VERSION) {
exports._ = require('underscore');
}
-if (typeof async !== 'undefined') {
- exports.async = async;
-} else {
- exports.async = require('async');
-}
-
-
-exports.chain = function (acts, last) {
- next();
-
- function next(err) {
- if (err) {
- // acts.pop()(err);
- last(err);
- } else {
- var act = acts.shift();
- var args = Array.prototype.slice.call(arguments);
-
- if (acts.length > 0) {
- args = args.slice(1).concat(next);
- } else {
- args = args.slice(1).concat(last);
- }
-
- act.apply(null, args);
- }
- }
-};
+exports.plow = require('./plow');
View
1  lib/validator.js
@@ -3,7 +3,6 @@ var validator = {};
module.exports = validator;
-
var validations = {
NumberType: function (val, callback) {
if (_.isNumber(val)) {
View
7 package.json
@@ -12,12 +12,13 @@
"test": "./test/testrunner"
},
"dependencies": {
- "underscore": "*",
- "async": "*"
+ "underscore": "*"
},
"devDependencies": {
"mocha": "*",
- "should": "*"
+ "should": "*",
+ "grunt": "*",
+ "browserbuild": "*"
},
"optionalDependencies": {},
"engines": {
Please sign in to comment.
Something went wrong with that request. Please try again.