Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fieldval

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fieldval - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

8

docs/fieldval.json

@@ -14,4 +14,4 @@ {

"js_external": "__CURRENT_DOMAIN__/demo_files/fieldval.js",
"runnable_contents": "var data = {\n\t\"my_email\": \"almost@@example.com\",\n \"my_integer\": \"clearly not an integer\",\n \"multiple_of_three\": 8\n}\n\nvar validator = new FieldVal(data);\nvalidator.get(\"my_email\", BasicVal.email(true)());\nvalidator.get(\"my_integer\", BasicVal.integer(true));\nvalidator.get(\"multiple_of_three\", BasicVal.integer(true), function(val){\n if(val % 3 !== 0){\n return {\n \"error_message\": \"Not a multiple of three\",\n \"error\": 1000\n }\n }\n});\n\ndocument.write(\"<pre>\"+JSON.stringify(validator.end(),null,4)+\"</pre>\");",
"contents": "var validator = new FieldVal(data);\nvalidator.get(\"my_email\", BasicVal.email(true)());\nvalidator.get(\"my_integer\", BasicVal.integer(true));\nvalidator.get(\"multiple_of_three\", BasicVal.integer(true), function(val){\n if(val % 3 !== 0){\n return {\n \"error_message\": \"Not a multiple of three\",\n \"error\": 1000\n }\n }\n});\n\nconsole.log(validator.end());"
"runnable_contents": "var data = {\n\t\"my_email\": \"almost@@example.com\",\n \"my_integer\": \"clearly not an integer\",\n \"multiple_of_three\": 8\n}\n\nvar validator = new FieldVal(data);\nvalidator.get(\"my_email\", BasicVal.email(true));\nvalidator.get(\"my_integer\", BasicVal.integer(true));\nvalidator.get(\"multiple_of_three\", BasicVal.integer(true), function(val){\n if(val % 3 !== 0){\n return {\n \"error_message\": \"Not a multiple of three\",\n \"error\": 1000\n }\n }\n});\n\ndocument.write(\"<pre>\"+JSON.stringify(validator.end(),null,4)+\"</pre>\");",
"contents": "var validator = new FieldVal(data);\nvalidator.get(\"my_email\", BasicVal.email(true));\nvalidator.get(\"my_integer\", BasicVal.integer(true));\nvalidator.get(\"multiple_of_three\", BasicVal.integer(true), function(val){\n if(val % 3 !== 0){\n return {\n \"error_message\": \"Not a multiple of three\",\n \"error\": 1000\n }\n }\n});\n\nconsole.log(validator.end());"
}

@@ -34,3 +34,3 @@ ],

{
"contents": "<script type=\"text/javascript\" src=\"/PATH_TO/fieldval.js\"></script>script>\n<script type=\"text/javascript\">\n\nvar validator = new FieldVal({\n\t\"my_key\": 37\n})\n\nvar my_key = validator.get(\"my_key\", BasicVal.integer(true), BasicVal.minimum(40));\n\nconsole.log(validator.end());\n\n</script>"
"contents": "<script type=\"text/javascript\" src=\"/PATH_TO/fieldval.js\"></script>\n<script type=\"text/javascript\">\n\nvar validator = new FieldVal({\n\t\"my_key\": 37\n})\n\nvar my_key = validator.get(\"my_key\", BasicVal.integer(true), BasicVal.minimum(40));\n\nconsole.log(validator.end());\n\n</script>"
}

@@ -95,3 +95,3 @@ ],

{
"contents": "var validator = new FieldVal(val);\nvalidator.get(\"name\", BasicVal.string(true));\nvalidator.get(\"email\", BasicVal.email(true)());\nvalidator.get(\"enquiry\", BasicVal.object(true), function(enquiry){\n var inner_validator = new FieldVal(enquiry);\n inner_validator.get(\"type\", BasicVal.string(true), BasicVal.one_of([\"One\",\"Two\"]))\n inner_validator.get(\"message\", BasicVal.string(true))\n return inner_validator.end();\n});\n\nvalidator.end();"
"contents": "var validator = new FieldVal(val);\nvalidator.get(\"name\", BasicVal.string(true));\nvalidator.get(\"email\", BasicVal.email(true));\nvalidator.get(\"enquiry\", BasicVal.object(true), function(enquiry){\n var inner_validator = new FieldVal(enquiry);\n inner_validator.get(\"type\", BasicVal.string(true), BasicVal.one_of([\"One\",\"Two\"]))\n inner_validator.get(\"message\", BasicVal.string(true))\n return inner_validator.end();\n});\n\nvalidator.end();"
}

@@ -98,0 +98,0 @@ ],

@@ -1,1 +0,1 @@

var FieldVal=function(){"use strict";function r(e,n){var t=this;if(t.async_waiting=0,t.validating=e,t.invalid_keys={},t.recognized_keys={},t.errors=[],void 0!==n)if(n){var o;if(n.error===r.ONE_OR_MORE_ERRORS)o=n;else if(n.error===r.MULTIPLE_ERRORS)for(var i=0;i<n.errors.length;i++){var a=n.errors[i];a.error!==r.ONE_OR_MORE_ERRORS?t.errors.push(a):o=a}else t.errors.push(n);if(o){for(var s in e)e.hasOwnProperty(s)&&(t.recognized_keys[s]=!0);if(o.unrecognized){t.unrecognized_keys=o.unrecognized;for(var u in t.unrecognized_keys)t.unrecognized_keys.hasOwnProperty(u)&&delete t.recognized_keys[u]}o.invalid&&(t.invalid_keys=o.invalid)}}else for(var c in e)e.hasOwnProperty(c)&&(t.recognized_keys[c]=!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 s=e[a];if(o=o[s],void 0===o)return void 0;if(i){var u;u=i instanceof r?i.invalid_keys:i.invalid,u&&(i=u[s])}}return new r(o,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 s=o.invalid;s&&(o=s[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 s=e,u=0;o>u;u++){var c,_=t[u];c=s instanceof r?s.invalid_keys:s.invalid;var l;l=u===o-1?n:c[_],l||(l={error:r.ONE_OR_MORE_ERRORS,error_message:r.ONE_OR_MORE_ERRORS_STRING}),s instanceof r?s.invalid(_,l):(c||(c=s.invalid={}),c[_]=r.add_to_invalid(l,c[_])),s=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 s=r.use_checks(i,n,{validator:o,field_name:e,emit:function(r){i=r}},function(){void 0!==t&&t(i)});return s===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={},s={};for(n in t.unrecognized_keys)t.unrecognized_keys.hasOwnProperty(n)&&(a[n]=t.unrecognized_keys[n]);var u,c,_=t.get_unrecognized();for(u=0;u<_.length;u++)c=_[u],s[c]={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)&&(s[l]=t.invalid_keys[l]);i=!0}if(i&&(o.invalid=s),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.REQUIRED_ERROR=Math.sqrt,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:!1;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={},s=0;if("object"==typeof e){if(Array.isArray(e)){var u=!1,c=e,_=!1,l=function(){if(s++,n.stop||s>c.length)return _=!0,void t();var e=r.use_check(c[s-1],n,function(){l()});e===r.ASYNC&&(u=!0)};return l(),_?u?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 d,f,v=function(e){if(null!==e&&void 0!==e){if(i&&(n.stop=!0),n.had_error=!0,e===r.REQUIRED_ERROR)return void 0!==n.field_name?(n.validator.error(n.field_name,r.create_error(r.MISSING_ERROR,a)),void t()):n.existing_validator?(n.validator.error(r.create_error(r.MISSING_ERROR,a)),void t()):(n.return_missing=!0,void t());e===r.NOT_REQUIRED_BUT_MISSING?t():n.existing_validator?(void 0!==n.field_name?n.validator.invalid(n.field_name,e):n.validator.error(e),t()):(n.validator.error(e),t())}else t()};return"function"==typeof o?(f=o,d=o(n.value,n.emit,function(r){v(r)})):(f=o.check,d=o.check(n.value,n.emit,function(r){v(r)})),3===f.length?r.ASYNC:(v(d),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,return_missing:!1,had_error:!1};t.validator?(i.validator=t.validator,i.existing_validator=!0):i.validator=new r;var a,s=!1,u=function(r){a=r,s=!0,o&&o(r)};i.validator.async_waiting++;var c=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.return_missing?(u(r.REQUIRED_ERROR),void i.validator.async_call_ended()):i.existing_validator?(u(null),void i.validator.async_call_ended()):(u(i.validator.end()),void i.validator.async_call_ended())});return c===r.ASYNC?(o&&(u=o),r.ASYNC):s?a:r.ASYNC},r.required=function(e,n){var t=function(n){return null===n||void 0===n?e||void 0===e?r.REQUIRED_ERROR:r.NOT_REQUIRED_BUT_MISSING:void 0};return void 0!==n?(n.check=t,n):t},r.type=function(e,n){var t=n&&void 0!==n.required?n.required:!0,o=function(o,i){var a=r.required(t)(o);if(a)return a;var s=r.get_value_and_type(o,e,n),u=s.desired_type,c=s.type;return o=s.value,c!==u?r.create_error(r.INCORRECT_TYPE_ERROR,n,u,c):void(i&&i(o))};return void 0!==n?(n.check=o,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(){return{error:111,error_message:"Invalid date format."}},invalid_date:function(){return{error:112,error_message:"Invalid date."}},invalid_date_format_string:function(){return{error:114,error_message:"Invalid date format string."}}},date_format:function(n){n=n||{};var t=function(t,o){for(var i=[],a=0,s=!1;a<t.length&&!s;){var u=!1;for(var c in e.date_components){var _=t.substring(a,a+c.length);if(_===c){i.push(c),a+=c.length,u=!0;break}}u||(s=!0)}return s?r.create_error(e.errors.invalid_date_format_string,n):void o(n.emit==e.EMIT_STRING?t:i)};return n?(n.check=t,n):{check:t}},date_with_format_array:function(r,n){for(var t="",o=0;o<n.length;o++){var i=n[o],a=e.date_components[i];if(0===a)t+=i;else{var s;"yyyy"===i?s=r.getUTCFullYear():"yy"===i?s=r.getUTCFullYear().toString().substring(2):"MM"===i||"M"===i?s=r.getUTCMonth()+1:"dd"===i||"d"===i?s=r.getUTCDate():"hh"===i||"h"===i?s=r.getUTCHours():"mm"===i||"m"===i?s=r.getUTCMinutes():("ss"===i||"s"===i)&&(s=r.getUTCSeconds()),t+=e.pad_to_valid(s.toString(),a)}}return t},pad_to_valid:function(r,e){var n,o=t.integer({parse:!0}).check(r,function(r){n=r});if(o||0>n)return r;for(var i=0;i<e.length;i++){var a=e[i];if(r.length<=a){for(var s=a-r.length,u=0;s>u;u++)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(n,i){for(var a={},s=[],u=0,c=null,_=null,l=-1,d=!1;u<n.length&&!d;)if(l++,c=o[l],_=e.date_components[c],0!==_){for(var f=_[0],v=_[_.length-1],h="",g=0;v>g;g++){var y=n[u+g];if(void 0===y){f>g&&(d=!0);break}var m=y.charCodeAt(0);if(48>m||m>57){if(g===f)break;d=!0;break}h+=y}if(u+=g,d)break;var p=parseInt(h);s.push(h),"yyyy"===c||"yy"===c?a.year=p:"MM"===c||"M"===c?a.month=p:"dd"===c||"d"===c?a.day=p:"hh"===c||"h"===c?a.hour=p:"mm"===c||"m"===c?a.minute=p:("ss"===c||"s"===c)&&(a.second=p)}else{if(n[u]!==c){d=!0;break}s.push(null),u++}if(d||l<o.length-1)return r.create_error(e.errors.invalid_date_format,t);if(void 0!==a.hour&&(a.hour<0||a.hour>23))return r.create_error(e.errors.invalid_date,t);if(void 0!==a.minute&&(a.minute<0||a.minute>59))return r.create_error(e.errors.invalid_date,t);if(void 0!==a.second&&(a.second<0||a.second>59))return r.create_error(e.errors.invalid_date,t);if(void 0!==a.month){var R=a.month;if(R>12)return r.create_error(e.errors.invalid_date,t);if(1>R)return r.create_error(e.errors.invalid_date,t);if(a.day){var E=a.day;if(1>E)return r.create_error(e.errors.invalid_date,t);if(a.year){var k=a.year;if(2==R)if(k%400===0||k%100!==0&&k%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===R||6===R||9===R||11===R){if(E>30)return r.create_error(e.errors.invalid_date,t)}else if(2===R){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(a.day){if(a.day>31)return r.create_error(e.errors.invalid_date,t);if(a.day<1)return r.create_error(e.errors.invalid_date,t)}if(t.emit)if(t.emit===e.EMIT_COMPONENT_ARRAY)i(s);else if(t.emit===e.EMIT_OBJECT)i(a);else if(t.emit===e.EMIT_DATE){var O=new Date(0);O.setUTCFullYear(0),void 0!==a.year&&O.setYear(a.year),void 0!==a.month&&O.setUTCMonth(a.month-1),void 0!==a.day&&O.setUTCDate(a.day),void 0!==a.hour&&O.setUTCHours(a.hour),void 0!==a.minute&&O.setUTCMinutes(a.minute),void 0!==a.second&&O.setUTCSeconds(a.second),i(O)}};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(1/0===Math.abs(i)&&(i=0),i>=o)return-1;for(n=Math.max(i>=0?i:o-Math.abs(i),0);o>n;){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}},too_long:function(r){return{error:101,error_message:"Length is greater than "+r}},too_small:function(r){return{error:102,error_message:"Value is less than "+r}},too_large:function(r){return{error:103,error_message:"Value is greater than "+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}},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}},no_suffix:function(r){return{error:110,error_message:"Value does not have suffix: "+r}},not_equal:function(r){return{error:113,error_message:"Not equal to "+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:104,error_message:"Value not allowed"}},should_not_contain:function(r){var e=r.join(",");return{error:105,error_message:"Cannot contain "+e}}},equal_to:function(n,t){var o=function(o){return o!==n?r.create_error(e.errors.not_equal,t,n):void 0};return t?(t.check=o,t):{check:o}},merge_required_and_flags:function(r,e){return"object"==typeof r?e=r:(e||(e={}),e.required=r),e},integer:function(n,t){return r.type("integer",e.merge_required_and_flags(n,t))},number:function(n,t){return r.type("number",e.merge_required_and_flags(n,t))},array:function(n,t){return r.type("array",e.merge_required_and_flags(n,t))},object:function(n,t){return r.type("object",e.merge_required_and_flags(n,t))},"boolean":function(n,t){return r.type("boolean",e.merge_required_and_flags(n,t))},string:function(n,t){t=e.merge_required_and_flags(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.REQUIRED_ERROR:r.NOT_REQUIRED_BUT_MISSING:void 0)};return t?(t.check=o,t):{check:o}},length:function(n,t){var o=function(o){return o.length!==n?r.create_error(e.errors.incorrect_length,t,n):void 0};return t?(t.check=o,t):{check:o}},min_length:function(n,t){var o=function(o){return o.length<n?r.create_error(e.errors.too_short,t,n):void 0};return t?(t.check=o,t):{check:o}},max_length:function(n,t){var o=function(o){return o.length>n?r.create_error(e.errors.too_long,t,n):void 0};return t?(t.check=o,t):{check:o}},no_whitespace:function(n){var t=function(t){return/\s/.test(t)?r.create_error(e.errors.contains_whitespace,n,max_len):void 0};return n?(n.check=t,n):{check:t}},minimum:function(n,t){var o=function(o){return n>o?r.create_error(e.errors.too_small,t,n):void 0};return t?(t.check=o,t):{check:o}},maximum:function(n,t){var o=function(o){return o>n?r.create_error(e.errors.too_large,t,n):void 0};return t?(t.check=o,t):{check:o}},range:function(n,t,o){var i=function(i){return n>i?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(-1!==o.indexOf(n[i]))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];o.push("object"==typeof a?a[0]:a)}else for(var s in n)n.hasOwnProperty(s)&&o.push(s);var u=function(n){return-1===o.indexOf(n)?r.create_error(e.errors.not_in_list,t):void 0};return t?(t.check=u,t):{check:u}},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];o.push("object"==typeof a?a[0]:a)}else for(var s in n)n.hasOwnProperty(s)&&o.push(s);var u=function(n){return-1!==o.indexOf(n)?r.create_error(e.errors.value_in_list,t):void 0};return t?(t.check=u,t):{check:u}},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&&90>=o||o>=97&&122>=o?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,each:function(e,n){var t=function(n){var t=new r(null),o=function(o){var i=n[o],a=e(i,o,function(r){n[o]=r});if(a===r.ASYNC)throw new Error(".each used with async checks, use .each_async.");a===r.REQUIRED_ERROR?t.missing(""+o):a&&t.invalid(""+o,a)};if(Array.isArray(n))for(var i=0;i<n.length;i++)o(i);else for(var a in n)n.hasOwnProperty(a)&&o(a);var s=t.end();return s?s:void 0};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 s,u,c=new r(null),_=0;a&&(s=_);var l=function(){if(a){if(s++,s>n.length)return void o(c.end());u=n[s-1]}else{if(_++,_>i.length)return void o(c.end());s=i[_-1],u=n[s]}r.use_checks(u,[function(r,n,t){e(r,s,n,t)}],{field_name:a?""+(s-1):s,validator:c,emit:function(r){a?n[s-1]=r:n[s]=r}},function(){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 s,u=n[a],c=r.use_checks(o,u,null,null,function(r){s=r});if(c===r.ASYNC)throw new Error(".multiple used with async checks, use .multiple_async.");if(!c)return void 0!==s&&i(s),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,s){var u,c=function(r){u=r},_=0,l=function(){if(_++,_>n.length)return void s(r.create_error(e.errors.no_valid_option,t));var o=n[_-1];r.use_checks(i,o,{field_name:null,validator:null,emit:c},function(r){r?l():s(void 0)})};return l(),o};return t?(t.check=i,t):{check:i}},email:function(n,t){t=e.merge_required_and_flags(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_flags(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}},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}.call();return r.DateVal=n,r.BasicVal=t,r}.call();"undefined"!=typeof module?module.exports=FieldVal:(BasicVal=FieldVal.BasicVal,DateVal=FieldVal.DateVal);
var FieldVal=function(){"use strict";function r(e,n){var t=this;if(t.async_waiting=0,t.validating=e,t.invalid_keys={},t.recognized_keys={},t.errors=[],void 0!==n)if(n){var o;if(n.error===r.ONE_OR_MORE_ERRORS)o=n;else if(n.error===r.MULTIPLE_ERRORS)for(var i=0;i<n.errors.length;i++){var a=n.errors[i];a.error!==r.ONE_OR_MORE_ERRORS?t.errors.push(a):o=a}else t.errors.push(n);if(o){for(var s in e)e.hasOwnProperty(s)&&(t.recognized_keys[s]=!0);if(o.unrecognized){t.unrecognized_keys=o.unrecognized;for(var c in t.unrecognized_keys)t.unrecognized_keys.hasOwnProperty(c)&&delete t.recognized_keys[c]}o.invalid&&(t.invalid_keys=o.invalid)}}else for(var u in e)e.hasOwnProperty(u)&&(t.recognized_keys[u]=!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 s=e[a];if(o=o[s],void 0===o)return void 0;if(i){var c;c=i instanceof r?i.invalid_keys:i.invalid,c&&(i=c[s])}}return new r(o,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 s=o.invalid;s&&(o=s[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 s=e,c=0;o>c;c++){var u,_=t[c];u=s instanceof r?s.invalid_keys:s.invalid;var l;l=c===o-1?n:u[_],l||(l={error:r.ONE_OR_MORE_ERRORS,error_message:r.ONE_OR_MORE_ERRORS_STRING}),s instanceof r?s.invalid(_,l):(u||(u=s.invalid={}),u[_]=r.add_to_invalid(l,u[_])),s=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 s=r.use_checks(i,n,{validator:o,field_name:e,emit:function(r){i=r}},function(){void 0!==t&&t(i)});return s===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={},s={};for(n in t.unrecognized_keys)t.unrecognized_keys.hasOwnProperty(n)&&(a[n]=t.unrecognized_keys[n]);var c,u,_=t.get_unrecognized();for(c=0;c<_.length;c++)u=_[c],s[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)&&(s[l]=t.invalid_keys[l]);i=!0}if(i&&(o.invalid=s),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:!1;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={},s=0;if("object"==typeof e){if(Array.isArray(e)){var c=!1,u=e,_=!1,l=function(){if(s++,n.stop||s>u.length)return _=!0,void t();var e=r.use_check(u[s-1],n,function(){l()});e===r.ASYNC&&(c=!0)};return l(),_?c?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,s=!1,c=function(r){a=r,s=!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?(c(null),void i.validator.async_call_ended()):(c(i.validator.end()),void i.validator.async_call_ended())});return u===r.ASYNC?(o&&(c=o),r.ASYNC):s?a:r.ASYNC},r.merge_flags_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){return null===t||void 0===t?e||void 0===e?r.create_error(r.MISSING_ERROR,n):r.NOT_REQUIRED_BUT_MISSING:void 0};return r.merge_flags_and_checks(n,t)},r.type=function(e,n){var t=n&&void 0!==n.required?n.required:!0,o=function(o,i){var a=r.required(t,n||{}).check(o);if(a)return a;var s=r.get_value_and_type(o,e,n),c=s.desired_type,u=s.type;return o=s.value,u!==c?r.create_error(r.INCORRECT_TYPE_ERROR,n,c,u):void(i&&i(o))};return r.merge_flags_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(){return{error:111,error_message:"Invalid date format."}},invalid_date:function(){return{error:112,error_message:"Invalid date."}},invalid_date_format_string:function(){return{error:114,error_message:"Invalid date format string."}}},date_format:function(n){n=n||{};var t=function(t,o){for(var i=[],a=0,s=!1;a<t.length&&!s;){var c=!1;for(var u in e.date_components){var _=t.substring(a,a+u.length);if(_===u){i.push(u),a+=u.length,c=!0;break}}c||(s=!0)}return s?r.create_error(e.errors.invalid_date_format_string,n):void o(n.emit==e.EMIT_STRING?t:i)};return n?(n.check=t,n):{check:t}},date_with_format_array:function(r,n){for(var t="",o=0;o<n.length;o++){var i=n[o],a=e.date_components[i];if(0===a)t+=i;else{var s;"yyyy"===i?s=r.getUTCFullYear():"yy"===i?s=r.getUTCFullYear().toString().substring(2):"MM"===i||"M"===i?s=r.getUTCMonth()+1:"dd"===i||"d"===i?s=r.getUTCDate():"hh"===i||"h"===i?s=r.getUTCHours():"mm"===i||"m"===i?s=r.getUTCMinutes():("ss"===i||"s"===i)&&(s=r.getUTCSeconds()),t+=e.pad_to_valid(s.toString(),a)}}return t},pad_to_valid:function(r,e){var n,o=t.integer({parse:!0}).check(r,function(r){n=r});if(o||0>n)return r;for(var i=0;i<e.length;i++){var a=e[i];if(r.length<=a){for(var s=a-r.length,c=0;s>c;c++)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(n,i){for(var a={},s=[],c=0,u=null,_=null,l=-1,f=!1;c<n.length&&!f;)if(l++,u=o[l],_=e.date_components[u],0!==_){for(var d=_[0],v=_[_.length-1],h="",g=0;v>g;g++){var y=n[c+g];if(void 0===y){d>g&&(f=!0);break}var m=y.charCodeAt(0);if(48>m||m>57){if(g===d)break;f=!0;break}h+=y}if(c+=g,f)break;var p=parseInt(h);s.push(h),"yyyy"===u||"yy"===u?a.year=p:"MM"===u||"M"===u?a.month=p:"dd"===u||"d"===u?a.day=p:"hh"===u||"h"===u?a.hour=p:"mm"===u||"m"===u?a.minute=p:("ss"===u||"s"===u)&&(a.second=p)}else{if(n[c]!==u){f=!0;break}s.push(null),c++}if(f||l<o.length-1)return r.create_error(e.errors.invalid_date_format,t);if(void 0!==a.hour&&(a.hour<0||a.hour>23))return r.create_error(e.errors.invalid_date,t);if(void 0!==a.minute&&(a.minute<0||a.minute>59))return r.create_error(e.errors.invalid_date,t);if(void 0!==a.second&&(a.second<0||a.second>59))return r.create_error(e.errors.invalid_date,t);if(void 0!==a.month){var R=a.month;if(R>12)return r.create_error(e.errors.invalid_date,t);if(1>R)return r.create_error(e.errors.invalid_date,t);if(a.day){var E=a.day;if(1>E)return r.create_error(e.errors.invalid_date,t);if(a.year){var k=a.year;if(2==R)if(k%400===0||k%100!==0&&k%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===R||6===R||9===R||11===R){if(E>30)return r.create_error(e.errors.invalid_date,t)}else if(2===R){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(a.day){if(a.day>31)return r.create_error(e.errors.invalid_date,t);if(a.day<1)return r.create_error(e.errors.invalid_date,t)}if(t.emit)if(t.emit===e.EMIT_COMPONENT_ARRAY)i(s);else if(t.emit===e.EMIT_OBJECT)i(a);else if(t.emit===e.EMIT_DATE){var O=new Date(0);O.setUTCFullYear(0),void 0!==a.year&&O.setYear(a.year),void 0!==a.month&&O.setUTCMonth(a.month-1),void 0!==a.day&&O.setUTCDate(a.day),void 0!==a.hour&&O.setUTCHours(a.hour),void 0!==a.minute&&O.setUTCMinutes(a.minute),void 0!==a.second&&O.setUTCSeconds(a.second),i(O)}};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(1/0===Math.abs(i)&&(i=0),i>=o)return-1;for(n=Math.max(i>=0?i:o-Math.abs(i),0);o>n;){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}},too_long:function(r){return{error:101,error_message:"Length is greater than "+r}},too_small:function(r){return{error:102,error_message:"Value is less than "+r}},too_large:function(r){return{error:103,error_message:"Value is greater than "+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}},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}},no_suffix:function(r){return{error:110,error_message:"Value does not have suffix: "+r}},not_equal:function(r){return{error:113,error_message:"Not equal to "+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:104,error_message:"Value not allowed"}},should_not_contain:function(r){var e=r.join(",");return{error:105,error_message:"Cannot contain "+e}}},equal_to:function(n,t){var o=function(o){return o!==n?r.create_error(e.errors.not_equal,t,n):void 0};return t?(t.check=o,t):{check:o}},merge_required_and_flags: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_flags(n,t))},number:function(n,t){return r.type("number",e.merge_required_and_flags(n,t))},array:function(n,t){return r.type("array",e.merge_required_and_flags(n,t))},object:function(n,t){return r.type("object",e.merge_required_and_flags(n,t))},"boolean":function(n,t){return r.type("boolean",e.merge_required_and_flags(n,t))},string:function(n,t){t=e.merge_required_and_flags(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){return o.length!==n?r.create_error(e.errors.incorrect_length,t,n):void 0};return t?(t.check=o,t):{check:o}},min_length:function(n,t){var o=function(o){return o.length<n?r.create_error(e.errors.too_short,t,n):void 0};return t?(t.check=o,t):{check:o}},max_length:function(n,t){var o=function(o){return o.length>n?r.create_error(e.errors.too_long,t,n):void 0};return t?(t.check=o,t):{check:o}},no_whitespace:function(n){var t=function(t){return/\s/.test(t)?r.create_error(e.errors.contains_whitespace,n):void 0};return n?(n.check=t,n):{check:t}},minimum:function(n,t){var o=function(o){return n>o?r.create_error(e.errors.too_small,t,n):void 0};return t?(t.check=o,t):{check:o}},maximum:function(n,t){var o=function(o){return o>n?r.create_error(e.errors.too_large,t,n):void 0};return t?(t.check=o,t):{check:o}},range:function(n,t,o){var i=function(i){return n>i?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(-1!==o.indexOf(n[i]))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];o.push("object"==typeof a?a[0]:a)}else for(var s in n)n.hasOwnProperty(s)&&o.push(s);var c=function(n){return-1===o.indexOf(n)?r.create_error(e.errors.not_in_list,t):void 0};return t?(t.check=c,t):{check:c}},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];o.push("object"==typeof a?a[0]:a)}else for(var s in n)n.hasOwnProperty(s)&&o.push(s);var c=function(n){return-1!==o.indexOf(n)?r.create_error(e.errors.value_in_list,t):void 0};return t?(t.check=c,t):{check:c}},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&&90>=o||o>=97&&122>=o?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,each:function(e,n){var t=function(n){var t=new r(null),o=function(o){var i=n[o],a=e(i,o,function(r){n[o]=r});if(a===r.ASYNC)throw new Error(".each used with async checks, use .each_async.");a&&t.invalid(""+o,a)};if(Array.isArray(n))for(var i=0;i<n.length;i++)o(i);else for(var a in n)n.hasOwnProperty(a)&&o(a);var s=t.end();return s?s:void 0};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 s,c,u=new r(null),_=0;a&&(s=_);var l=function(){if(a){if(s++,s>n.length)return void o(u.end());c=n[s-1]}else{if(_++,_>i.length)return void o(u.end());s=i[_-1],c=n[s]}r.use_checks(c,[function(r,n,t){e(r,s,n,t)}],{field_name:a?""+(s-1):s,validator:u,emit:function(r){a?n[s-1]=r:n[s]=r}},function(){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 s,c=n[a],u=r.use_checks(o,c,null,null,function(r){s=r});if(u===r.ASYNC)throw new Error(".multiple used with async checks, use .multiple_async.");if(!u)return void 0!==s&&i(s),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,s){var c,u=function(r){c=r},_=0,l=function(){if(_++,_>n.length)return void s(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():s(void 0)})};return l(),o};return t?(t.check=i,t):{check:i}},email:function(n,t){t=e.merge_required_and_flags(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_flags(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}},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}.call();return r.DateVal=n,r.BasicVal=t,r}.call();"undefined"!=typeof module?module.exports=FieldVal:(BasicVal=FieldVal.BasicVal,DateVal=FieldVal.DateVal);
{
"name": "fieldval",
"version": "0.4.0",
"version": "0.4.1",
"description": "fieldval",

@@ -5,0 +5,0 @@ "main": "fieldval.js",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc