Module 466107

5,922 characters · in no known chunk
Dependencies
Required by (1)
Lazily required by (0)none
Requires (1)
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";var r=n(589841),i=Object.prototype.hasOwnProperty,s=Array.isArray,a={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:r.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1,throwOnLimitExceeded:!1},o=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},l=function(e,t,n){if(e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1)return e.split(",");if(t.throwOnLimitExceeded&&n>=t.arrayLimit)throw RangeError("Array limit exceeded. Only "+t.arrayLimit+" element"+(1===t.arrayLimit?"":"s")+" allowed in an array.");return e},u="utf8=%26%2310003%3B",c="utf8=%E2%9C%93",d=function(e,t){var n={__proto__:null},d=t.ignoreQueryPrefix?e.replace(/^\?/,""):e;d=d.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var _=t.parameterLimit===1/0?void 0:t.parameterLimit,f=d.split(t.delimiter,t.throwOnLimitExceeded?_+1:_);if(t.throwOnLimitExceeded&&f.length>_)throw RangeError("Parameter limit exceeded. Only "+_+" parameter"+(1===_?"":"s")+" allowed.");var p=-1,h=t.charset;if(t.charsetSentinel)for(m=0;m<f.length;++m)0===f[m].indexOf("utf8=")&&(f[m]===c?h="utf-8":f[m]===u&&(h="iso-8859-1"),p=m,m=f.length);for(m=0;m<f.length;++m)if(m!==p){var m,E,g,A=f[m],I=A.indexOf("]="),T=-1===I?A.indexOf("="):I+1;-1===T?(E=t.decoder(A,a.decoder,h,"key"),g=t.strictNullHandling?null:""):(E=t.decoder(A.slice(0,T),a.decoder,h,"key"),g=r.maybeMap(l(A.slice(T+1),t,s(n[E])?n[E].length:0),function(e){return t.decoder(e,a.decoder,h,"value")})),g&&t.interpretNumericEntities&&"iso-8859-1"===h&&(g=o(String(g))),A.indexOf("[]=")>-1&&(g=s(g)?[g]:g);var S=i.call(n,E);S&&"combine"===t.duplicates?n[E]=r.combine(n[E],g):S&&"last"!==t.duplicates||(n[E]=g)}return n},_=function(e,t,n,i){var s=0;if(e.length>0&&"[]"===e[e.length-1]){var a=e.slice(0,-1).join("");s=Array.isArray(t)&&t[a]?t[a].length:0}for(var o=i?t:l(t,n,s),u=e.length-1;u>=0;--u){var c,d=e[u];if("[]"===d&&n.parseArrays)c=n.allowEmptyArrays&&(""===o||n.strictNullHandling&&null===o)?[]:r.combine([],o);else{c=n.plainObjects?{__proto__:null}:{};var _="["===d.charAt(0)&&"]"===d.charAt(d.length-1)?d.slice(1,-1):d,f=n.decodeDotInKeys?_.replace(/%2E/g,"."):_,p=parseInt(f,10);n.parseArrays||""!==f?!isNaN(p)&&d!==f&&String(p)===f&&p>=0&&n.parseArrays&&p<=n.arrayLimit?(c=[])[p]=o:"__proto__"!==f&&(c[f]=o):c={0:o}}o=c}return o},f=function(e,t,n,r){if(e){var s=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,a=/(\[[^[\]]*])/,o=/(\[[^[\]]*])/g,l=n.depth>0&&a.exec(s),u=l?s.slice(0,l.index):s,c=[];if(u){if(!n.plainObjects&&i.call(Object.prototype,u)&&!n.allowPrototypes)return;c.push(u)}for(var d=0;n.depth>0&&null!==(l=o.exec(s))&&d<n.depth;){if(d+=1,!n.plainObjects&&i.call(Object.prototype,l[1].slice(1,-1))&&!n.allowPrototypes)return;c.push(l[1])}if(l){if(!0===n.strictDepth)throw RangeError("Input depth exceeded depth option of "+n.depth+" and strictDepth is true");c.push("["+s.slice(l.index)+"]")}return _(c,t,n,r)}},p=function(e){if(!e)return a;if(void 0!==e.allowEmptyArrays&&"boolean"!=typeof e.allowEmptyArrays)throw TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==e.decodeDotInKeys&&"boolean"!=typeof e.decodeDotInKeys)throw TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0!==e.throwOnLimitExceeded&&"boolean"!=typeof e.throwOnLimitExceeded)throw TypeError("`throwOnLimitExceeded` option must be a boolean");var t=void 0===e.charset?a.charset:e.charset,n=void 0===e.duplicates?a.duplicates:e.duplicates;if("combine"!==n&&"first"!==n&&"last"!==n)throw TypeError("The duplicates option must be either combine, first, or last");return{allowDots:void 0===e.allowDots?!0===e.decodeDotInKeys||a.allowDots:!!e.allowDots,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:a.allowEmptyArrays,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:a.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:a.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:a.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:a.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:a.comma,decodeDotInKeys:"boolean"==typeof e.decodeDotInKeys?e.decodeDotInKeys:a.decodeDotInKeys,decoder:"function"==typeof e.decoder?e.decoder:a.decoder,delimiter:"string"==typeof e.delimiter||r.isRegExp(e.delimiter)?e.delimiter:a.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:a.depth,duplicates:n,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:a.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:a.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:a.plainObjects,strictDepth:"boolean"==typeof e.strictDepth?!!e.strictDepth:a.strictDepth,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:a.strictNullHandling,throwOnLimitExceeded:"boolean"==typeof e.throwOnLimitExceeded&&e.throwOnLimitExceeded}};e.exports=function(e,t){var n=p(t);if(""===e||null==e)return n.plainObjects?{__proto__:null}:{};for(var i="string"==typeof e?d(e,n):e,s=n.plainObjects?{__proto__:null}:{},a=Object.keys(i),o=0;o<a.length;++o){var l=a[o],u=f(l,i[l],n,"string"==typeof e);s=r.merge(s,u,n)}return!0===n.allowSparse?s:r.compact(s)}}