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