(function(n){if(typeof define=="function"&&define.amd)define(["jquery"],n);else if(typeof exports=="object"){var t=require("jquery");module.exports=n(t)}else n(window.jQuery||window.Zepto||window.$)})(function(n){"use strict";n.fn.serializeJSON=function(t){var i,e,u,o,s,f,a,h,c,l,r,v,y;return i=n.serializeJSON,e=this,u=i.setupOpts(t),o=e.serializeArray(),i.readCheckboxUncheckedValues(o,u,e),s={},n.each(o,function(n,t){f=t.name;a=t.value;c=i.extractTypeAndNameWithNoType(f);l=c.nameWithNoType;r=c.type;r||(r=i.attrFromInputWithName(e,f,"data-value-type"));i.validateType(f,r,u);r!=="skip"&&(v=i.splitInputNameIntoKeysArray(l),h=i.parseValue(a,f,r,u),y=!h&&i.shouldSkipFalsy(e,f,l,r,u),y||i.deepSet(s,v,h,u))}),s};n.serializeJSON={defaultOptions:{checkboxUncheckedValue:undefined,parseNumbers:!1,parseBooleans:!1,parseNulls:!1,parseAll:!1,parseWithFunction:null,skipFalsyValuesForTypes:[],skipFalsyValuesForFields:[],customTypes:{},defaultTypes:{string:function(n){return String(n)},number:function(n){return Number(n)},boolean:function(n){return["false","null","undefined","","0"].indexOf(n)===-1},"null":function(n){return["false","null","undefined","","0"].indexOf(n)===-1?n:null},array:function(n){return JSON.parse(n)},object:function(n){return JSON.parse(n)},auto:function(t){return n.serializeJSON.parseValue(t,null,null,{parseNumbers:!0,parseBooleans:!0,parseNulls:!0})},skip:null},useIntKeysAsArrayIndex:!1},setupOpts:function(t){var u,f,e,i,r,o;o=n.serializeJSON;t==null&&(t={});e=o.defaultOptions||{};f=["checkboxUncheckedValue","parseNumbers","parseBooleans","parseNulls","parseAll","parseWithFunction","skipFalsyValuesForTypes","skipFalsyValuesForFields","customTypes","defaultTypes","useIntKeysAsArrayIndex"];for(u in t)if(f.indexOf(u)===-1)throw new Error("serializeJSON ERROR: invalid option '"+u+"'. Please use one of "+f.join(", "));return i=function(n){return t[n]!==!1&&t[n]!==""&&(t[n]||e[n])},r=i("parseAll"),{checkboxUncheckedValue:i("checkboxUncheckedValue"),parseNumbers:r||i("parseNumbers"),parseBooleans:r||i("parseBooleans"),parseNulls:r||i("parseNulls"),parseWithFunction:i("parseWithFunction"),skipFalsyValuesForTypes:i("skipFalsyValuesForTypes"),skipFalsyValuesForFields:i("skipFalsyValuesForFields"),typeFunctions:n.extend({},i("defaultTypes"),i("customTypes")),useIntKeysAsArrayIndex:i("useIntKeysAsArrayIndex")}},parseValue:function(t,i,r,u){var e,f;return e=n.serializeJSON,f=t,u.typeFunctions&&r&&u.typeFunctions[r]?f=u.typeFunctions[r](t):u.parseNumbers&&e.isNumeric(t)?f=Number(t):u.parseBooleans&&(t==="true"||t==="false")?f=t==="true":u.parseNulls&&t=="null"?f=null:u.typeFunctions&&u.typeFunctions.string&&(f=u.typeFunctions.string(t)),u.parseWithFunction&&!r&&(f=u.parseWithFunction(f,i)),f},isObject:function(n){return n===Object(n)},isUndefined:function(n){return n===void 0},isValidArrayIndex:function(n){return/^[0-9]+$/.test(String(n))},isNumeric:function(n){return n-parseFloat(n)>=0},optionKeys:function(n){if(Object.keys)return Object.keys(n);var t,i=[];for(t in n)i.push(t);return i},readCheckboxUncheckedValues:function(t,i,r){var f,e,o,u,s;i==null&&(i={});s=n.serializeJSON;f="input[type=checkbox][name]:not(:checked):not([disabled])";e=r.find(f).add(r.filter(f));e.each(function(r,f){if(o=n(f),u=o.attr("data-unchecked-value"),u==null&&(u=i.checkboxUncheckedValue),u!=null){if(f.name&&f.name.indexOf("[][")!==-1)throw new Error("serializeJSON ERROR: checkbox unchecked values are not supported on nested arrays of objects like '"+f.name+"'. See https://github.com/marioizquierdo/jquery.serializeJSON/issues/67");t.push({name:f.name,value:u})}})},extractTypeAndNameWithNoType:function(n){var t;return(t=n.match(/(.*):([^:]+)$/))?{nameWithNoType:t[1],type:t[2]}:{nameWithNoType:n,type:null}},shouldSkipFalsy:function(t,i,r,u,f){var h=n.serializeJSON,s=h.attrFromInputWithName(t,i,"data-skip-falsy"),e,o;return s!=null?s!=="false":(e=f.skipFalsyValuesForFields,e&&(e.indexOf(r)!==-1||e.indexOf(i)!==-1))?!0:(o=f.skipFalsyValuesForTypes,u==null&&(u="string"),o&&o.indexOf(u)!==-1)?!0:!1},attrFromInputWithName:function(n,t,i){var u,r,f;return u=t.replace(/(:|\.|\[|\]|\s)/g,"\\$1"),r='[name="'+u+'"]',f=n.find(r).add(n.filter(r)),f.attr(i)},validateType:function(t,i,r){var u,f;if(f=n.serializeJSON,u=f.optionKeys(r?r.typeFunctions:f.defaultOptions.defaultTypes),i&&u.indexOf(i)===-1)throw new Error("serializeJSON ERROR: Invalid type "+i+" found in input name '"+t+"', please use one of "+u.join(", "));else return!0},splitInputNameIntoKeysArray:function(t){var i,r;return r=n.serializeJSON,i=t.split("["),i=n.map(i,function(n){return n.replace(/\]/g,"")}),i[0]===""&&i.shift(),i},deepSet:function(t,i,r,u){var f,o,c,s,h,e;if(u==null&&(u={}),e=n.serializeJSON,e.isUndefined(t))throw new Error("ArgumentError: param 'o' expected to be an object or array, found undefined");if(!i||i.length===0)throw new Error("ArgumentError: param 'keys' expected to be an array with least one element");f=i[0];i.length===1?f===""?t.push(r):t[f]=r:(o=i[1],f===""&&(s=t.length-1,h=t[s],f=e.isObject(h)&&(e.isUndefined(h[o])||i.length>2)?s:s+1),o===""?(e.isUndefined(t[f])||!n.isArray(t[f]))&&(t[f]=[]):u.useIntKeysAsArrayIndex&&e.isValidArrayIndex(o)?(e.isUndefined(t[f])||!n.isArray(t[f]))&&(t[f]=[]):(e.isUndefined(t[f])||!e.isObject(t[f]))&&(t[f]={}),c=i.slice(1),e.deepSet(t[f],c,r,u))}}})