customs.js
Advanced tools
+4
-1
| { | ||
| "name": "customs.js", | ||
| "version": "0.2.1", | ||
| "version": "0.2.2", | ||
| "dependencies": { | ||
| "assist.js": "~0.3.4" | ||
| }, | ||
| "ignore": [ | ||
@@ -5,0 +8,0 @@ "**/.*", |
| { | ||
| "assist" : "/node_modules/assist.js/dist/amd", | ||
| "proclaim" : "/node_modules/proclaim/lib/proclaim", | ||
| "sinon" : "/node_modules/sinon/pkg/sinon" | ||
| } |
+6
-46
@@ -7,3 +7,6 @@ /*! | ||
| define(function () { | ||
| define([ | ||
| 'assist/isEmpty', | ||
| 'assist/tmpl' | ||
| ], function (isEmpty, tmpl) { | ||
@@ -16,47 +19,4 @@ | ||
| return { | ||
| /** | ||
| * Determine if an object is empty. | ||
| * | ||
| * @example | ||
| * var isEmpty = isEmpty({}); | ||
| * // true | ||
| * | ||
| * @public | ||
| * | ||
| * @param {object} obj - obj to run isEmpty test on | ||
| * @reutns {boolean} - true if object is empty. false if not. | ||
| */ | ||
| isEmpty: function (obj) { | ||
| // Array | ||
| if (Object.prototype.toString.call(obj) === '[object Array]') { | ||
| return (obj.length > 0); | ||
| } | ||
| // Object | ||
| for(var prop in obj) { | ||
| if(obj.hasOwnProperty(prop)) { return false; } | ||
| } | ||
| return true; | ||
| }, | ||
| /** | ||
| * Micro template function. | ||
| * | ||
| * @example | ||
| * var msg = tmpl('{0}', ['msg']); | ||
| * | ||
| * @public | ||
| * | ||
| * @param {string} str - string to template. | ||
| * @param {array} data - array of values to template. | ||
| * @reutns {str} - error msg string. | ||
| */ | ||
| tmpl: function (str, data) { | ||
| return str.replace(/{([^{}]*)}/g, function(a, b) { | ||
| return typeof data[b] === 'string' ? data[b] : a; | ||
| }); | ||
| } | ||
| isEmpty: isEmpty, | ||
| tmpl: tmpl | ||
| }; | ||
@@ -63,0 +23,0 @@ |
+4
-46
@@ -7,5 +7,6 @@ /*! | ||
| var isEmpty = require('assist/isEmpty'); | ||
| var tmpl = require('assist/tmpl'); | ||
| /* ----------------------------------------------------------------------------- | ||
@@ -16,49 +17,6 @@ * utils | ||
| module.exports = { | ||
| /** | ||
| * Determine if an object is empty. | ||
| * | ||
| * @example | ||
| * var isEmpty = isEmpty({}); | ||
| * // true | ||
| * | ||
| * @public | ||
| * | ||
| * @param {object} obj - obj to run isEmpty test on | ||
| * @reutns {boolean} - true if object is empty. false if not. | ||
| */ | ||
| isEmpty: function (obj) { | ||
| // Array | ||
| if (Object.prototype.toString.call(obj) === '[object Array]') { | ||
| return (obj.length > 0); | ||
| } | ||
| // Object | ||
| for(var prop in obj) { | ||
| if(obj.hasOwnProperty(prop)) { return false; } | ||
| } | ||
| return true; | ||
| }, | ||
| /** | ||
| * Micro template function. | ||
| * | ||
| * @example | ||
| * var msg = tmpl('{0}', ['msg']); | ||
| * | ||
| * @public | ||
| * | ||
| * @param {string} str - string to template. | ||
| * @param {array} data - array of values to template. | ||
| * @reutns {str} - error msg string. | ||
| */ | ||
| tmpl: function (str, data) { | ||
| return str.replace(/{([^{}]*)}/g, function(a, b) { | ||
| return typeof data[b] === 'string' ? data[b] : a; | ||
| }); | ||
| } | ||
| isEmpty: isEmpty, | ||
| tmpl: tmpl | ||
| }; | ||
+44
-26
@@ -18,13 +18,24 @@ (function (root, factory) { | ||
| /*! | ||
| * utils.js | ||
| * isArray.js | ||
| * | ||
| * Copyright (c) 2014 | ||
| */ | ||
| var utils, customs, _checks_, _exam_; | ||
| utils = { | ||
| var assistIsArray, assistIsEmpty, assistTmpl, utils, customs, _checks_, _exam_; | ||
| assistIsArray = function (value) { | ||
| return Object.prototype.toString.call(value) === '[object Array]'; | ||
| }; | ||
| /*! | ||
| * isEmpty.js | ||
| * | ||
| * Copyright (c) 2014 | ||
| */ | ||
| assistIsEmpty = function (isArray) { | ||
| /* ----------------------------------------------------------------------------- | ||
| * isEmpty | ||
| * ---------------------------------------------------------------------------*/ | ||
| /** | ||
| * Determine if an object is empty. | ||
| * Determine if an object or array is empty. | ||
| * | ||
| * @example | ||
| * var isEmpty = isEmpty({}); | ||
| * var empty = isEmpty({}); | ||
| * // true | ||
@@ -37,6 +48,6 @@ * | ||
| */ | ||
| isEmpty: function (obj) { | ||
| return function (obj) { | ||
| // Array | ||
| if (Object.prototype.toString.call(obj) === '[object Array]') { | ||
| return obj.length > 0; | ||
| if (isArray(obj)) { | ||
| return obj.length === 0; | ||
| } | ||
@@ -50,22 +61,29 @@ // Object | ||
| return true; | ||
| }, | ||
| /** | ||
| * Micro template function. | ||
| * | ||
| * @example | ||
| * var msg = tmpl('{0}', ['msg']); | ||
| * | ||
| * @public | ||
| * | ||
| * @param {string} str - string to template. | ||
| * @param {array} data - array of values to template. | ||
| * @reutns {str} - error msg string. | ||
| */ | ||
| tmpl: function (str, data) { | ||
| return str.replace(/{([^{}]*)}/g, function (a, b) { | ||
| return typeof data[b] === 'string' ? data[b] : a; | ||
| }); | ||
| } | ||
| }; | ||
| }(assistIsArray); | ||
| /*! | ||
| * tmpl.js | ||
| * | ||
| * Copyright (c) 2014 | ||
| */ | ||
| assistTmpl = function (str, data) { | ||
| return str.replace(/{([^{}]*)}/g, function (a, b) { | ||
| return typeof data[b] === 'string' ? data[b] : a; | ||
| }); | ||
| }; | ||
| /*! | ||
| * utils.js | ||
| * | ||
| * Copyright (c) 2014 | ||
| */ | ||
| utils = function (isEmpty, tmpl) { | ||
| /* ----------------------------------------------------------------------------- | ||
| * utils | ||
| * ---------------------------------------------------------------------------*/ | ||
| return { | ||
| isEmpty: isEmpty, | ||
| tmpl: tmpl | ||
| }; | ||
| }(assistIsEmpty, assistTmpl); | ||
| /*! | ||
| * checks.js | ||
@@ -72,0 +90,0 @@ * |
@@ -1,1 +0,1 @@ | ||
| !function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=b()}):"object"==typeof exports?module.exports=b():a.Customs=b()}(this,function(){var a,b,c,d;return a={isEmpty:function(a){if("[object Array]"===Object.prototype.toString.call(a))return a.length>0;for(var b in a)if(a.hasOwnProperty(b))return!1;return!0},tmpl:function(a,b){return a.replace(/{([^{}]*)}/g,function(a,c){return"string"==typeof b[c]?b[c]:a})}},c=function(a){var b={numeric:/^[0-9]+$/,integer:/^\-?[0-9]+$/,decimal:/^\-?[0-9]*\.?[0-9]+$/,email:/^[a-zA-Z0-9.!#$%&'*+\-\/=?\^_`{|}~\-]+@[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*$/,alpha:/^[a-z]+$/i,alphaNumeric:/^[a-z0-9]+$/i,alphaDash:/^[a-z0-9_\-]+$/i,natural:/^[0-9]+$/i,naturalNoZero:/^[1-9][0-9]*$/i,ip:/^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$/i,base64:/[^a-zA-Z0-9\/\+=]/i,numericDash:/^[\d\-\s]+$/,url:/^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i},c={};return c.required={msg:"The {0} field is required.",check:function(b){return null!==b&&"object"==typeof b?a.isEmpty(b):null!==b&&""!==b}},c["default"]={msg:"The {0} field is still set to default, please change.",check:function(a,b){return a!==b}},c.email={msg:"The {0} field must contain a valid email address.",check:function(a){return b.email.test(a)}},c.emails={msg:"The {0} field must contain all valid email addresses.",check:function(a){for(var c=a.split(","),d=0;d<c.length;d++){var e=String(c[d]).replace(/^\s+|\s+$/g,"");if(!b.email.test(e))return!1}return!0}},c.minLength={msg:"The {0} field must be at least {1} characters in length.",check:function(a,c){return b.numeric.test(c)?a.length>=parseInt(c,10):!1}},c.maxLength={msg:"The {0} field must not exceed {1} characters in length.",check:function(a,c){return b.numeric.test(c)?a.length<=parseInt(c,10):!1}},c.exactLength={msg:"The {0} field must be exactly {1} characters in length.",check:function(a,c){return b.numeric.test(c)?a.length===parseInt(c,10):!1}},c.greaterThan={msg:"The {0} field must contain a number greater than {1}.",check:function(a,c){return b.decimal.test(a)?parseFloat(a)>parseFloat(c):!1}},c.lessThan={msg:"The {0} field must contain a number less than {1}.",check:function(a,c){return b.decimal.test(a)?parseFloat(a)<parseFloat(c):!1}},c.alpha={msg:"The {0} field must only contain alphabetical characters.",check:function(a){return b.alpha.test(a)}},c.alphaNumeric={msg:"The {0} field must only contain alpha-numeric characters.",check:function(a){return b.alphaNumeric.test(a)}},c.alphaDash={msg:"The {0} field must only contain alpha-numeric characters, underscores, and dashes.",check:function(a){return b.alphaDash.test(a)}},c.numeric={msg:"The {0} field must contain only numbers.",check:function(a){return b.numeric.test(a)}},c.integer={msg:"The {0} field must contain an integer.",check:function(a){return b.integer.test(a)}},c.decimal={msg:"The {0} field must contain a decimal number.",check:function(a){return b.decimal.test(a)}},c.natural={msg:"The {0} field must contain only positive numbers.",check:function(a){return b.natural.test(a)}},c.naturalNoZero={msg:"The {0} field must contain a number greater than zero.",check:function(a){return b.naturalNoZero.test(a)}},c.url={msg:"The {0} field must contain a valid URL.",check:function(a){return b.url.test(a)}},c.creditCard={msg:"The {0} field must contain a valid credit card number.",check:function(a){if(!b.numericDash.test(a))return!1;for(var c=a.replace(/[ -]+/g,""),d=c.length,e=0,f=0,g=[[0,1,2,3,4,5,6,7,8,9],[0,2,4,6,8,1,3,5,7,9]];d--;)f+=g[e][parseInt(c.charAt(d),10)],e^=1;return f%10===0&&f>0}},c.fileType={msg:"The {0} field must contain only {1} files.",check:function(a,b){for(var c=a.substr(a.lastIndexOf(".")+1),d=b.split(","),e=0;e<d.length;e++){var f=String(d[e]).replace(/^\s+|\s+$/g,"");if(c===f)return!0}return!1}},c}(a),d=function(a,b){var c=function(){this.isValid=!0,this.errors={}};return c.prototype.run=function(a,b){for(var c in a)b[c]&&this.checkRules(c,a[c],b[c])},c.prototype.checkRules=function(a,b,c){var d=[],e=""===b,f=c[0];if(e&&f&&"required"!==c[0].name)return!0;for(var g in c){var h=this.checkRule(a,b,c[g]);h&&d.push(h)}d.length&&(this.errors[a]=d)},c.prototype.checkRule=function(a,c,d){if(!b[d.name])throw new Error("There is no check defined by the name: "+d.name);return b[d.name].check(c,d.args)?null:this.formatError(a,d)},c.prototype.formatError=function(c,d){this.isValid=!1;var e=b[d.name].msg,f=[c];return d.args&&(f=f.concat([d.args])),{name:d.name,msg:a.tmpl(e,f)}},c}(a,c),b=function(a){var b=function(a){this.rules=this.build(a)};return b.prototype.build=function(a){var b={};for(var c in a)b[c]=this.buildRules(a[c]);return b},b.prototype.buildRules=function(a){for(var b=a.split("|"),c=[],d=0,e=b.length;e>d;d++){var f=this.parseRule(b[d]),g="required"===f.name?"unshift":"push";c[g](f)}return c},b.prototype.parseRule=function(a){var b=/^(.+?)\[(.+)\]$/.exec(a);return b?{name:b[1],args:b[2]}:{name:a}},b.prototype.check=function(b){var c=new a;return c.run(b,this.rules||{}),{isValid:c.isValid,errors:c.errors}},b}(d)}); | ||
| !function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=b()}):"object"==typeof exports?module.exports=b():a.Customs=b()}(this,function(){var a,b,c,d,e,f,g;return a=function(a){return"[object Array]"===Object.prototype.toString.call(a)},b=function(a){return function(b){if(a(b))return 0===b.length;for(var c in b)if(b.hasOwnProperty(c))return!1;return!0}}(a),c=function(a,b){return a.replace(/{([^{}]*)}/g,function(a,c){return"string"==typeof b[c]?b[c]:a})},d=function(a,b){return{isEmpty:a,tmpl:b}}(b,c),f=function(a){var b={numeric:/^[0-9]+$/,integer:/^\-?[0-9]+$/,decimal:/^\-?[0-9]*\.?[0-9]+$/,email:/^[a-zA-Z0-9.!#$%&'*+\-\/=?\^_`{|}~\-]+@[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*$/,alpha:/^[a-z]+$/i,alphaNumeric:/^[a-z0-9]+$/i,alphaDash:/^[a-z0-9_\-]+$/i,natural:/^[0-9]+$/i,naturalNoZero:/^[1-9][0-9]*$/i,ip:/^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$/i,base64:/[^a-zA-Z0-9\/\+=]/i,numericDash:/^[\d\-\s]+$/,url:/^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i},c={};return c.required={msg:"The {0} field is required.",check:function(b){return null!==b&&"object"==typeof b?a.isEmpty(b):null!==b&&""!==b}},c["default"]={msg:"The {0} field is still set to default, please change.",check:function(a,b){return a!==b}},c.email={msg:"The {0} field must contain a valid email address.",check:function(a){return b.email.test(a)}},c.emails={msg:"The {0} field must contain all valid email addresses.",check:function(a){for(var c=a.split(","),d=0;d<c.length;d++){var e=String(c[d]).replace(/^\s+|\s+$/g,"");if(!b.email.test(e))return!1}return!0}},c.minLength={msg:"The {0} field must be at least {1} characters in length.",check:function(a,c){return b.numeric.test(c)?a.length>=parseInt(c,10):!1}},c.maxLength={msg:"The {0} field must not exceed {1} characters in length.",check:function(a,c){return b.numeric.test(c)?a.length<=parseInt(c,10):!1}},c.exactLength={msg:"The {0} field must be exactly {1} characters in length.",check:function(a,c){return b.numeric.test(c)?a.length===parseInt(c,10):!1}},c.greaterThan={msg:"The {0} field must contain a number greater than {1}.",check:function(a,c){return b.decimal.test(a)?parseFloat(a)>parseFloat(c):!1}},c.lessThan={msg:"The {0} field must contain a number less than {1}.",check:function(a,c){return b.decimal.test(a)?parseFloat(a)<parseFloat(c):!1}},c.alpha={msg:"The {0} field must only contain alphabetical characters.",check:function(a){return b.alpha.test(a)}},c.alphaNumeric={msg:"The {0} field must only contain alpha-numeric characters.",check:function(a){return b.alphaNumeric.test(a)}},c.alphaDash={msg:"The {0} field must only contain alpha-numeric characters, underscores, and dashes.",check:function(a){return b.alphaDash.test(a)}},c.numeric={msg:"The {0} field must contain only numbers.",check:function(a){return b.numeric.test(a)}},c.integer={msg:"The {0} field must contain an integer.",check:function(a){return b.integer.test(a)}},c.decimal={msg:"The {0} field must contain a decimal number.",check:function(a){return b.decimal.test(a)}},c.natural={msg:"The {0} field must contain only positive numbers.",check:function(a){return b.natural.test(a)}},c.naturalNoZero={msg:"The {0} field must contain a number greater than zero.",check:function(a){return b.naturalNoZero.test(a)}},c.url={msg:"The {0} field must contain a valid URL.",check:function(a){return b.url.test(a)}},c.creditCard={msg:"The {0} field must contain a valid credit card number.",check:function(a){if(!b.numericDash.test(a))return!1;for(var c=a.replace(/[ -]+/g,""),d=c.length,e=0,f=0,g=[[0,1,2,3,4,5,6,7,8,9],[0,2,4,6,8,1,3,5,7,9]];d--;)f+=g[e][parseInt(c.charAt(d),10)],e^=1;return f%10===0&&f>0}},c.fileType={msg:"The {0} field must contain only {1} files.",check:function(a,b){for(var c=a.substr(a.lastIndexOf(".")+1),d=b.split(","),e=0;e<d.length;e++){var f=String(d[e]).replace(/^\s+|\s+$/g,"");if(c===f)return!0}return!1}},c}(d),g=function(a,b){var c=function(){this.isValid=!0,this.errors={}};return c.prototype.run=function(a,b){for(var c in a)b[c]&&this.checkRules(c,a[c],b[c])},c.prototype.checkRules=function(a,b,c){var d=[],e=""===b,f=c[0];if(e&&f&&"required"!==c[0].name)return!0;for(var g in c){var h=this.checkRule(a,b,c[g]);h&&d.push(h)}d.length&&(this.errors[a]=d)},c.prototype.checkRule=function(a,c,d){if(!b[d.name])throw new Error("There is no check defined by the name: "+d.name);return b[d.name].check(c,d.args)?null:this.formatError(a,d)},c.prototype.formatError=function(c,d){this.isValid=!1;var e=b[d.name].msg,f=[c];return d.args&&(f=f.concat([d.args])),{name:d.name,msg:a.tmpl(e,f)}},c}(d,f),e=function(a){var b=function(a){this.rules=this.build(a)};return b.prototype.build=function(a){var b={};for(var c in a)b[c]=this.buildRules(a[c]);return b},b.prototype.buildRules=function(a){for(var b=a.split("|"),c=[],d=0,e=b.length;e>d;d++){var f=this.parseRule(b[d]),g="required"===f.name?"unshift":"push";c[g](f)}return c},b.prototype.parseRule=function(a){var b=/^(.+?)\[(.+)\]$/.exec(a);return b?{name:b[1],args:b[2]}:{name:a}},b.prototype.check=function(b){var c=new a;return c.run(b,this.rules||{}),{isValid:c.isValid,errors:c.errors}},b}(g)}); |
+4
-1
@@ -5,3 +5,3 @@ { | ||
| "author": "Jarid Margolin <jarid@firstopinion.co>", | ||
| "version": "0.2.1", | ||
| "version": "0.2.2", | ||
| "homepage": "https://github.com/jaridmargolin/customs.js", | ||
@@ -19,2 +19,5 @@ "repository": { | ||
| "main": "dist/common/customs.js", | ||
| "dependencies": { | ||
| "assist.js": "~0.3.4" | ||
| }, | ||
| "devDependencies": { | ||
@@ -21,0 +24,0 @@ "easy-build": "~0.0.2", |
+6
-46
@@ -7,3 +7,6 @@ /*! | ||
| define(function () { | ||
| define([ | ||
| 'assist/isEmpty', | ||
| 'assist/tmpl' | ||
| ], function (isEmpty, tmpl) { | ||
@@ -16,47 +19,4 @@ | ||
| return { | ||
| /** | ||
| * Determine if an object is empty. | ||
| * | ||
| * @example | ||
| * var isEmpty = isEmpty({}); | ||
| * // true | ||
| * | ||
| * @public | ||
| * | ||
| * @param {object} obj - obj to run isEmpty test on | ||
| * @reutns {boolean} - true if object is empty. false if not. | ||
| */ | ||
| isEmpty: function (obj) { | ||
| // Array | ||
| if (Object.prototype.toString.call(obj) === '[object Array]') { | ||
| return (obj.length > 0); | ||
| } | ||
| // Object | ||
| for(var prop in obj) { | ||
| if(obj.hasOwnProperty(prop)) { return false; } | ||
| } | ||
| return true; | ||
| }, | ||
| /** | ||
| * Micro template function. | ||
| * | ||
| * @example | ||
| * var msg = tmpl('{0}', ['msg']); | ||
| * | ||
| * @public | ||
| * | ||
| * @param {string} str - string to template. | ||
| * @param {array} data - array of values to template. | ||
| * @reutns {str} - error msg string. | ||
| */ | ||
| tmpl: function (str, data) { | ||
| return str.replace(/{([^{}]*)}/g, function(a, b) { | ||
| return typeof data[b] === 'string' ? data[b] : a; | ||
| }); | ||
| } | ||
| isEmpty: isEmpty, | ||
| tmpl: tmpl | ||
| }; | ||
@@ -63,0 +23,0 @@ |
100276
-1.77%1
Infinity%2910
-2.81%+ Added
+ Added
+ Added