Module 641797

4,884 characters · in no known chunk
Dependencies
Required by (1)
Lazily required by (0)none
Requires (3)
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";var i=n(788409),r=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,h={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:r.encode,encodeValuesOnly:!1,filter:void 0,format:_,formatter:s.formatters[_],indices:!1,serializeDate:function(e){return d.call(e)},skipNulls:!1,strictNullHandling:!1},f={},E=function e(t,n,s,a,o,u,d,_,E,p,m,g,A,I,T,S,N,C){for(var y,O,R=t,v=C,b=0,L=!1;void 0!==(v=v.get(f))&&!L;){var D=v.get(t);if(b+=1,void 0!==D)if(D===b)throw RangeError("Cyclic object value");else L=!0;void 0===v.get(f)&&(b=0)}if("function"==typeof p?R=p(n,R):R instanceof Date?R=A(R):"comma"===s&&l(R)&&(R=r.maybeMap(R,function(e){return e instanceof Date?A(e):e})),null===R){if(u)return E&&!S?E(n,h.encoder,N,"key",I):n;R=""}if("string"==typeof(y=R)||"number"==typeof y||"boolean"==typeof y||"symbol"==typeof y||"bigint"==typeof y||r.isBuffer(R))return E?[T(S?n:E(n,h.encoder,N,"key",I))+"="+T(E(R,h.encoder,N,"value",I))]:[T(n)+"="+T(String(R))];var w=[];if(void 0===R)return w;if("comma"===s&&l(R))S&&E&&(R=r.maybeMap(R,E)),O=[{value:R.length>0?R.join(",")||null:void 0}];else if(l(p))O=p;else{var P=Object.keys(R);O=m?P.sort(m):P}var M=_?String(n).replace(/\./g,"%2E"):String(n),x=a&&l(R)&&1===R.length?M+"[]":M;if(o&&l(R)&&0===R.length)return x+"[]";for(var U=0;U<O.length;++U){var k=O[U],G="object"==typeof k&&k&&void 0!==k.value?k.value:R[k];if(!d||null!==G){var V=g&&_?String(k).replace(/\./g,"%2E"):String(k),F=l(R)?"function"==typeof s?s(x,V):x:x+(g?"."+V:"["+V+"]");C.set(t,b);var B=i();B.set(f,C),c(w,e(G,F,s,a,o,u,d,_,"comma"===s&&S&&l(R)?null:E,p,m,g,A,I,T,S,N,B))}}return w},p=function(e){if(!e)return h;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||h.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 i=s.default;if(void 0!==e.format){if(!a.call(s.formatters,e.format))throw TypeError("Unknown format option provided.");i=e.format}var r=s.formatters[i],u=h.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":h.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||h.allowDots:!!e.allowDots;return{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:h.addQueryPrefix,allowDots:c,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:h.allowEmptyArrays,arrayFormat:t,charset:n,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:h.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:void 0===e.delimiter?h.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:h.encode,encodeDotInKeys:"boolean"==typeof e.encodeDotInKeys?e.encodeDotInKeys:h.encodeDotInKeys,encoder:"function"==typeof e.encoder?e.encoder:h.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:h.encodeValuesOnly,filter:u,format:i,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:h.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:h.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:h.strictNullHandling}};e.exports=function(e,t){var n,r=e,s=p(t);"function"==typeof s.filter?r=(0,s.filter)("",r):l(s.filter)&&(n=s.filter);var a=[];if("object"!=typeof r||null===r)return"";var u=o[s.arrayFormat],d="comma"===u&&s.commaRoundTrip;n||(n=Object.keys(r)),s.sort&&n.sort(s.sort);for(var _=i(),h=0;h<n.length;++h){var f=n[h],m=r[f];s.skipNulls&&null===m||c(a,E(m,f,u,d,s.allowEmptyArrays,s.strictNullHandling,s.skipNulls,s.encodeDotInKeys,s.encode?s.encoder:null,s.filter,s.sort,s.allowDots,s.serializeDate,s.format,s.formatter,s.encodeValuesOnly,s.charset,_))}var g=a.join(s.delimiter),A=!0===s.addQueryPrefix?"?":"";return s.charsetSentinel&&("iso-8859-1"===s.charset?A+="utf8=%26%2310003%3B&":A+="utf8=%E2%9C%93&"),g.length>0?A+g:""}}