1 line
5.8 KiB
JavaScript
1 line
5.8 KiB
JavaScript
import{g as q}from"./_commonjsHelpers-BosuxZz1.js";import{d as w}from"./index-CROxjmim.js";var E={},C=i=>encodeURIComponent(i).replace(/[!'()*]/g,s=>`%${s.charCodeAt(0).toString(16).toUpperCase()}`),p=(i,s)=>{if(!(typeof i=="string"&&typeof s=="string"))throw new TypeError("Expected the arguments to be of type `string`");if(s==="")return[i];const l=i.indexOf(s);return l===-1?[i]:[i.slice(0,l),i.slice(l+s.length)]},I=function(i,s){for(var l={},o=Object.keys(i),F=Array.isArray(s),m=0;m<o.length;m++){var u=o[m],y=i[u];(F?s.indexOf(u)!==-1:s(u,y,i))&&(l[u]=y)}return l};(function(i){const s=C,l=w,o=p,F=I,m=r=>r==null;function u(r){switch(r.arrayFormat){case"index":return e=>(n,t)=>{const a=n.length;return t===void 0||r.skipNull&&t===null||r.skipEmptyString&&t===""?n:t===null?[...n,[d(e,r),"[",a,"]"].join("")]:[...n,[d(e,r),"[",d(a,r),"]=",d(t,r)].join("")]};case"bracket":return e=>(n,t)=>t===void 0||r.skipNull&&t===null||r.skipEmptyString&&t===""?n:t===null?[...n,[d(e,r),"[]"].join("")]:[...n,[d(e,r),"[]=",d(t,r)].join("")];case"comma":case"separator":return e=>(n,t)=>t==null||t.length===0?n:n.length===0?[[d(e,r),"=",d(t,r)].join("")]:[[n,d(t,r)].join(r.arrayFormatSeparator)];default:return e=>(n,t)=>t===void 0||r.skipNull&&t===null||r.skipEmptyString&&t===""?n:t===null?[...n,d(e,r)]:[...n,[d(e,r),"=",d(t,r)].join("")]}}function y(r){let e;switch(r.arrayFormat){case"index":return(n,t,a)=>{if(e=/\[(\d*)\]$/.exec(n),n=n.replace(/\[\d*\]$/,""),!e){a[n]=t;return}a[n]===void 0&&(a[n]={}),a[n][e[1]]=t};case"bracket":return(n,t,a)=>{if(e=/(\[\])$/.exec(n),n=n.replace(/\[\]$/,""),!e){a[n]=t;return}if(a[n]===void 0){a[n]=[t];return}a[n]=[].concat(a[n],t)};case"comma":case"separator":return(n,t,a)=>{const c=typeof t=="string"&&t.includes(r.arrayFormatSeparator),f=typeof t=="string"&&!c&&h(t,r).includes(r.arrayFormatSeparator);t=f?h(t,r):t;const O=c||f?t.split(r.arrayFormatSeparator).map(N=>h(N,r)):t===null?t:h(t,r);a[n]=O};default:return(n,t,a)=>{if(a[n]===void 0){a[n]=t;return}a[n]=[].concat(a[n],t)}}}function S(r){if(typeof r!="string"||r.length!==1)throw new TypeError("arrayFormatSeparator must be single character string")}function d(r,e){return e.encode?e.strict?s(r):encodeURIComponent(r):r}function h(r,e){return e.decode?l(r):r}function j(r){return Array.isArray(r)?r.sort():typeof r=="object"?j(Object.keys(r)).sort((e,n)=>Number(e)-Number(n)).map(e=>r[e]):r}function g(r){const e=r.indexOf("#");return e!==-1&&(r=r.slice(0,e)),r}function $(r){let e="";const n=r.indexOf("#");return n!==-1&&(e=r.slice(n)),e}function b(r){r=g(r);const e=r.indexOf("?");return e===-1?"":r.slice(e+1)}function A(r,e){return e.parseNumbers&&!Number.isNaN(Number(r))&&typeof r=="string"&&r.trim()!==""?r=Number(r):e.parseBooleans&&r!==null&&(r.toLowerCase()==="true"||r.toLowerCase()==="false")&&(r=r.toLowerCase()==="true"),r}function U(r,e){e=Object.assign({decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1},e),S(e.arrayFormatSeparator);const n=y(e),t=Object.create(null);if(typeof r!="string"||(r=r.trim().replace(/^[?#&]/,""),!r))return t;for(const a of r.split("&")){if(a==="")continue;let[c,f]=o(e.decode?a.replace(/\+/g," "):a,"=");f=f===void 0?null:["comma","separator"].includes(e.arrayFormat)?f:h(f,e),n(h(c,e),f,t)}for(const a of Object.keys(t)){const c=t[a];if(typeof c=="object"&&c!==null)for(const f of Object.keys(c))c[f]=A(c[f],e);else t[a]=A(c,e)}return e.sort===!1?t:(e.sort===!0?Object.keys(t).sort():Object.keys(t).sort(e.sort)).reduce((a,c)=>{const f=t[c];return f&&typeof f=="object"&&!Array.isArray(f)?a[c]=j(f):a[c]=f,a},Object.create(null))}i.extract=b,i.parse=U,i.stringify=(r,e)=>{if(!r)return"";e=Object.assign({encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:","},e),S(e.arrayFormatSeparator);const n=f=>e.skipNull&&m(r[f])||e.skipEmptyString&&r[f]==="",t=u(e),a={};for(const f of Object.keys(r))n(f)||(a[f]=r[f]);const c=Object.keys(a);return e.sort!==!1&&c.sort(e.sort),c.map(f=>{const O=r[f];return O===void 0?"":O===null?d(f,e):Array.isArray(O)?O.reduce(t(f),[]).join("&"):d(f,e)+"="+d(O,e)}).filter(f=>f.length>0).join("&")},i.parseUrl=(r,e)=>{e=Object.assign({decode:!0},e);const[n,t]=o(r,"#");return Object.assign({url:n.split("?")[0]||"",query:U(b(r),e)},e&&e.parseFragmentIdentifier&&t?{fragmentIdentifier:h(t,e)}:{})},i.stringifyUrl=(r,e)=>{e=Object.assign({encode:!0,strict:!0},e);const n=g(r.url).split("?")[0]||"",t=i.extract(r.url),a=i.parse(t,{sort:!1}),c=Object.assign(a,r.query);let f=i.stringify(c,e);f&&(f=`?${f}`);let O=$(r.url);return r.fragmentIdentifier&&(O=`#${d(r.fragmentIdentifier,e)}`),`${n}${f}${O}`},i.pick=(r,e,n)=>{n=Object.assign({parseFragmentIdentifier:!0},n);const{url:t,query:a,fragmentIdentifier:c}=i.parseUrl(r,n);return i.stringifyUrl({url:t,query:F(a,e),fragmentIdentifier:c},n)},i.exclude=(r,e,n)=>{const t=Array.isArray(e)?a=>!e.includes(a):(a,c)=>!e(a,c);return i.pick(r,t,n)}})(E);const x=q(E),R=/^(\w+:\/\/[^/?]+)?(.*?)(\?.+)?$/,L=/^(\/\/[^/?]+)(.*?)(\?.+)?$/,T=i=>i.filter(s=>typeof s=="string"||typeof s=="number").map(s=>`${s}`).filter(s=>s),P=(i,s)=>{const{protocolRelative:l}=s,o=i.join("/"),F=l?L:R,[,m="",u="",y=""]=o.match(F)||[];return{prefix:m,pathname:{parts:u.split("/").filter(S=>S!==""),hasLeading:y?/^\/\/+/.test(u):/^\/+/.test(u),hasTrailing:y?/\/\/+$/.test(u):/\/+$/.test(u)},suffix:y}},B=(i,s)=>{const{prefix:l,pathname:o,suffix:F}=i,{parts:m,hasLeading:u,hasTrailing:y}=o,{leadingSlash:S,trailingSlash:d}=s,h=S===!0||S==="keep"&&u,j=d===!0||d==="keep"&&y;let g=l;m.length>0&&((g||h)&&(g+="/"),g+=m.join("/")),j&&(g+="/"),!g&&h&&(g+="/");const $={...x.parse(F,s.queryOptions),...s.query},b=x.stringify($,s.queryOptions);return b&&(g+=`?${b}`),g},k=(...i)=>{const s=i[i.length-1];let l;s&&typeof s=="object"&&(l=s,i=i.slice(0,-1)),l={leadingSlash:!0,trailingSlash:!1,protocolRelative:!1,...l},i=T(i);const o=P(i,l);return B(o,l)};export{k as u};
|