Best JavaScript code snippet using wpt
content_disposition.js
Source:content_disposition.js
...9 if (tmp) {10 tmp = tmp[1];11 let filename = rfc2616unquote(tmp);12 filename = unescape(filename);13 filename = rfc5987decode(filename);14 filename = rfc2047decode(filename);15 return fixupEncoding(filename);16 }17 tmp = rfc2231getparam(contentDisposition);18 if (tmp) {19 let filename = rfc2047decode(tmp);20 return fixupEncoding(filename);21 }22 tmp = toParamRegExp('filename', 'i').exec(contentDisposition);23 if (tmp) {24 tmp = tmp[1];25 let filename = rfc2616unquote(tmp);26 filename = rfc2047decode(filename);27 return fixupEncoding(filename);28 }29 function toParamRegExp(attributePattern, flags) {30 return new RegExp('(?:^|;)\\s*' + attributePattern + '\\s*=\\s*' + '(' + '[^";\\s][^;\\s]*' + '|' + '"(?:[^"\\\\]|\\\\"?)+"?' + ')', flags);31 }32 function textdecode(encoding, value) {33 if (encoding) {34 if (!/^[\x00-\xFF]+$/.test(value)) {35 return value;36 }37 try {38 let decoder = new TextDecoder(encoding, {39 fatal: true40 });41 let bytes = Array.from(value, function (ch) {42 return ch.charCodeAt(0) & 0xFF;43 });44 value = decoder.decode(new Uint8Array(bytes));45 needsEncodingFixup = false;46 } catch (e) {47 if (/^utf-?8$/i.test(encoding)) {48 try {49 value = decodeURIComponent(escape(value));50 needsEncodingFixup = false;51 } catch (err) {}52 }53 }54 }55 return value;56 }57 function fixupEncoding(value) {58 if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {59 value = textdecode('utf-8', value);60 if (needsEncodingFixup) {61 value = textdecode('iso-8859-1', value);62 }63 }64 return value;65 }66 function rfc2231getparam(contentDisposition) {67 let matches = [],68 match;69 let iter = toParamRegExp('filename\\*((?!0\\d)\\d+)(\\*?)', 'ig');70 while ((match = iter.exec(contentDisposition)) !== null) {71 let [, n, quot, part] = match;72 n = parseInt(n, 10);73 if (n in matches) {74 if (n === 0) {75 break;76 }77 continue;78 }79 matches[n] = [quot, part];80 }81 let parts = [];82 for (let n = 0; n < matches.length; ++n) {83 if (!(n in matches)) {84 break;85 }86 let [quot, part] = matches[n];87 part = rfc2616unquote(part);88 if (quot) {89 part = unescape(part);90 if (n === 0) {91 part = rfc5987decode(part);92 }93 }94 parts.push(part);95 }96 return parts.join('');97 }98 function rfc2616unquote(value) {99 if (value.startsWith('"')) {100 let parts = value.slice(1).split('\\"');101 for (let i = 0; i < parts.length; ++i) {102 let quotindex = parts[i].indexOf('"');103 if (quotindex !== -1) {104 parts[i] = parts[i].slice(0, quotindex);105 parts.length = i + 1;106 }107 parts[i] = parts[i].replace(/\\(.)/g, '$1');108 }109 value = parts.join('"');110 }111 return value;112 }113 function rfc5987decode(extvalue) {114 let encodingend = extvalue.indexOf('\'');115 if (encodingend === -1) {116 return extvalue;117 }118 let encoding = extvalue.slice(0, encodingend);119 let langvalue = extvalue.slice(encodingend + 1);120 let value = langvalue.replace(/^[^']*'/, '');121 return textdecode(encoding, value);122 }123 function rfc2047decode(value) {124 if (!value.startsWith('=?') || /[\x00-\x19\x80-\xff]/.test(value)) {125 return value;126 }127 return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (_, charset, encoding, text) {...
content_disposition.ts
Source:content_disposition.ts
...71 part = unquote(part);72 if (quote) {73 part = unescape(part);74 if (n === 0) {75 part = rfc5987decode(part);76 }77 }78 parts.push(part);79 }80 return parts.join("");81}82function rfc5987decode(value: string): string {83 const encodingEnd = value.indexOf(`'`);84 if (encodingEnd === -1) {85 return value;86 }87 const encoding = value.slice(0, encodingEnd);88 const langValue = value.slice(encodingEnd + 1);89 return textDecode(encoding, langValue.replace(/^[^']*'/, ""));90}91function textDecode(encoding: string, value: string): string {92 if (encoding) {93 try {94 const decoder = new TextDecoder(encoding, {fatal: true});95 const bytes = Array.from(value, (c) => c.charCodeAt(0));96 if (bytes.every((code) => code <= 0xff)) {97 value = decoder.decode(new Uint8Array(bytes));98 needsEncodingFixup = false;99 }100 // deno-lint-ignore no-empty101 } catch {}102 }103 return value;104}105export function getFilename(header: string): string {106 needsEncodingFixup = true;107 // filename*=ext-value ("ext-value" from RFC 5987, referenced by RFC 6266).108 let matches = FILENAME_STAR_REGEX.exec(header);109 if (matches) {110 const [, filename] = matches;111 return fixupEncoding(112 rfc2047decode(rfc5987decode(unescape(unquote(filename))))113 );114 }115 // Continuations (RFC 2231 section 3, referenced by RFC 5987 section 3.1).116 // filename*n*=part117 // filename*n=part118 const filename = rfc2231getParam(header);119 if (filename) {120 return fixupEncoding(rfc2047decode(filename));121 }122 // filename=value (RFC 5987, section 4.1).123 matches = FILENAME_REGEX.exec(header);124 if (matches) {125 const [, filename] = matches;126 return fixupEncoding(rfc2047decode(unquote(filename)));...
Using AI Code Generation
1var wptools = require('wptools');2var decoded = wptools.rfc5987decode('UTF-8\'\'%E4%BD%A0%E5%A5%BD');3var wptools = require('wptools');4var decoded = wptools.rfc5987decode('UTF-8\'\'%E4%BD%A0%E5%A5%BD');5var wptools = require('wptools');6var decoded = wptools.rfc5987decode('UTF-8\'\'%E4%BD%A0%E5%A5%BD');7var wptools = require('wptools');8var decoded = wptools.rfc5987decode('UTF-8\'\'%E4%BD%A0%E5%A5%BD');9var wptools = require('wptools');10var decoded = wptools.rfc5987decode('UTF-8\'\'%E4%BD%A0%E5%A5%BD');11var wptools = require('wptools');12var decoded = wptools.rfc5987decode('UTF-8\'\'%E4%BD%A0%E5%A5%BD');13var wptools = require('wptools');14var decoded = wptools.rfc5987decode('UTF-8\'\'%E4%BD%A0%E5%A5%BD');
Using AI Code Generation
1var rfc5987decode = require('./wpt-common.js').rfc5987decode;2console.log(rfc5987decode('UTF-8\'\'%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A'));3exports.rfc5987decode = function (str) {4 var match = str.match(/([^']*)'([^']*)'(.*)/);5 if (match) {6 var encoding = match[1];7 var lang = match[2];8 var encoded = match[3];9 return decodeURIComponent(encoded);10 }11 return str;12};
Using AI Code Generation
1var wptools = require('wptools');2var rfc5987decode = wptools.rfc5987decode;3console.log(rfc5987decode('en-us'));4var wptools = require('wptools');5var fetch = wptools.fetch;6 console.log(res);7});8var wptools = require('wptools');9var fetch = wptools.fetch;10 console.log(res);11});12var wptools = require('wptools');13var fetch = wptools.fetch;14 console.log(res);15});16var wptools = require('wptools');17var fetch = wptools.fetch;18 console.log(res);19});20var wptools = require('wptools');21var fetch = wptools.fetch;22 console.log(res);23});24var wptools = require('wptools');25var fetch = wptools.fetch;26 console.log(res);27});28var wptools = require('wptools');29var fetch = wptools.fetch;30 console.log(res);31});
Using AI Code Generation
1var wptools = require('wptools');2var result = wptools.rfc5987decode(url);3console.log(result);4 var result = wptools.rfc5987decode(url);5 console.log(result);6Copyright (c) 2017-2019 WPTT
Using AI Code Generation
1var rfc5987decode = require('wptools').rfc5987decode;2console.log(rfc5987decode('en-US;foo=bar;baz=quux'));3var rfc5987decode = require('wptools').rfc5987decode;4console.log(rfc5987decode('en-US;foo=bar;baz=quux'));5var rfc5987decode = require('wptools').rfc5987decode;6console.log(rfc5987decode('en-US;foo=bar;baz=quux'));7var rfc5987decode = require('wptools').rfc5987decode;8console.log(rfc5987decode('en-US;foo=bar;baz=quux'));9var rfc5987decode = require('wptools').rfc5987decode;10console.log(rfc5987decode('en-US;foo=bar;baz=quux'));11var rfc5987decode = require('wptools').rfc5987decode;12console.log(rfc5987decode('en-US;foo=bar;baz=quux'));13var rfc5987decode = require('wptools').rfc5987decode;14console.log(rfc
Using AI Code Generation
1var wptools = require('wptools');2var decoded = wptools.rfc5987decode(url);3console.log(decoded);4var wptools = require('wptools');5var encoded = wptools.rfc5987encode(url);6console.log(encoded);7var wptools = require('wptools');8var decoded = wptools.rfc5987decode(url);9console.log(decoded);10var wptools = require('wptools');11var encoded = wptools.rfc5987encode(url);12console.log(encoded);13var wptools = require('wptools');14var decoded = wptools.rfc5987decode(url);15console.log(decoded);16var wptools = require('wptools');17var encoded = wptools.rfc5987encode(url);18console.log(encoded);19var wptools = require('wptools');20var decoded = wptools.rfc5987decode(url);21console.log(decoded);22var wptools = require('wpt
Using AI Code Generation
1var decoded = jQuery.wptexturize.rfc5987decode('en-us\'\'%C3%A9');2console.log(decoded);3var decoded = jQuery('en-us\'\'%C3%A9').wptexturize.rfc5987decode();4console.log(decoded);5var decoded = jQuery('en-us\'\'%C3%A9').wptexturize.rfc5987decode();6console.log(decoded);7var decoded = jQuery('en-us\'\'%C3%A9').wptexturize.rfc5987decode();8console.log(decoded);9var decoded = jQuery('en-us\'\'%C3%A9').wptexturize.rfc5987decode();10console.log(decoded);11var decoded = jQuery('en-us\'\'%C3%A9').wptexturize.rfc5987decode();12console.log(decoded);13var decoded = jQuery('en-us\'\'%C3%A9').wptexturize.rfc5987decode();14console.log(decoded);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!