-
Notifications
You must be signed in to change notification settings - Fork 9
/
fieldval.min.js
1 lines (1 loc) · 21.7 KB
/
fieldval.min.js
1
var FieldVal=function(){"use strict";function r(e,n){var t=this;t.async_waiting=0,t.validating=e,t.invalid_keys={},t.recognized_keys={},t.errors=[],t.options=n||{},t.ignore_unrecognized=t.options.ignore_unrecognized;var o=t.options.error;if(void 0!==o)if(o){var i;if(o.error===r.ONE_OR_MORE_ERRORS)i=o;else if(o.error===r.MULTIPLE_ERRORS)for(var a=0;a<o.errors.length;a++){var c=o.errors[a];c.error!==r.ONE_OR_MORE_ERRORS?t.errors.push(c):i=c}else t.errors.push(o);if(i){for(var s in e)e.hasOwnProperty(s)&&(t.recognized_keys[s]=!0);if(i.unrecognized){t.unrecognized_keys=i.unrecognized;for(var u in t.unrecognized_keys)t.unrecognized_keys.hasOwnProperty(u)&&delete t.recognized_keys[u]}i.invalid&&(t.invalid_keys=i.invalid)}}else for(var _ in e)e.hasOwnProperty(_)&&(t.recognized_keys[_]=!0)}Array.isArray||(Array.isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)});var e=function(r){var e;for(e in r)if(r.hasOwnProperty(e))return!1;return!0};r.prototype.dig=function(){var e,n=this,t=arguments[0];e=Array.isArray(t)?t:arguments;for(var o=n.validating,i=n,a=0;a<e.length;a++){var c=e[a];if(o=o[c],void 0===o)return;if(i){var s;s=i instanceof r?i.invalid_keys:i.invalid,s&&(i=s[c])}}return new r(o,{error:i})},r.get_error=function(){var r,e=arguments[0],n=arguments[arguments.length-1];if("object"!=typeof n||Array.isArray(n))throw new Error("Last argument to .get_error is not an error");if(Array.isArray(e))r=e;else{r=[];for(var t=0;t<arguments.length-1;t++)r.push(arguments[t])}for(var o=n,i=0;i<r.length;i++){var a=r[i];if(o){var c=o.invalid;c&&(o=c[a])}}return o},r.prototype.error=function(){var e=this,n=arguments[arguments.length-1];1===arguments.length&&e.errors.push(n);var t,o;if(2===arguments.length){var i=arguments[0];if(!Array.isArray(i)){var a=arguments[0];return e.invalid_keys[a]=r.add_to_invalid(n,e.invalid_keys[a]),e}t=i,o=i.length}else t=arguments,o=arguments.length-1;for(var c=e,s=0;s<o;s++){var u,_=t[s];u=c instanceof r?c.invalid_keys:c.invalid;var l;l=s===o-1?n:u[_],l||(l={error:r.ONE_OR_MORE_ERRORS,error_message:r.ONE_OR_MORE_ERRORS_STRING}),c instanceof r?c.invalid(_,l):(u||(u=c.invalid={}),u[_]=r.add_to_invalid(l,u[_])),c=l}return e},r.prototype.invalid=r.prototype.error,r.prototype.get=function(e){var n,t=this,o=Array.prototype.slice.call(arguments,1),i=!1,a=t.get_async(e,o,function(r){i=!0,n=r});if(a===r.ASYNC)throw new Error(".get used with async checks, use .get_async.");return n},r.prototype.get_async=function(e,n,t){var o=this;if(!Array.isArray(n))throw new Error(".get_async second argument must be an array of checks");var i=o.validating[e];o.recognized_keys[e]=!0;var a=o.invalid_keys[e];void 0!==a&&void 0!==a.error&&a.error===r.FIELD_UNRECOGNIZED&&delete o.invalid_keys[e];var c=r.use_checks(i,n,{validator:o,field_name:e,emit:function(r){i=r}},function(r){void 0!==t&&t(i)});return c===r.ASYNC?r.ASYNC:void 0},r.add_to_invalid=function(e,n){if(void 0!==n){if(void 0!==n.errors){for(var t=0;t<n.errors.length;t++){var o=n.errors;void 0!==o.error&&o.error===e.error&&(n.errors[t]=e)}n.errors.push(e)}else n=void 0!==n.error&&n.error===e.error?e:{error:r.MULTIPLE_ERRORS,error_message:r.MULTIPLE_ERRORS_STRING,errors:[n,e]};return n}return e},r.prototype.missing=function(e,n){var t=this;return t.error(e,r.create_error(r.MISSING_ERROR,n))},r.prototype.unrecognized=function(e,n){var t=this;return t.error(e,r.create_error(r.UNRECOGNIZED_ERROR,n))},r.prototype.recognized=function(r){var e=this;return e.recognized_keys[r]=!0,e},r.prototype.get_unrecognized=function(){var r,e=this,n=[];for(r in e.validating)e.validating.hasOwnProperty(r)&&e.recognized_keys[r]!==!0&&n.push(r);return n},r.prototype.async_call_ended=function(){var r=this;r.async_waiting--,r.async_waiting<=0&&r.end_callback&&r.end_callback(r.generate_response())},r.prototype.generate_response=function(){var n,t=this,o={},i=!1,a={},c={};for(n in t.unrecognized_keys)t.unrecognized_keys.hasOwnProperty(n)&&(a[n]=t.unrecognized_keys[n]);if(!t.ignore_unrecognized){var s,u,_=t.get_unrecognized();for(s=0;s<_.length;s++)u=_[s],c[u]={error_message:"Unrecognized field.",error:r.FIELD_UNRECOGNIZED},i=!0;if(!e(t.invalid_keys)){for(var l in t.invalid_keys)t.invalid_keys.hasOwnProperty(l)&&(c[l]=t.invalid_keys[l]);i=!0}}if(i&&(o.invalid=c),i){if(o.error_message=r.ONE_OR_MORE_ERRORS_STRING,o.error=r.ONE_OR_MORE_ERRORS,0===t.errors.length)return o;t.errors.push(o)}return 0!==t.errors.length?1===t.errors.length?t.errors[0]:{error:r.MULTIPLE_ERRORS,error_message:"Multiple errors.",errors:t.errors}:null},r.prototype.end=function(r){var e=this;return r?(e.end_callback=r,void(e.async_waiting<=0&&r(e.generate_response()))):e.generate_response()},r.prototype.end_with_recognized=function(r){var e=this;if(r)e.end(r);else if(e.async_waiting>0)return[e.generate_response()]},r.ASYNC=-1,r.NOT_REQUIRED_BUT_MISSING=Math.floor,r.FIELD_MISSING=1,r.FIELD_MISSING_STRING="Field missing.",r.INCORRECT_FIELD_TYPE=2,r.FIELD_UNRECOGNIZED=3,r.FIELD_UNRECOGNIZED_STRING="Unrecognized field.",r.MULTIPLE_ERRORS=4,r.MULTIPLE_ERRORS_STRING="Multiple errors.",r.ONE_OR_MORE_ERRORS=5,r.ONE_OR_MORE_ERRORS_STRING="One or more errors.",r.INCORRECT_TYPE_ERROR=function(e,n){return{error_message:"Incorrect field type. Expected "+e+", but received "+n+".",error:r.INCORRECT_FIELD_TYPE,expected:e,received:n}},r.MISSING_ERROR=function(){return{error_message:r.FIELD_MISSING_STRING,error:r.FIELD_MISSING}},r.UNRECOGNIZED_ERROR=function(){return{error_message:r.FIELD_UNRECOGNIZED_STRING,error:r.FIELD_UNRECOGNIZED}},r.get_value_and_type=function(r,e,n){n||(n={});var t=void 0!==n.parse&&n.parse;if("string"!=typeof r||t)if("integer"===e){var o=parseInt(r,10);isNaN(o)||o.toString().length!==r.toString().length||(r=o,e=o,e="number")}else if("number"===e){var i=parseFloat(r,10);isNaN(i)||i.toString().length!==r.toString().length||(r=i,e="number")}else"boolean"===e&&("true"===r&&(r=!0),"false"===r&&(r=!1));var a=typeof r;return"object"===a&&Array.isArray(r)&&(a="array"),{type:a,desired_type:e,value:r}},r.use_check=function(e,n,t){var o,i=!0,a={},c=0;if("object"==typeof e){if(Array.isArray(e)){var s=!1,u=e,_=!1,l=function(){if(c++,n.stop||c>u.length)return _=!0,void t();var e=r.use_check(u[c-1],n,function(){l()});e===r.ASYNC&&(s=!0)};return l(),_?s?r.ASYNC:void 0:r.ASYNC}a=e,o=a,a&&void 0!==a.stop_on_error&&(i=a.stop_on_error)}else{if("function"!=typeof e)throw new Error("A check can only be provided as a function or as an object with a function as the .check property.");o=e,i=!0}var f,d,v=function(e){if(null!==e&&void 0!==e){if(i&&(n.stop=!0),n.had_error=!0,e!==r.NOT_REQUIRED_BUT_MISSING)return void 0!==n.field_name?(n.validator.error(n.field_name,e),void t()):(n.validator.error(e),void t());t()}else t()};return"function"==typeof o?(d=o,f=o(n.value,n.emit,function(r){v(r)})):(d=o.check,f=o.check(n.value,n.emit,function(r){v(r)})),3===d.length?r.ASYNC:(v(f),null)},r.use_checks=function(e,n,t,o){"function"==typeof t&&(o=t,t=void 0),t||(t={});var i={value:e,field_name:t.field_name,emit:function(r){i.value=r},options:t,stop:!1,had_error:!1};t.validator?(i.validator=t.validator,i.existing_validator=!0):i.validator=new r;var a,c=!1,s=function(r){a=r,c=!0,o&&o(r)};i.validator.async_waiting++;var u=r.use_check(n||[],i,function(){return i.had_error?i.options.emit&&i.options.emit(void 0):i.options.emit&&i.options.emit(i.value),i.existing_validator?(s(null),void i.validator.async_call_ended()):(s(i.validator.end()),void i.validator.async_call_ended())});return u===r.ASYNC?(o&&(s=o),r.ASYNC):c?a:r.ASYNC},r.merge_options_and_checks=function(r,e){var n={};if(r)for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t]);return n.check=e,n},r.required=function(e,n){var t=function(t){if(null===t||void 0===t)return e||void 0===e?r.create_error(r.MISSING_ERROR,n):r.NOT_REQUIRED_BUT_MISSING};return r.merge_options_and_checks(n,t)},r.type=function(e,n){var t=!n||void 0===n.required||n.required,o=function(o,i){var a=r.required(t,n||{}).check(o);if(a)return a;var c=r.get_value_and_type(o,e,n),s=c.desired_type,u=c.type;return o=c.value,u!==s?r.create_error(r.INCORRECT_TYPE_ERROR,n,s,u):void(i&&i(o))};return r.merge_options_and_checks(n,o)},r.create_error=function(e,n){if(!n)return e.apply(null,Array.prototype.slice.call(arguments,2));if(e===r.MISSING_ERROR){var t=typeof n.missing_error;if("function"===t)return n.missing_error.apply(null,Array.prototype.slice.call(arguments,2));if("object"===t)return n.missing_error;if("string"===t)return{error_message:n.missing_error}}else{var o=typeof n.error;if("function"===o)return n.error.apply(null,Array.prototype.slice.call(arguments,2));if("object"===o)return n.error;if("string"===o)return{error_message:n.error}}return e.apply(null,Array.prototype.slice.call(arguments,2))};var n=function(){var e={errors:{invalid_date_format:function(r){return{error:111,error_message:"Invalid date format.",format:r}},invalid_date:function(){return{error:112,error_message:"Invalid date."}},invalid_date_format_string:function(){return{error:114,error_message:"Invalid date format string."}},invalid_date_format_array:function(){return{error:121,error_message:"Invalid date format array."}}},date_format_array:function(n){n=n||{};var t=function(t,o){for(var i=0;i<t.length;i++)if(void 0===e.date_components[t[i]])return r.create_error(e.errors.invalid_date_format_array,n);o(t)};return n?(n.check=t,n):{check:t}},date_format:function(n){n=n||{};var t=function(t,o){for(var i=[],a=0,c=!1;a<t.length&&!c;){var s=!1;for(var u in e.date_components){var _=t.substring(a,a+u.length);if(_===u){i.push(u),a+=u.length,s=!0;break}}if(!s)return r.create_error(e.errors.invalid_date_format_string,n)}o(n.emit==e.EMIT_STRING?t:i)};return n?(n.check=t,n):{check:t}},date_with_format_array:function(n,o){var i=r.use_checks(o,[t.array(!0),t.each(function(r,e,n){return t.string(!0,{trim:!1}).check(r)}),e.date_format_array()]);if(null!==i)throw new Error("Not a valid date format: "+JSON.stringify(i));for(var a="",c=0;c<o.length;c++){var s=o[c],u=e.date_components[s];if(0===u)a+=s;else{var _;"yyyy"===s?_=n.getUTCFullYear():"yy"===s?_=n.getUTCFullYear().toString().substring(2):"MM"===s||"M"===s?_=n.getUTCMonth()+1:"dd"===s||"d"===s?_=n.getUTCDate():"hh"===s||"h"===s?_=n.getUTCHours():"mm"===s||"m"===s?_=n.getUTCMinutes():"ss"!==s&&"s"!==s||(_=n.getUTCSeconds()),a+=e.pad_to_valid(_.toString(),u)}}return a},pad_to_valid:function(r,e){var n,o=t.integer({parse:!0}).check(r,function(r){n=r});if(o||n<0)return r;for(var i=0;i<e.length;i++){var a=e[i];if(r.length<=a){for(var c=a-r.length,s=0;s<c;s++)r="0"+r;return r}}return r},date:function(n,t){t=t||{};var o,i=e.date_format().check(n,function(r){o=r});i&&console.error&&console.error(i.error_message);var a=function(i,a){for(var c={},s=[],u=0,_=null,l=null,f=-1,d=!1;u<i.length&&!d;)if(f++,_=o[f],l=e.date_components[_],0!==l){for(var v=l[0],h=l[l.length-1],g="",y=0;y<h;y++){var p=i[u+y];if(void 0===p){y<v&&(d=!0);break}var m=p.charCodeAt(0);if(m<48||m>57){if(y===v)break;d=!0;break}g+=p}if(u+=y,d)break;var R=parseInt(g);s.push(g),"yyyy"===_||"yy"===_?c.year=R:"MM"===_||"M"===_?c.month=R:"dd"===_||"d"===_?c.day=R:"hh"===_||"h"===_?c.hour=R:"mm"===_||"m"===_?c.minute=R:"ss"!==_&&"s"!==_||(c.second=R)}else{if(i[u]!==_){d=!0;break}s.push(null),u++}if(d||f<o.length-1)return r.create_error(e.errors.invalid_date_format,t,n);if(void 0!==c.hour&&(c.hour<0||c.hour>23))return r.create_error(e.errors.invalid_date,t);if(void 0!==c.minute&&(c.minute<0||c.minute>59))return r.create_error(e.errors.invalid_date,t);if(void 0!==c.second&&(c.second<0||c.second>59))return r.create_error(e.errors.invalid_date,t);if(void 0!==c.month){var k=c.month;if(k>12)return r.create_error(e.errors.invalid_date,t);if(k<1)return r.create_error(e.errors.invalid_date,t);if(c.day){var E=c.day;if(E<1)return r.create_error(e.errors.invalid_date,t);if(c.year){var O=c.year;if(2==k)if(O%400===0||O%100!==0&&O%4===0){if(E>29)return r.create_error(e.errors.invalid_date,t)}else if(E>28)return r.create_error(e.errors.invalid_date,t)}if(4===k||6===k||9===k||11===k){if(E>30)return r.create_error(e.errors.invalid_date,t)}else if(2===k){if(E>29)return r.create_error(e.errors.invalid_date,t)}else if(E>31)return r.create_error(e.errors.invalid_date,t)}}else if(c.day){if(c.day>31)return r.create_error(e.errors.invalid_date,t);if(c.day<1)return r.create_error(e.errors.invalid_date,t)}if(t.emit)if(t.emit===e.EMIT_COMPONENT_ARRAY)a(s);else if(t.emit===e.EMIT_OBJECT)a(c);else if(t.emit===e.EMIT_DATE){var I=new Date(0);I.setUTCFullYear(0),void 0!==c.year&&I.setYear(c.year),void 0!==c.month&&I.setUTCMonth(c.month-1),void 0!==c.day&&I.setUTCDate(c.day),void 0!==c.hour&&I.setUTCHours(c.hour),void 0!==c.minute&&I.setUTCMinutes(c.minute),void 0!==c.second&&I.setUTCSeconds(c.second),a(I)}};return t?(t.check=a,t):{check:a}}};return e.EMIT_COMPONENT_ARRAY={},e.EMIT_DATE={},e.EMIT_OBJECT={},e.EMIT_STRING={},e.date_components={yyyy:[4],yy:[2],MM:[2],M:[1,2],dd:[2],d:[1,2],hh:[2],h:[1,2],mm:[2],m:[1,2],ss:[2],s:[1,2]," ":0,"-":0,"/":0,":":0},e}.call(),t=function(){Array.prototype.indexOf||(Array.prototype.indexOf=function(r,e){var n;if(null===this)throw new TypeError('"this" is null or not defined');var t=Object(this),o=t.length>>>0;if(0===o)return-1;var i=+e||0;if(Math.abs(i)===1/0&&(i=0),i>=o)return-1;for(n=Math.max(i>=0?i:o-Math.abs(i),0);n<o;){if(n in t&&t[n]===r)return n;n++}return-1});var e={errors:{too_short:function(r){return{error:100,error_message:"Length is less than "+r,min_length:r}},too_long:function(r){return{error:101,error_message:"Length is greater than "+r,max_length:r}},too_small:function(r){return{error:102,error_message:"Value is less than "+r,minimum:r}},too_large:function(r){return{error:103,error_message:"Value is greater than "+r,maximum:r}},not_in_list:function(){return{error:104,error_message:"Value is not a valid choice"}},cannot_be_empty:function(){return{error:105,error_message:"Value cannot be empty."}},no_prefix:function(r){return{error:106,error_message:"Value does not have prefix: "+r,prefix:r}},invalid_email:function(){return{error:107,error_message:"Invalid email address format."}},invalid_url:function(){return{error:108,error_message:"Invalid url format."}},incorrect_length:function(r){return{error:109,error_message:"Length is not equal to "+r,length:r}},no_suffix:function(r){return{error:110,error_message:"Value does not have suffix: "+r,suffix:r}},not_equal:function(r){return{error:113,error_message:"Not equal to "+r+".",equal:r}},no_valid_option:function(){return{error:115,error_message:"None of the options were valid."}},contains_whitespace:function(){return{error:116,error_message:"Contains whitespace."}},must_start_with_letter:function(){return{error:117,error_message:"Must start with a letter."}},value_in_list:function(){return{error:118,error_message:"Value not allowed"}},should_not_contain:function(r){var e=r.join(",");return{error:119,error_message:"Cannot contain "+e,cannot_contain:r}},invalid_domain:function(){return{error:120,error_message:"Invalid domain format."}}},equal_to:function(n,t){var o=function(o){if(o!==n)return r.create_error(e.errors.not_equal,t,n)};return t?(t.check=o,t):{check:o}},merge_required_and_options:function(r,e){var n={};"object"==typeof r?(e=r,r=void 0):e||(e={});for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t]);return void 0!==r&&(n.required=r),n},integer:function(n,t){return r.type("integer",e.merge_required_and_options(n,t))},number:function(n,t){return r.type("number",e.merge_required_and_options(n,t))},array:function(n,t){return r.type("array",e.merge_required_and_options(n,t))},object:function(n,t){return r.type("object",e.merge_required_and_options(n,t))},"boolean":function(n,t){return r.type("boolean",e.merge_required_and_options(n,t))},string:function(n,t){t=e.merge_required_and_options(n,t);var o=function(e,o){var i=r.type("string",t);"object"==typeof i&&(i=i.check);var a=i(e,o);return a?a:(t&&t.trim===!1||(e=e.trim()),0===e.length?n||void 0===n?r.create_error(r.MISSING_ERROR,t):r.NOT_REQUIRED_BUT_MISSING:void 0)};return t?(t.check=o,t):{check:o}},length:function(n,t){var o=function(o){if(o.length!==n)return r.create_error(e.errors.incorrect_length,t,n)};return t?(t.check=o,t):{check:o}},min_length:function(n,t){var o=function(o){if(o.length<n)return r.create_error(e.errors.too_short,t,n)};return t?(t.check=o,t):{check:o}},max_length:function(n,t){var o=function(o){if(o.length>n)return r.create_error(e.errors.too_long,t,n)};return t?(t.check=o,t):{check:o}},no_whitespace:function(n){var t=function(t){if(/\s/.test(t))return r.create_error(e.errors.contains_whitespace,n)};return n?(n.check=t,n):{check:t}},minimum:function(n,t){var o=function(o){if(o<n)return r.create_error(e.errors.too_small,t,n)};return t?(t.check=o,t):{check:o}},maximum:function(n,t){var o=function(o){if(o>n)return r.create_error(e.errors.too_large,t,n)};return t?(t.check=o,t):{check:o}},range:function(n,t,o){var i=function(i){return i<n?r.create_error(e.errors.too_small,o,n):i>t?r.create_error(e.errors.too_large,o,t):void 0};return o?(o.check=i,o):{check:i}},does_not_contain:function(n,t){Array.isArray(n)||(n=[n]);var o=function(o){for(var i=0;i<n.length;i++)if(o.indexOf(n[i])!==-1)return r.create_error(e.errors.should_not_contain,t,n)};return t?(t.check=o,t):{check:o}},one_of:function(n,t){var o=[];if(Array.isArray(n))for(var i=0;i<n.length;i++){var a=n[i];null!==a&&"object"==typeof a?o.push(a[0]):o.push(a)}else for(var c in n)n.hasOwnProperty(c)&&o.push(c);var s=function(n){if(o.indexOf(n)===-1)return r.create_error(e.errors.not_in_list,t)};return t?(t.check=s,t):{check:s}},not_one_of:function(n,t){var o=[];if("[object Array]"===Object.prototype.toString.call(n))for(var i=0;i<n.length;i++){var a=n[i];"object"==typeof a?o.push(a[0]):o.push(a)}else for(var c in n)n.hasOwnProperty(c)&&o.push(c);var s=function(n){if(o.indexOf(n)!==-1)return r.create_error(e.errors.value_in_list,t)};return t?(t.check=s,t):{check:s}},not_empty:function(n,t){var o=function(o){if(n){if(0===o.trim().length)return r.create_error(e.errors.cannot_be_empty,t)}else if(0===o.length)return r.create_error(e.errors.cannot_be_empty,t)};return t?(t.check=o,t):{check:o}},prefix:function(n,t){var o=function(o){return o.length>=n.length?o.substring(0,n.length)!=n?r.create_error(e.errors.no_prefix,t,n):void 0:r.create_error(e.errors.no_prefix,t,n)};return t?(t.check=o,t):{check:o}},start_with_letter:function(n){var t=function(t){if(!(t.length>0))return r.create_error(e.errors.must_start_with_letter,n);var o=t.charCodeAt(0);return o>=65&&o<=90||o>=97&&o<=122?void 0:r.create_error(e.errors.must_start_with_letter,n)};return n?(n.check=t,n):{check:t}},suffix:function(n,t){var o=function(o){return o.length>=n.length?o.substring(o.length-n.length,o.length)!=n?r.create_error(e.errors.no_suffix,t,n):void 0:r.create_error(e.errors.no_suffix,t,n)};return t?(t.check=o,t):{check:o}},date:n.date,date_format:n.date_format,date_format_array:n.date_format_array,each:function(e,n){var t=function(n,t){var o=new r(null),i=function(t){var i=n[t],a=e(i,t,function(r){n[t]=r});if(a===r.ASYNC)throw new Error(".each used with async checks, use .each_async.");a&&o.invalid(""+t,a)};if(Array.isArray(n))for(var a=0;a<n.length;a++)i(a);else for(var c in n)n.hasOwnProperty(c)&&i(c);var s=o.end();if(s)return s};return n?(n.check=t,n):{check:t}},each_async:function(e,n){var t=function(n,t,o){var i,a=Array.isArray(n);a||(i=Object.keys(n));var c,s,u=new r(null),_=0;a&&(c=_);var l=function(){if(a){if(c++,c>n.length)return void o(u.end());s=n[c-1]}else{if(_++,_>i.length)return void o(u.end());c=i[_-1],s=n[c]}r.use_checks(s,[function(r,n,t){e(r,c,n,t)}],{field_name:a?""+(c-1):c,validator:u,emit:function(r){a?n[c-1]=r:n[c]=r}},function(r){l()})};l()};return n?(n.check=t,n):{check:t}},multiple:function(n,t){n=n||[],0===n.length&&console.error("BasicVal.multiple called without possibles.");var o=function(o,i){for(var a=0;a<n.length;a++){var c,s=n[a],u=r.use_checks(o,s,{emit:function(r){c=r}});if(u===r.ASYNC)throw new Error(".multiple used with async checks, use .multiple_async.");if(!u)return void 0!==c&&i(c),null}return r.create_error(e.errors.no_valid_option,t)};return t?(t.check=o,t):{check:o}},multiple_async:function(n,t){if(n=n||[],0===n.length)return void console.error("BasicVal.multiple_async called without possibles.");var o,i=function(i,a,c){var s,u=function(r){s=r},_=0,l=function(){if(_++,_>n.length)return void c(r.create_error(e.errors.no_valid_option,t));var o=n[_-1];r.use_checks(i,o,{field_name:null,validator:null,emit:u},function(r){r?l():c(void 0)})};return l(),o};return t?(t.check=i,t):{check:i}},email:function(n,t){t=e.merge_required_and_options(n,t);var o=function(n){var o=e.string(t).check(n);if(void 0!==o)return o;var i=e.email_regex;return i.test(n)?void 0:r.create_error(e.errors.invalid_email,t)};return t?(t.check=o,t):{check:o}},url:function(n,t){t=e.merge_required_and_options(n,t);var o=function(n){var o=e.string(t).check(n);if(void 0!==o)return o;var i=e.url_regex;return i.test(n)?void 0:r.create_error(e.errors.invalid_url,t)};return t?(t.check=o,t):{check:o}},domain:function(n,t){t=e.merge_required_and_options(n,t);var o=function(n){var o=e.string(t).check(n);if(void 0!==o)return o;var i=e.domain_regex;return i.test(n)?void 0:r.create_error(e.errors.invalid_domain,t)};return t?(t.check=o,t):{check:o}},required:r.required};return e.email_regex=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,e.url_regex=/^(https?):\/\/(((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])))(:[1-9][0-9]+)?(\/)?([\/?].+)?$/,e.domain_regex=/^(https?):\/\/(((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])))(:[1-9][0-9]+)?(\/)?$/,e}.call();return r.DateVal=n,r.BasicVal=t,r}.call();"undefined"!=typeof module?module.exports=FieldVal:(BasicVal=FieldVal.BasicVal,DateVal=FieldVal.DateVal);