swc/crates/swc_bundler/tests/.cache/untrusted/034fc63657ef89e7081cc0dd9c1dfa2525307627.ts
2021-11-09 20:42:49 +09:00

6 lines
2.8 KiB
TypeScript

// Loaded from https://cdn.esm.sh/v45/@tinyhttp/content-disposition@1.3.0/es2015/content-disposition.js
/* esm.sh - esbuild bundle(@tinyhttp/content-disposition@1.3.0) es2015 production */
import { Buffer as __Buffer$ } from "/v45/node_buffer.js";import{basename as f}from"/v45/path-browserify@1.0.1/es2015/path-browserify.js";var p=/[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g,u=/%[0-9A-Fa-f]{2}/,l=/%([0-9A-Fa-f]{2})/g,E=/[^\x20-\x7e\xa0-\xff]/g,g=/\\([\u0000-\u007f])/g,h=/([\\"])/g,x=/;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g,_=/^[\x20-\x7e\x80-\xff]+$/,w=/^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/,m=/^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/,A=/^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/,d=e=>String(e).replace(E,"?"),c=class{constructor(t,r){this.type=t,this.parameters=r}},y=e=>'"'+String(e).replace(h,"\\$1")+'"',T=e=>"%"+String(e).charCodeAt(0).toString(16).toUpperCase();function P(e){let t=String(e),r=encodeURIComponent(t).replace(p,T);return"UTF-8''"+r}function R({parameters:e,type:t}){if(!t||typeof t!="string"||!w.test(t))throw new TypeError("invalid type");let r=String(t).toLowerCase();if(e&&typeof e=="object"){let o=Object.keys(e).sort();for(let n of o){let s=n.substr(-1)==="*"?P(e[n]):y(e[n]);r+="; "+n+"="+s}}return r}function C(e,t){if(e===void 0)return;let r={};if(t===void 0&&(t=!0),typeof t=="string"&&E.test(t))throw new TypeError("fallback must be ISO-8859-1 string");let o=f(e),n=_.test(o),s=typeof t!="string"?t&&d(o):f(t),a=typeof s=="string"&&s!==o;return(a||!n||u.test(o))&&(r["filename*"]=o),(n||a)&&(r.filename=a?s:o),r}var S=(e,t)=>String.fromCharCode(parseInt(t,16));function G(e,t={}){return R(new c(t.type||"attachment",C(e,t.fallback)))}function X(e){let t=m.exec(e);if(!t)throw new TypeError("invalid extended field value");let r=t[1].toLowerCase(),o=t[2],n,s=o.replace(l,S);switch(r){case"iso-8859-1":n=d(s);break;case"utf-8":n=__Buffer$.from(s,"binary").toString("utf8");break;default:throw new TypeError("unsupported charset in extended field")}return n}function b(e){let t=A.exec(e);if(!t)throw new TypeError("invalid type format");let r=t[0].length,o=t[1].toLowerCase(),n,s=[],a={},i;for(r=x.lastIndex=t[0].substr(-1)===";"?r-1:r;t=x.exec(e);){if(t.index!==r)throw new TypeError("invalid parameter format");if(r+=t[0].length,n=t[1].toLowerCase(),i=t[2],s.indexOf(n)!==-1)throw new TypeError("invalid duplicate parameter");if(s.push(n),n.indexOf("*")+1===n.length){n=n.slice(0,-1),i=X(i),a[n]=i;continue}typeof a[n]!="string"&&(i[0]==='"'&&(i=i.substr(1,i.length-2).replace(g,"$1")),a[n]=i)}if(r!==-1&&r!==e.length)throw new TypeError("invalid parameter format");return new c(o,a)}export{c as ContentDisposition,G as contentDisposition,b as parse};