New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mhtml2html

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mhtml2html - npm Package Compare versions

Comparing version
1.3.2
to
2.0.0
+1
-8
dist/mhtml2html.js

@@ -1,8 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mhtml2html=e():t.mhtml2html=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,r){"use strict";const n=r(3),o=r(4),i=r(9);let s,a;function h(t,e){if(!t)throw new Error(e);return!0}function u(t,e,r){let n,s;for(s=0;(s=r.indexOf("url(",s))>0;s+=n.length){s+="url(".length,n=r.substring(s,r.indexOf(")",s));const a=i.resolve(e,n.replace(/(\"|\')/g,""));if(null!=t[a])try{const e=`'data:${t[a].type};base64,${"base64"===t[a].encoding?t[a].data:o(t[a].data)}'`;r=`${r.substring(0,s)}${e}${r.substring(s+n.length)}`}catch(t){console.warn(t)}}return r}const f={noConflict:()=>("undefined"!=typeof window&&(window.mhtml2html=s),f),parse:(t,e)=>{const r=0,o=1,i=2,s=3;let u,f,c,l,p,d,g,y,m,v,w,b,A,E,R,x;function _(){for(;h(E<t.length-1,"Unexpected EOF")&&/\s/.test(t[E]);)"\n"==t[++E]&&R++}function T(e){const r=E;for(;"\n"!==t[E]&&h(E++<t.length-1,"Unexpected EOF"););E++,R++;const o=t.substring(r,E);switch(e){case"quoted-printable":return n.decode(o);case"base64":return o.trim();default:return o}}function P(t,e){let r;(r=t.indexOf(":"))>-1?e[w=t.substring(0,r).trim()]=t.substring(r+1,t.length).trim():(h(void 0!==w,`Missing MHTML headers; Line ${R}`),e[w]+=t.trim())}for(f={},c={},l={},p={},v=r,E=R=0;v!=s;)switch(v){case r:if(0!=(b=T())&&"\n"!=b)P(b,f);else{h(void 0!==f["Content-Type"],`Missing document content type; Line ${R}`);const t=f["Content-Type"].match(/boundary=(.*)/m);h(null!=t,`Missing boundary from document headers; Line ${R}`),x=t[1].replace(/\"/g,""),_(),h((b=T()).includes(x),`Expected boundary; Line ${R}`),c={},v=o}break;case o:0!=(b=T())&&"\n"!=b?P(b,c):(g=c["Content-Transfer-Encoding"],y=c["Content-Type"],m=c["Content-ID"],d=c["Content-Location"],void 0===A&&h(void 0!==(A=d)&&"text/html"===y,`Index not found; Line ${R}`),h(void 0!==m||void 0!==d,`ID or location header not provided; Line ${R}`),h(void 0!==g,`Content-Transfer-Encoding not provided; Line ${R}`),h(void 0!==y,`Content-Type not provided; Line ${R}`),u={encoding:g,type:y,data:"",id:m},void 0!==m&&(p[m]=u),void 0!==d&&void 0===l[d]&&(l[d]=u),_(),c={},v=i);break;case i:for(b=T(g);!b.includes(x);)u.data+=b,b=T(g);try{u.data=decodeURIComponent(escape(u.data))}catch(t){}if(!0===e&&void 0!==A)return a(u.data);v=E>=t.length-1?s:o}return{frames:p,media:l,index:A}},convert:t=>{let e,r,i,s,c,l,p,d,g,y;"string"==typeof t?t=f.parse(t):h("object"==typeof t,"Expected argument of type string or object"),c=t.frames,s=t.media,i=t.index,h("object"==typeof c,"MHTML error: invalid frames"),h("object"==typeof s,"MHTML error: invalid media"),h("string"==typeof i,"MHTML error: invalid index"),h(s[i]&&"text/html"===s[i].type,"MHTML error: invalid index");const m=a(s[i].data),v=[m];for(;v.length;){const t=v.shift();t.childNodes.forEach(function(a){switch(a.getAttribute&&(g=a.getAttribute("href"),y=a.getAttribute("src")),a.removeAttribute&&a.removeAttribute("integrity"),a.tagName){case"HEAD":(p=m.createElement("base")).setAttribute("target","_parent"),a.insertBefore(p,a.firstChild);break;case"LINK":void 0!==s[g]&&"text/css"===s[g].type&&((l=m.createElement("style")).type="text/css",s[g].data=u(s,g,s[g].data),l.appendChild(m.createTextNode(s[g].data)),t.replaceChild(l,a));break;case"STYLE":(l=m.createElement("style")).type="text/css",l.appendChild(m.createTextNode(u(s,i,a.innerHTML))),t.replaceChild(l,a);break;case"IMG":if(d=null,void 0!==s[y]&&s[y].type.includes("image")){switch(s[y].encoding){case"quoted-printable":e=n.decode(s[y].data),d=`data:${s[y].type};utf8,${e}`;break;case"base64":d=`data:${s[y].type};base64,${s[y].data}`;break;default:try{r=o(s[y].data),d=`data:${s[y].type};base64,${r}`}catch(t){console.warn(t)}}null!==d&&a.setAttribute("src",d)}a.style.cssText=u(s,i,a.style.cssText);break;default:a.style&&(a.style.cssText=u(s,i,a.style.cssText))}v.push(a)})}return m}};!function(){if("undefined"!=typeof window&&(s=window.mhtml2html),"undefined"==typeof DOMParser){const t=require("jsdom").jsdom;a=e=>t(e,{})}else{const t=new DOMParser;a=e=>t.parseFromString(e,"text/html")}}(),t.exports=f},function(t,e,r){(function(t,n){var o;/*! https://mths.be/quoted-printable v1.0.1 by @mathias | MIT license */!function(i){var s=e,a=(t&&t.exports,"object"==typeof n&&n);a.global!==a&&a.window;var h=String.fromCharCode,u=function(t){return t.replace(/\x20$/,"=20").replace(/\t$/,"=09")},f=/[\0-\x08\n-\x1F=\x7F-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,c={encode:function(t){for(var e=t.replace(f,function(t){if(t>"ÿ")throw RangeError("`quotedPrintable.encode()` expects extended ASCII input only. Don’t forget to encode the input first using a character encoding like UTF-8.");return"="+("0"+t.charCodeAt(0).toString(16).toUpperCase()).slice(-2)}),r=e.split(/\r\n?|\n/g),n=-1,o=r.length,i=[];++n<o;)for(var s=75,a=0,h=r[n].length;a<h;){var c=e.slice(a,a+s);/=$/.test(c)?(c=c.slice(0,s-1),a+=s-1):/=[A-F0-9]$/.test(c)?(c=c.slice(0,s-2),a+=s-2):a+=s,i.push(c)}var l=c.length;return/[\t\x20]$/.test(c)&&(i.pop(),l+2<=s+1?i.push(u(c)):i.push(c.slice(0,l-1),u(c.slice(l-1,l)))),i.join("=\r\n")},decode:function(t){return t.replace(/[\t\x20]$/gm,"").replace(/=(?:\r\n?|\n|$)/g,"").replace(/=([a-fA-F0-9]{2})/g,function(t,e){var r=parseInt(e,16);return h(r)})},version:"1.0.1"};void 0===(o=function(){return c}.call(e,r,e,t))||(t.exports=o)}()}).call(this,r(1)(t),r(0))},function(t,e,r){(function(e){!function(){"use strict";t.exports=function(t){return(t instanceof e?t:e.from(t.toString(),"binary")).toString("base64")}}()}).call(this,r(5).Buffer)},function(t,e,r){"use strict";(function(t){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @license MIT
*/
var n=r(6),o=r(7),i=r(8);function s(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,e){if(s()<e)throw new RangeError("Invalid typed array length");return h.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=h.prototype:(null===t&&(t=new h(e)),t.length=e),t}function h(t,e,r){if(!(h.TYPED_ARRAY_SUPPORT||this instanceof h))return new h(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return c(this,t)}return u(this,t,e,r)}function u(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);h.TYPED_ARRAY_SUPPORT?(t=e).__proto__=h.prototype:t=l(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!h.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|d(e,r),o=(t=a(t,n)).write(e,r);o!==n&&(t=t.slice(0,o));return t}(t,e,r):function(t,e){if(h.isBuffer(e)){var r=0|p(e.length);return 0===(t=a(t,r)).length?t:(e.copy(t,0,0,r),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?a(t,0):l(t,e);if("Buffer"===e.type&&i(e.data))return l(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function f(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function c(t,e){if(f(e),t=a(t,e<0?0:0|p(e)),!h.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function l(t,e){var r=e.length<0?0:0|p(e.length);t=a(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function p(t){if(t>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function d(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return $(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return N(t).length;default:if(n)return $(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return T(this,e,r);case"ascii":return O(this,e,r);case"latin1":case"binary":return C(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function m(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:v(t,e,r,n,o);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):v(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function v(t,e,r,n,o){var i,s=1,a=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,h/=2,r/=2}function u(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var f=-1;for(i=r;i<a;i++)if(u(t,i)===u(e,-1===f?0:i-f)){if(-1===f&&(f=i),i-f+1===h)return f*s}else-1!==f&&(i-=i-f),f=-1}else for(r+h>a&&(r=a-h),i=r;i>=0;i--){for(var c=!0,l=0;l<h;l++)if(u(t,i+l)!==u(e,l)){c=!1;break}if(c)return i}return-1}function w(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[r+s]=a}return s}function b(t,e,r,n){return q($(e,t.length-r),t,r,n)}function A(t,e,r,n){return q(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function E(t,e,r,n){return A(t,e,r,n)}function R(t,e,r,n){return q(N(e),t,r,n)}function x(t,e,r,n){return q(function(t,e){for(var r,n,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function _(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function T(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,s,a,h,u=t[o],f=null,c=u>239?4:u>223?3:u>191?2:1;if(o+c<=r)switch(c){case 1:u<128&&(f=u);break;case 2:128==(192&(i=t[o+1]))&&(h=(31&u)<<6|63&i)>127&&(f=h);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&(h=(15&u)<<12|(63&i)<<6|63&s)>2047&&(h<55296||h>57343)&&(f=h);break;case 4:i=t[o+1],s=t[o+2],a=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(h=(15&u)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&h<1114112&&(f=h)}null===f?(f=65533,c=1):f>65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),o+=c}return function(t){var e=t.length;if(e<=P)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=P));return r}(n)}e.Buffer=h,e.SlowBuffer=function(t){+t!=t&&(t=0);return h.alloc(+t)},e.INSPECT_MAX_BYTES=50,h.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=s(),h.poolSize=8192,h._augment=function(t){return t.__proto__=h.prototype,t},h.from=function(t,e,r){return u(null,t,e,r)},h.TYPED_ARRAY_SUPPORT&&(h.prototype.__proto__=Uint8Array.prototype,h.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&h[Symbol.species]===h&&Object.defineProperty(h,Symbol.species,{value:null,configurable:!0})),h.alloc=function(t,e,r){return function(t,e,r,n){return f(e),e<=0?a(t,e):void 0!==r?"string"==typeof n?a(t,e).fill(r,n):a(t,e).fill(r):a(t,e)}(null,t,e,r)},h.allocUnsafe=function(t){return c(null,t)},h.allocUnsafeSlow=function(t){return c(null,t)},h.isBuffer=function(t){return!(null==t||!t._isBuffer)},h.compare=function(t,e){if(!h.isBuffer(t)||!h.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},h.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},h.concat=function(t,e){if(!i(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return h.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=h.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){var s=t[r];if(!h.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,o),o+=s.length}return n},h.byteLength=d,h.prototype._isBuffer=!0,h.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)y(this,e,e+1);return this},h.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)y(this,e,e+3),y(this,e+1,e+2);return this},h.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},h.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?T(this,0,t):g.apply(this,arguments)},h.prototype.equals=function(t){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===h.compare(this,t)},h.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},h.prototype.compare=function(t,e,r,n,o){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),a=Math.min(i,s),u=this.slice(n,o),f=t.slice(e,r),c=0;c<a;++c)if(u[c]!==f[c]){i=u[c],s=f[c];break}return i<s?-1:s<i?1:0},h.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},h.prototype.indexOf=function(t,e,r){return m(this,t,e,r,!0)},h.prototype.lastIndexOf=function(t,e,r){return m(this,t,e,r,!1)},h.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return w(this,t,e,r);case"utf8":case"utf-8":return b(this,t,e,r);case"ascii":return A(this,t,e,r);case"latin1":case"binary":return E(this,t,e,r);case"base64":return R(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var P=4096;function O(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function C(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function U(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=F(t[i]);return o}function S(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function I(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,o,i){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function j(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o<i;++o)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function M(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o<i;++o)t[r+o]=e>>>8*(n?o:3-o)&255}function L(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Y(t,e,r,n,i){return i||L(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function D(t,e,r,n,i){return i||L(t,0,r,8),o.write(t,e,r,n,52,8),r+8}h.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),h.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=h.prototype;else{var o=e-t;r=new h(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+t]}return r},h.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||I(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},h.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||I(t,e,this.length);for(var n=this[t+--e],o=1;e>0&&(o*=256);)n+=this[t+--e]*o;return n},h.prototype.readUInt8=function(t,e){return e||I(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||I(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||I(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||I(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||I(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||I(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||I(t,e,this.length);for(var n=e,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},h.prototype.readInt8=function(t,e){return e||I(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||I(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt16BE=function(t,e){e||I(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt32LE=function(t,e){return e||I(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||I(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||I(t,4,this.length),o.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||I(t,4,this.length),o.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||I(t,8,this.length),o.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||I(t,8,this.length),o.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},h.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},h.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):j(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):j(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):M(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);B(this,t,e,r,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i<r&&(s*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+r},h.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);B(this,t,e,r,o-1,-o)}var i=r-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+r},h.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):j(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):j(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):M(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,r){return Y(this,t,e,!0,r)},h.prototype.writeFloatBE=function(t,e,r){return Y(this,t,e,!1,r)},h.prototype.writeDoubleLE=function(t,e,r){return D(this,t,e,!0,r)},h.prototype.writeDoubleBE=function(t,e,r){return D(this,t,e,!1,r)},h.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o,i=n-r;if(this===t&&r<e&&e<n)for(o=i-1;o>=0;--o)t[o+e]=this[o+r];else if(i<1e3||!h.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},h.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!h.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{var s=h.isBuffer(t)?t:$(new h(t,n).toString()),a=s.length;for(i=0;i<r-e;++i)this[i+e]=s[i%a]}return this};var k=/[^+\/0-9A-Za-z-_]/g;function F(t){return t<16?"0"+t.toString(16):t.toString(16)}function $(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],s=0;s<n;++s){if((r=t.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function N(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(k,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function q(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}}).call(this,r(0))},function(t,e,r){"use strict";e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=u(t),s=n[0],a=n[1],h=new i(function(t,e,r){return 3*(e+r)/4-r}(0,s,a)),f=0,c=a>0?s-4:s;for(r=0;r<c;r+=4)e=o[t.charCodeAt(r)]<<18|o[t.charCodeAt(r+1)]<<12|o[t.charCodeAt(r+2)]<<6|o[t.charCodeAt(r+3)],h[f++]=e>>16&255,h[f++]=e>>8&255,h[f++]=255&e;2===a&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,h[f++]=255&e);1===a&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,h[f++]=e>>8&255,h[f++]=255&e);return h},e.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],s=0,a=r-o;s<a;s+=16383)i.push(f(t,s,s+16383>a?a:s+16383));1===o?(e=t[r-1],i.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,h=s.length;a<h;++a)n[a]=s[a],o[s.charCodeAt(a)]=a;function u(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function f(t,e,r){for(var o,i,s=[],a=e;a<r;a+=3)o=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,r,n,o){var i,s,a=8*o-n-1,h=(1<<a)-1,u=h>>1,f=-7,c=r?o-1:0,l=r?-1:1,p=t[e+c];for(c+=l,i=p&(1<<-f)-1,p>>=-f,f+=a;f>0;i=256*i+t[e+c],c+=l,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=n;f>0;s=256*s+t[e+c],c+=l,f-=8);if(0===i)i=1-u;else{if(i===h)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=u}return(p?-1:1)*s*Math.pow(2,i-n)},e.write=function(t,e,r,n,o,i){var s,a,h,u=8*i-o-1,f=(1<<u)-1,c=f>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-s))<1&&(s--,h*=2),(e+=s+c>=1?l/h:l*Math.pow(2,1-c))*h>=2&&(s++,h/=2),s+c>=f?(a=0,s=f):s+c>=1?(a=(e*h-1)*Math.pow(2,o),s+=c):(a=e*Math.pow(2,c-1)*Math.pow(2,o),s=0));o>=8;t[r+p]=255&a,p+=d,a/=256,o-=8);for(s=s<<o|a,u+=o;u>0;t[r+p]=255&s,p+=d,s/=256,u-=8);t[r+p-d]|=128*g}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},function(t,e,r){"use strict";var n=r(10),o=r(11);function i(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}e.parse=w,e.resolve=function(t,e){return w(t,!1,!0).resolve(e)},e.resolveObject=function(t,e){return t?w(t,!1,!0).resolveObject(e):e},e.format=function(t){o.isString(t)&&(t=w(t));return t instanceof i?t.format():i.prototype.format.call(t)},e.Url=i;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,h=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),f=["'"].concat(u),c=["%","/","?",";","#"].concat(f),l=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,g={javascript:!0,"javascript:":!0},y={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},v=r(12);function w(t,e,r){if(t&&o.isObject(t)&&t instanceof i)return t;var n=new i;return n.parse(t,e,r),n}i.prototype.parse=function(t,e,r){if(!o.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var i=t.indexOf("?"),a=-1!==i&&i<t.indexOf("#")?"?":"#",u=t.split(a);u[0]=u[0].replace(/\\/g,"/");var w=t=u.join(a);if(w=w.trim(),!r&&1===t.split("#").length){var b=h.exec(w);if(b)return this.path=w,this.href=w,this.pathname=b[1],b[2]?(this.search=b[2],this.query=e?v.parse(this.search.substr(1)):this.search.substr(1)):e&&(this.search="",this.query={}),this}var A=s.exec(w);if(A){var E=(A=A[0]).toLowerCase();this.protocol=E,w=w.substr(A.length)}if(r||A||w.match(/^\/\/[^@\/]+@[^@\/]+/)){var R="//"===w.substr(0,2);!R||A&&y[A]||(w=w.substr(2),this.slashes=!0)}if(!y[A]&&(R||A&&!m[A])){for(var x,_,T=-1,P=0;P<l.length;P++){-1!==(O=w.indexOf(l[P]))&&(-1===T||O<T)&&(T=O)}-1!==(_=-1===T?w.lastIndexOf("@"):w.lastIndexOf("@",T))&&(x=w.slice(0,_),w=w.slice(_+1),this.auth=decodeURIComponent(x)),T=-1;for(P=0;P<c.length;P++){var O;-1!==(O=w.indexOf(c[P]))&&(-1===T||O<T)&&(T=O)}-1===T&&(T=w.length),this.host=w.slice(0,T),w=w.slice(T),this.parseHost(),this.hostname=this.hostname||"";var C="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!C)for(var U=this.hostname.split(/\./),S=(P=0,U.length);P<S;P++){var I=U[P];if(I&&!I.match(p)){for(var B="",j=0,M=I.length;j<M;j++)I.charCodeAt(j)>127?B+="x":B+=I[j];if(!B.match(p)){var L=U.slice(0,P),Y=U.slice(P+1),D=I.match(d);D&&(L.push(D[1]),Y.unshift(D[2])),Y.length&&(w="/"+Y.join(".")+w),this.hostname=L.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),C||(this.hostname=n.toASCII(this.hostname));var k=this.port?":"+this.port:"",F=this.hostname||"";this.host=F+k,this.href+=this.host,C&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==w[0]&&(w="/"+w))}if(!g[E])for(P=0,S=f.length;P<S;P++){var $=f[P];if(-1!==w.indexOf($)){var N=encodeURIComponent($);N===$&&(N=escape($)),w=w.split($).join(N)}}var q=w.indexOf("#");-1!==q&&(this.hash=w.substr(q),w=w.slice(0,q));var z=w.indexOf("?");if(-1!==z?(this.search=w.substr(z),this.query=w.substr(z+1),e&&(this.query=v.parse(this.query)),w=w.slice(0,z)):e&&(this.search="",this.query={}),w&&(this.pathname=w),m[E]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){k=this.pathname||"";var H=this.search||"";this.path=k+H}return this.href=this.format(),this},i.prototype.format=function(){var t=this.auth||"";t&&(t=(t=encodeURIComponent(t)).replace(/%3A/i,":"),t+="@");var e=this.protocol||"",r=this.pathname||"",n=this.hash||"",i=!1,s="";this.host?i=t+this.host:this.hostname&&(i=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(s=v.stringify(this.query));var a=this.search||s&&"?"+s||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||m[e])&&!1!==i?(i="//"+(i||""),r&&"/"!==r.charAt(0)&&(r="/"+r)):i||(i=""),n&&"#"!==n.charAt(0)&&(n="#"+n),a&&"?"!==a.charAt(0)&&(a="?"+a),e+i+(r=r.replace(/[?#]/g,function(t){return encodeURIComponent(t)}))+(a=a.replace("#","%23"))+n},i.prototype.resolve=function(t){return this.resolveObject(w(t,!1,!0)).format()},i.prototype.resolveObject=function(t){if(o.isString(t)){var e=new i;e.parse(t,!1,!0),t=e}for(var r=new i,n=Object.keys(this),s=0;s<n.length;s++){var a=n[s];r[a]=this[a]}if(r.hash=t.hash,""===t.href)return r.href=r.format(),r;if(t.slashes&&!t.protocol){for(var h=Object.keys(t),u=0;u<h.length;u++){var f=h[u];"protocol"!==f&&(r[f]=t[f])}return m[r.protocol]&&r.hostname&&!r.pathname&&(r.path=r.pathname="/"),r.href=r.format(),r}if(t.protocol&&t.protocol!==r.protocol){if(!m[t.protocol]){for(var c=Object.keys(t),l=0;l<c.length;l++){var p=c[l];r[p]=t[p]}return r.href=r.format(),r}if(r.protocol=t.protocol,t.host||y[t.protocol])r.pathname=t.pathname;else{for(var d=(t.pathname||"").split("/");d.length&&!(t.host=d.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==d[0]&&d.unshift(""),d.length<2&&d.unshift(""),r.pathname=d.join("/")}if(r.search=t.search,r.query=t.query,r.host=t.host||"",r.auth=t.auth,r.hostname=t.hostname||t.host,r.port=t.port,r.pathname||r.search){var g=r.pathname||"",v=r.search||"";r.path=g+v}return r.slashes=r.slashes||t.slashes,r.href=r.format(),r}var w=r.pathname&&"/"===r.pathname.charAt(0),b=t.host||t.pathname&&"/"===t.pathname.charAt(0),A=b||w||r.host&&t.pathname,E=A,R=r.pathname&&r.pathname.split("/")||[],x=(d=t.pathname&&t.pathname.split("/")||[],r.protocol&&!m[r.protocol]);if(x&&(r.hostname="",r.port=null,r.host&&(""===R[0]?R[0]=r.host:R.unshift(r.host)),r.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===d[0]?d[0]=t.host:d.unshift(t.host)),t.host=null),A=A&&(""===d[0]||""===R[0])),b)r.host=t.host||""===t.host?t.host:r.host,r.hostname=t.hostname||""===t.hostname?t.hostname:r.hostname,r.search=t.search,r.query=t.query,R=d;else if(d.length)R||(R=[]),R.pop(),R=R.concat(d),r.search=t.search,r.query=t.query;else if(!o.isNullOrUndefined(t.search)){if(x)r.hostname=r.host=R.shift(),(C=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@"))&&(r.auth=C.shift(),r.host=r.hostname=C.shift());return r.search=t.search,r.query=t.query,o.isNull(r.pathname)&&o.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!R.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var _=R.slice(-1)[0],T=(r.host||t.host||R.length>1)&&("."===_||".."===_)||""===_,P=0,O=R.length;O>=0;O--)"."===(_=R[O])?R.splice(O,1):".."===_?(R.splice(O,1),P++):P&&(R.splice(O,1),P--);if(!A&&!E)for(;P--;P)R.unshift("..");!A||""===R[0]||R[0]&&"/"===R[0].charAt(0)||R.unshift(""),T&&"/"!==R.join("/").substr(-1)&&R.push("");var C,U=""===R[0]||R[0]&&"/"===R[0].charAt(0);x&&(r.hostname=r.host=U?"":R.length?R.shift():"",(C=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@"))&&(r.auth=C.shift(),r.host=r.hostname=C.shift()));return(A=A||r.host&&R.length)&&!U&&R.unshift(""),R.length?r.pathname=R.join("/"):(r.pathname=null,r.path=null),o.isNull(r.pathname)&&o.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=t.auth||r.auth,r.slashes=r.slashes||t.slashes,r.href=r.format(),r},i.prototype.parseHost=function(){var t=this.host,e=a.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},function(t,e,r){(function(t,n){var o;/*! https://mths.be/punycode v1.4.1 by @mathias */!function(i){e&&e.nodeType,t&&t.nodeType;var s="object"==typeof n&&n;s.global!==s&&s.window!==s&&s.self;var a,h=2147483647,u=36,f=1,c=26,l=38,p=700,d=72,g=128,y="-",m=/^xn--/,v=/[^\x20-\x7E]/,w=/[\x2E\u3002\uFF0E\uFF61]/g,b={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},A=u-f,E=Math.floor,R=String.fromCharCode;function x(t){throw new RangeError(b[t])}function _(t,e){for(var r=t.length,n=[];r--;)n[r]=e(t[r]);return n}function T(t,e){var r=t.split("@"),n="";return r.length>1&&(n=r[0]+"@",t=r[1]),n+_((t=t.replace(w,".")).split("."),e).join(".")}function P(t){for(var e,r,n=[],o=0,i=t.length;o<i;)(e=t.charCodeAt(o++))>=55296&&e<=56319&&o<i?56320==(64512&(r=t.charCodeAt(o++)))?n.push(((1023&e)<<10)+(1023&r)+65536):(n.push(e),o--):n.push(e);return n}function O(t){return _(t,function(t){var e="";return t>65535&&(e+=R((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=R(t)}).join("")}function C(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function U(t,e,r){var n=0;for(t=r?E(t/p):t>>1,t+=E(t/e);t>A*c>>1;n+=u)t=E(t/A);return E(n+(A+1)*t/(t+l))}function S(t){var e,r,n,o,i,s,a,l,p,m,v,w=[],b=t.length,A=0,R=g,_=d;for((r=t.lastIndexOf(y))<0&&(r=0),n=0;n<r;++n)t.charCodeAt(n)>=128&&x("not-basic"),w.push(t.charCodeAt(n));for(o=r>0?r+1:0;o<b;){for(i=A,s=1,a=u;o>=b&&x("invalid-input"),((l=(v=t.charCodeAt(o++))-48<10?v-22:v-65<26?v-65:v-97<26?v-97:u)>=u||l>E((h-A)/s))&&x("overflow"),A+=l*s,!(l<(p=a<=_?f:a>=_+c?c:a-_));a+=u)s>E(h/(m=u-p))&&x("overflow"),s*=m;_=U(A-i,e=w.length+1,0==i),E(A/e)>h-R&&x("overflow"),R+=E(A/e),A%=e,w.splice(A++,0,R)}return O(w)}function I(t){var e,r,n,o,i,s,a,l,p,m,v,w,b,A,_,T=[];for(w=(t=P(t)).length,e=g,r=0,i=d,s=0;s<w;++s)(v=t[s])<128&&T.push(R(v));for(n=o=T.length,o&&T.push(y);n<w;){for(a=h,s=0;s<w;++s)(v=t[s])>=e&&v<a&&(a=v);for(a-e>E((h-r)/(b=n+1))&&x("overflow"),r+=(a-e)*b,e=a,s=0;s<w;++s)if((v=t[s])<e&&++r>h&&x("overflow"),v==e){for(l=r,p=u;!(l<(m=p<=i?f:p>=i+c?c:p-i));p+=u)_=l-m,A=u-m,T.push(R(C(m+_%A,0))),l=E(_/A);T.push(R(C(l,0))),i=U(r,b,n==o),r=0,++n}++r,++e}return T.join("")}a={version:"1.4.1",ucs2:{decode:P,encode:O},decode:S,encode:I,toASCII:function(t){return T(t,function(t){return v.test(t)?"xn--"+I(t):t})},toUnicode:function(t){return T(t,function(t){return m.test(t)?S(t.slice(4).toLowerCase()):t})}},void 0===(o=function(){return a}.call(e,r,e,t))||(t.exports=o)}()}).call(this,r(1)(t),r(0))},function(t,e,r){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},function(t,e,r){"use strict";e.decode=e.parse=r(13),e.encode=e.stringify=r(14)},function(t,e,r){"use strict";function n(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,r,i){e=e||"&",r=r||"=";var s={};if("string"!=typeof t||0===t.length)return s;var a=/\+/g;t=t.split(e);var h=1e3;i&&"number"==typeof i.maxKeys&&(h=i.maxKeys);var u=t.length;h>0&&u>h&&(u=h);for(var f=0;f<u;++f){var c,l,p,d,g=t[f].replace(a,"%20"),y=g.indexOf(r);y>=0?(c=g.substr(0,y),l=g.substr(y+1)):(c=g,l=""),p=decodeURIComponent(c),d=decodeURIComponent(l),n(s,p)?o(s[p])?s[p].push(d):s[p]=[s[p],d]:s[p]=d}return s};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,r){"use strict";var n=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};t.exports=function(t,e,r,a){return e=e||"&",r=r||"=",null===t&&(t=void 0),"object"==typeof t?i(s(t),function(s){var a=encodeURIComponent(n(s))+r;return o(t[s])?i(t[s],function(t){return a+encodeURIComponent(n(t))}).join(e):a+encodeURIComponent(n(t[s]))}).join(e):a?encodeURIComponent(n(a))+r+encodeURIComponent(n(t)):""};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function i(t,e){if(t.map)return t.map(e);for(var r=[],n=0;n<t.length;n++)r.push(e(t[n],n));return r}var s=Object.keys||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.push(r);return e}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mhtml2html=t():e.mhtml2html=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){const r=n(3),o=n(4);function i(e,t){if(!e)throw new Error(t);return!0}function a(e){return i("undefined"!=typeof DOMParser,"No DOM parser available"),{window:{document:(new DOMParser).parseFromString(e,"text/html")}}}function c(e,t){if(0===t.indexOf("http://")||0===t.indexOf("https://"))return t;const n=e.split("/"),r=t.split("/");n.pop();for(let e=0;e<r.length;e++)"."!=r[e]&&(".."==r[e]?n.pop():n.push(r[e]));return n.join("/")}function d(e,t,n){let r,i;for(i=0;(i=n.indexOf("url(",i))>0;i+=r.length){i+="url(".length;const a=c(t,(r=n.substring(i,n.indexOf(")",i))).replace(/(\"|\')/g,""));if(null!=e[a]){"text/css"===e[a].type&&(e[a].data=d(e,t,e[a].data));try{const t=`'data:${e[a].type};base64,${"base64"===e[a].encoding?e[a].data:o.encode(e[a].data)}'`;n=`${n.substring(0,i)}${t}${n.substring(i+r.length)}`}catch(e){console.warn(e)}}}return n}const s={parse:(e,t=!1,n=a)=>{const o=0,c=1,d=2,s=3;let u,l,f,p,h,g,b,y,v,x,m,A,C,w,$,T;function M(){for(;i(w<e.length-1,"Unexpected EOF")&&/\s/.test(e[w]);)"\n"==e[++w]&&$++}function j(t){const n=w;for(;"\n"!==e[w]&&i(w++<e.length-1,"Unexpected EOF"););w++,$++;const o=e.substring(n,w);return"quoted-printable"===t?r.decode(o):"base64"===t?o.trim():o}function F(e,t){const n=e.indexOf(":");n>-1?t[m=e.substring(0,n).trim()]=e.substring(n+1,e.length).trim():(i(void 0!==m,`Missing MHTML headers; Line ${$}`),t[m]+=e.trim())}for(l={},f={},p={},h={},x=o,w=$=0;x!=s;)switch(x){case o:if(0!=(A=j())&&"\n"!=A)F(A,l);else{i(void 0!==l["Content-Type"],`Missing document content type; Line ${$}`);const e=l["Content-Type"].match(/boundary=(.*)/m);i(null!=e,`Missing boundary from document headers; Line ${$}`),T=e[1].replace(/\"/g,""),M(),i((A=j()).includes(T),`Expected boundary; Line ${$}`),f={},x=c}break;case c:0!=(A=j())&&"\n"!=A?F(A,f):(b=f["Content-Transfer-Encoding"],y=f["Content-Type"],v=f["Content-ID"],g=f["Content-Location"],void 0===C&&i(void 0!==(C=g)&&"text/html"===y,`Index not found; Line ${$}`),i(void 0!==v||void 0!==g,`ID or location header not provided; Line ${$}`),i(void 0!==b,`Content-Transfer-Encoding not provided; Line ${$}`),i(void 0!==y,`Content-Type not provided; Line ${$}`),u={encoding:b,type:y,data:"",id:v},void 0!==v&&(h[v]=u),void 0!==g&&void 0===p[g]&&(p[g]=u),M(),f={},x=d);break;case d:for(A=j(b);!A.includes(T);)u.data+=A,A=j(b);try{u.data=decodeURIComponent(escape(u.data))}catch(e){}if(!0===t&&void 0!==C)return n(u.data);x=w>=e.length-1?s:c}return{frames:h,media:p,index:C}},convert:(e,t=a)=>{let n,c,u,l,f,p,h,g,b,y;"string"==typeof e?e=s.parse(e):i("object"==typeof e,"Expected argument of type string or object"),f=e.frames,l=e.media,u=e.index,i("object"==typeof f,"MHTML error: invalid frames"),i("object"==typeof l,"MHTML error: invalid media"),i("string"==typeof u,"MHTML error: invalid index"),i(l[u]&&"text/html"===l[u].type,"MHTML error: invalid index");const v=t(l[u].data),x=v.window.document,m=[x];for(;m.length;){const e=m.shift();e.childNodes.forEach(function(t){switch(t.getAttribute&&(b=t.getAttribute("href"),y=t.getAttribute("src")),t.removeAttribute&&t.removeAttribute("integrity"),t.tagName){case"HEAD":(h=x.createElement("base")).setAttribute("target","_parent"),t.insertBefore(h,t.firstChild);break;case"LINK":void 0!==l[b]&&"text/css"===l[b].type&&((p=x.createElement("style")).type="text/css",l[b].data=d(l,b,l[b].data),p.appendChild(x.createTextNode(l[b].data)),e.replaceChild(p,t));break;case"STYLE":(p=x.createElement("style")).type="text/css",p.appendChild(x.createTextNode(d(l,u,t.innerHTML))),e.replaceChild(p,t);break;case"IMG":if(g=null,void 0!==l[y]&&l[y].type.includes("image")){switch(l[y].encoding){case"quoted-printable":n=r.decode(l[y].data),g=`data:${l[y].type};utf8,${escape(n)}`;break;case"base64":g=`data:${l[y].type};base64,${l[y].data}`;break;default:try{c=o.encode(l[y].data),g=`data:${l[y].type};base64,${c}`}catch(e){console.warn(e)}}null!==g&&t.setAttribute("src",g)}t.style.cssText=d(l,u,t.style.cssText);break;default:t.style&&(t.style.cssText=d(l,u,t.style.cssText))}m.push(t)})}return v}};e.exports=s},function(e,t,n){(function(e,r){var o;/*! https://mths.be/quoted-printable v1.0.1 by @mathias | MIT license */!function(i){var a=t,c=(e&&e.exports,"object"==typeof r&&r);c.global!==c&&c.window;var d=String.fromCharCode,s=function(e){return e.replace(/\x20$/,"=20").replace(/\t$/,"=09")},u=/[\0-\x08\n-\x1F=\x7F-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,l={encode:function(e){for(var t=e.replace(u,function(e){if(e>"ÿ")throw RangeError("`quotedPrintable.encode()` expects extended ASCII input only. Don’t forget to encode the input first using a character encoding like UTF-8.");return"="+("0"+e.charCodeAt(0).toString(16).toUpperCase()).slice(-2)}),n=t.split(/\r\n?|\n/g),r=-1,o=n.length,i=[];++r<o;)for(var a=75,c=0,d=n[r].length;c<d;){var l=t.slice(c,c+a);/=$/.test(l)?(l=l.slice(0,a-1),c+=a-1):/=[A-F0-9]$/.test(l)?(l=l.slice(0,a-2),c+=a-2):c+=a,i.push(l)}var f=l.length;return/[\t\x20]$/.test(l)&&(i.pop(),f+2<=a+1?i.push(s(l)):i.push(l.slice(0,f-1),s(l.slice(f-1,f)))),i.join("=\r\n")},decode:function(e){return e.replace(/[\t\x20]$/gm,"").replace(/=(?:\r\n?|\n|$)/g,"").replace(/=([a-fA-F0-9]{2})/g,function(e,t){var n=parseInt(t,16);return d(n)})},version:"1.0.1"};void 0===(o=function(){return l}.call(t,n,t,e))||(e.exports=o)}()}).call(this,n(0)(e),n(1))},function(e,t,n){(function(e,r){var o;/*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */!function(i){var a=t,c=(e&&e.exports,"object"==typeof r&&r);c.global!==c&&c.window;var d=function(e){this.message=e};(d.prototype=new Error).name="InvalidCharacterError";var s=function(e){throw new d(e)},u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=/[\t\n\f\r ]/g,f={encode:function(e){e=String(e),/[^\0-\xFF]/.test(e)&&s("The string to be encoded contains characters outside of the Latin1 range.");for(var t,n,r,o,i=e.length%3,a="",c=-1,d=e.length-i;++c<d;)t=e.charCodeAt(c)<<16,n=e.charCodeAt(++c)<<8,r=e.charCodeAt(++c),a+=u.charAt((o=t+n+r)>>18&63)+u.charAt(o>>12&63)+u.charAt(o>>6&63)+u.charAt(63&o);return 2==i?(t=e.charCodeAt(c)<<8,n=e.charCodeAt(++c),a+=u.charAt((o=t+n)>>10)+u.charAt(o>>4&63)+u.charAt(o<<2&63)+"="):1==i&&(o=e.charCodeAt(c),a+=u.charAt(o>>2)+u.charAt(o<<4&63)+"=="),a},decode:function(e){var t=(e=String(e).replace(l,"")).length;t%4==0&&(t=(e=e.replace(/==?$/,"")).length),(t%4==1||/[^+a-zA-Z0-9\/]/.test(e))&&s("Invalid character: the string to be decoded is not correctly encoded.");for(var n,r,o=0,i="",a=-1;++a<t;)r=u.indexOf(e.charAt(a)),n=o%4?64*n+r:r,o++%4&&(i+=String.fromCharCode(255&n>>(-2*o&6)));return i},version:"0.1.0"};void 0===(o=function(){return f}.call(t,n,t,e))||(e.exports=o)}()}).call(this,n(0)(e),n(1))}])});
+6
-5

@@ -14,5 +14,5 @@ #!/usr/bin/env node

const serializeDocument = require("jsdom").serializeDocument;
const mhtml2html = require('./dist/mhtml2html');
const fs = require('fs');
const mhtml2html = require('./dist/mhtml2html');
const { JSDOM } = require("jsdom");
const fs = require('fs');

@@ -30,4 +30,5 @@ // Ensure that an input and output path is provided.

fs.writeFile(process.argv[3], serializeDocument(mhtml2html.convert(data)), err => {
if(err) {
const doc = mhtml2html.convert(data, (html) => new JSDOM(html));
fs.writeFile(process.argv[3], doc.serialize(), err => {
if (err) {
return console.log(err);

@@ -34,0 +35,0 @@ }

{
"name": "mhtml2html",
"version": "1.3.2",
"version": "2.0.0",
"description": "Converts an mhtml document to a single html document",

@@ -33,4 +33,4 @@ "author": "Mayank Sindwani",

"dependencies": {
"btoa": "^1.2.1",
"jsdom": "^9.4.2",
"base-64": "^0.1.0",
"jsdom": "^15.1.1",
"quoted-printable": "^1.0.1"

@@ -37,0 +37,0 @@ },

+34
-21

@@ -11,3 +11,3 @@ # mhtml2html.js

`mhtml2html` is compatible with Node >= v4.3.2.
`mhtml2html` is compatible with Node >= v10.

@@ -28,31 +28,43 @@ **It has only been tested with MHTML files built and used with the latest versions of Chrome**

### Example
### Node.js Example
mhtml2html can be used via the command line:
```sh
$ mhtml2html <input.mhtml> <output.html>
```
For programmatic usage, mhtml2html can be used provided a WHATWG DOM parser implementation (e.g [jsdom](https://github.com/jsdom/jsdom)):
```js
const mhtml2html = require('mhtml2html');
const { JSDOM } = require("jsdom");
const mhtml = '<your MHTML string>';
const mhtmlParsed = mhtml2html.parse(mhtml);
const html = mhtml2html.convert(mhtmlParsed);
console.log(html);
// Alternatively you could convert the result directly and have
// it implicitly parsed i.e:
// const html = mhtml2html.convert(mhtml);
const htmlDoc = mhtml2html.convert(mhtml, (html) => new JSDOM(html));
console.log(htmlDoc);
```
## API
### Browser Example
### noConflict
By default, mhtml2html will use the DOMParser available in most browsers:
`mhtml2html.noConflict();`
```js
import mhtml2html from 'mhtml2html';
* Resets the module that was previously defined for browser conflict resolution.
* Returns a localized version of mhtml2html.
const mhtml = '<your MHTML string>';
const html = mhtml2html.convert(mhtml);
console.log(html);
```
## API
### parse
`mhtml2html.parse(mhtml_string, html_only = false);`
`mhtml2html.parse(mhtml, htmlOnly = false, parseDOM = <function>);`
* Accepts an MHTML String.
* If html_only is true, returns the html document without resources.
Otherwise it returns an MHTML parsed object:
* mhtml: An MHTML String.
* htmlOnly: If set to true, returns the html document without resources.
* parseDOM: A callback that accepts a DOM string and returns a window object (defaults to `DOMParser` only available in browsers)
* Returns an html document without resources if `htmlOnly` is set to true. Otherwise it returns an MHTML parsed object:

@@ -75,6 +87,7 @@ ``` json

`mhtml2html.convert(mhtml_string or mhtml_object);`
`mhtml2html.convert(mhtml, parseDOM = <function>);`
* Accepts an MHTML String or parsed MHTML Object.
* Returns an html document element.
* mhtml: An MHTML String or MHTML parsed object.
* parseDOM: A callback that accepts a DOM string and returns a window object (defaults to `DOMParser` only available in browsers)
* Returns an html window element.

@@ -81,0 +94,0 @@ ## Development