Build 533169stable
Module 641797
4,909 characters · in no known chunkDependencies
Source Raw
function(e,t,n){"use strict";var r=n(788409),i=n(589841),s=n(404312),a=Object.prototype.hasOwnProperty,o={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},l=Array.isArray,u=Array.prototype.push,c=function(e,t){u.apply(e,l(t)?t:[t])},d=Date.prototype.toISOString,_=s.default,f={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:i.encode,encodeValuesOnly:!1,filter:void 0,format:_,formatter:s.formatters[_],indices:!1,serializeDate:function(e){return d.call(e)},skipNulls:!1,strictNullHandling:!1},p=function(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"symbol"==typeof e||"bigint"==typeof e},h={},m=function e(t,n,s,a,o,u,d,_,m,E,g,A,I,T,S,y,v,N){for(var C,R=t,O=N,b=0,D=!1;void 0!==(O=O.get(h))&&!D;){var L=O.get(t);if(b+=1,void 0!==L)if(L===b)throw RangeError("Cyclic object value");else D=!0;void 0===O.get(h)&&(b=0)}if("function"==typeof E?R=E(n,R):R instanceof Date?R=I(R):"comma"===s&&l(R)&&(R=i.maybeMap(R,function(e){return e instanceof Date?I(e):e})),null===R){if(u)return m&&!y?m(n,f.encoder,v,"key",T):n;R=""}if(p(R)||i.isBuffer(R))return m?[S(y?n:m(n,f.encoder,v,"key",T))+"="+S(m(R,f.encoder,v,"value",T))]:[S(n)+"="+S(String(R))];var w=[];if(void 0===R)return w;if("comma"===s&&l(R))y&&m&&(R=i.maybeMap(R,m)),C=[{value:R.length>0?R.join(",")||null:void 0}];else if(l(E))C=E;else{var M=Object.keys(R);C=g?M.sort(g):M}var P=_?String(n).replace(/\./g,"%2E"):String(n),x=a&&l(R)&&1===R.length?P+"[]":P;if(o&&l(R)&&0===R.length)return x+"[]";for(var k=0;k<C.length;++k){var U=C[k],G="object"==typeof U&&U&&void 0!==U.value?U.value:R[U];if(!d||null!==G){var F=A&&_?String(U).replace(/\./g,"%2E"):String(U),V=l(R)?"function"==typeof s?s(x,F):x:x+(A?"."+F:"["+F+"]");N.set(t,b);var B=r();B.set(h,N),c(w,e(G,V,s,a,o,u,d,_,"comma"===s&&y&&l(R)?null:m,E,g,A,I,T,S,y,v,B))}}return w},E=function(e){if(!e)return f;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.encodeDotInKeys&&"boolean"!=typeof e.encodeDotInKeys)throw TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw TypeError("Encoder has to be a function.");var t,n=e.charset||f.charset;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");var r=s.default;if(void 0!==e.format){if(!a.call(s.formatters,e.format))throw TypeError("Unknown format option provided.");r=e.format}var i=s.formatters[r],u=f.filter;if(("function"==typeof e.filter||l(e.filter))&&(u=e.filter),t=e.arrayFormat in o?e.arrayFormat:"indices"in e?e.indices?"indices":"repeat":f.arrayFormat,"commaRoundTrip"in e&&"boolean"!=typeof e.commaRoundTrip)throw TypeError("`commaRoundTrip` must be a boolean, or absent");var c=void 0===e.allowDots?!0===e.encodeDotInKeys||f.allowDots:!!e.allowDots;return{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:f.addQueryPrefix,allowDots:c,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:f.allowEmptyArrays,arrayFormat:t,charset:n,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:f.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:void 0===e.delimiter?f.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:f.encode,encodeDotInKeys:"boolean"==typeof e.encodeDotInKeys?e.encodeDotInKeys:f.encodeDotInKeys,encoder:"function"==typeof e.encoder?e.encoder:f.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:f.encodeValuesOnly,filter:u,format:r,formatter:i,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:f.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:f.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:f.strictNullHandling}};e.exports=function(e,t){var n,i,s=e,a=E(t);"function"==typeof a.filter?s=(i=a.filter)("",s):l(a.filter)&&(n=i=a.filter);var u=[];if("object"!=typeof s||null===s)return"";var d=o[a.arrayFormat],_="comma"===d&&a.commaRoundTrip;n||(n=Object.keys(s)),a.sort&&n.sort(a.sort);for(var f=r(),p=0;p<n.length;++p){var h=n[p],g=s[h];a.skipNulls&&null===g||c(u,m(g,h,d,_,a.allowEmptyArrays,a.strictNullHandling,a.skipNulls,a.encodeDotInKeys,a.encode?a.encoder:null,a.filter,a.sort,a.allowDots,a.serializeDate,a.format,a.formatter,a.encodeValuesOnly,a.charset,f))}var A=u.join(a.delimiter),I=!0===a.addQueryPrefix?"?":"";return a.charsetSentinel&&("iso-8859-1"===a.charset?I+="utf8=%26%2310003%3B&":I+="utf8=%E2%9C%93&"),A.length>0?I+A:""}}