ios-dev/comments/Home/node_modules/@tinyhttp/content-disposition/dist/index.js.map

1 line
9.5 KiB
Plaintext
Raw Permalink Normal View History

2024-03-11 14:47:28 +03:00
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst ENCODE_URL_ATTR_CHAR_REGEXP = /[\\x00-\\x20\"'()*,/:;<=>?@[\\\\\\]{}\\x7f]/g\n\nconst HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/\nconst HEX_ESCAPE_REPLACE_REGEXP = /%([0-9A-Fa-f]{2})/g\n\nconst NON_LATIN1_REGEXP = /[^\\x20-\\x7e\\xa0-\\xff]/g\n\n// eslint-disable-next-line no-control-regex\nconst QESC_REGEXP = /\\\\([\\u0000-\\u007f])/g\n\nconst QUOTE_REGEXP = /([\\\\\"])/g\n\nconst PARAM_REGEXP =\n /;[\\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 // eslint-disable-line no-control-regex\nconst TEXT_REGEXP = /^[\\x20-\\x7e\\x80-\\xff]+$/\nconst TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/\n\nconst EXT_VALUE_REGEXP =\n /^([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!#$&+.^_`|~-])+)$/\n\n// eslint-disable-next-line no-control-regex\nconst DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\\x09\\x20]*(?:$|;)/\n\nconst getlatin1 = (val: unknown) => {\n // simple Unicode -> ISO-8859-1 transformation\n return String(val).replace(NON_LATIN1_REGEXP, '?')\n}\n\nexport class ContentDisposition {\n type: string\n parameters: Record<string, unknown>\n constructor(type: string, parameters: Record<string, unknown>) {\n this.type = type\n this.parameters = parameters\n }\n}\n\nconst qstring = (val: unknown) => '\"' + String(val).replace(QUOTE_REGEXP, '\\\\$1') + '\"'\n\nconst pencode = (char: string) => '%' + String(char).charCodeAt(0).toString(16).toUpperCase()\n\nfunction ustring(val: unknown): string {\n const str = String(val)\n\n // percent encode as UTF-8\n const encoded = encodeURIComponent(str).replace(ENCODE_URL_ATTR_CHAR_REGEXP, pencode)\n\n return \"UTF-8''\" + encoded\n}\n\nconst basename = (str: string) => str.slice(str.lastIndexOf('/') + 1)\n\nfunction format({\n parameters,\n type\n}: Partial<{\n parameters: Record<string, unknown>\n type: string | boolean | undefined\n}>) {\n if (!type || typeof type !== 'string' || !TOKEN_REGEXP.test(type)) {\n throw new TypeError('invalid type')\n }\n\n // start with normalized type\n let string = String(type).toLowerCase()\n\n // append parameters\n if (parameters && typeof parameters === 'object') {\n const params = Object.keys(parameters).sort()\n\n for (const param of params) {\n const val = param.slice(-1) === '*' ? ustring(parameters[param]) : qstring(parameters[param])\n\n string += '; ' + param + '=' + val\n }\n }\n\n return string\n}\n\nfunction createParams(filename?: string, fallback?: string | boolean) {\n if (filename === undefined) return\n\n const params: Partial<\n Record<string, string> & {\n filename: string\n }\n > = {}\n\n // fallback defaults to true\n if (fallback === undefined) fallback = true\n\n if (typeof fallback === 'string' && NON_LATIN1_REGEXP.test(fallback)) {\n throw new TypeError('fallback must be ISO-8859-1 string')\n }\n\n // restrict to file base name\n const name = basename(filename)\n\n // determine if name is suitable for quoted string\n const isQuotedString = TEXT_REGEXP.test(name)\n\n // generate fallback name\n const fallbackName = typeof fallback !== 'string' ? fallback && getlatin1(name) : basename(fallback)\n const hasFallback = typeof fallbackName === 'string' && fallbackName !== name\n\n // set extended filename parameter\n if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) {\n params['filename*'] = name\n }\n\n // set filename parameter\n if (isQuotedString || hasFallback) {\n params.filename = hasFallback ? fallbackName : name\n }\n\n return params\n}\n\nconst pdecode = (_str: string, hex: string) => String.fromCharCode(parseInt(hex, 16))\n\n/**\n * Create an attachment Content-Disposition header.\n *\n * @param filename file name\n * @param options\n */\n\nexport function contentDisposition(\