hk-address-parser-lib
Version:
The library for the HKAddressParser project
1 lines • 175 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@turf/turf"),require("proj4")):"function"==typeof define&&define.amd?define(["exports","@turf/turf","proj4"],t):t((e=e||self)["hk-address-parser"]={},e.turf,e.proj4)}(this,function(e,t,n){"use strict";n=n&&n.hasOwnProperty("default")?n.default:n;var r={HK:{eng:"Hong Kong",chi:"香港"},KLN:{eng:"Kowloon",chi:"九龍"},NT:{eng:"New Territories",chi:"新界"}},i={invalid:{eng:"Invalid District Name",chi:"無效地區"},CW:{eng:"Central and Western District",chi:"中西區"},EST:{eng:"Eastern District",chi:"東區"},ILD:{eng:"Islands District",chi:"離島區"},KLC:{eng:"Kowloon City District",chi:"九龍城區"},KC:{eng:"Kwai Tsing District",chi:"葵青區"},KT:{eng:"Kwun Tong District",chi:"觀塘區"},NTH:{eng:"North District",chi:"北區"},SK:{eng:"Sai Kung District",chi:"西貢區"},ST:{eng:"Sha Tin Distric",chi:"沙田區"},SSP:{eng:"Sham Shui Po District",chi:"深水埗區"},STH:{eng:"Southern District",chi:"南區"},TP:{eng:"Tai Po District",chi:"大埔區"},TW:{eng:"Tsuen Wan District",chi:"荃灣區"},TM:{eng:"Tuen Mun District",chi:"屯門區"},WC:{eng:"Wan Chai District",chi:"灣仔區"},WTS:{eng:"Wong Tai Sin District",chi:"黃大仙區"},YTM:{eng:"Yau Tsim Mong District",chi:"油尖旺區"},YL:{eng:"Yuen Long District",chi:"元朗區"}};const o=1,a=.5,s=.7,u=.75,l=1.5,c="Block",f="Phase",h="Estate",d="Village",p="Street",g="Region",m="BuildingName",y={[m]:50,[d]:40,[h]:40,[p]:40,[g]:20,[f]:20,[c]:20},v=[m,c,f,h,d,p,g];console.log;class b{constructor(e,t,n){this.confident=e,this.matchedKey=t,this.matchedWords=n}}function _(e,t){for(const n in i)if(n===e)return t?i[n].chi:i[n].eng;return t?i.invalid.chi:i.invalid.eng}function w(e,t){const n={matchPercentage:0,matchedWord:null};if(t.indexOf(e)>=0)n.matchPercentage=.9,n.matchedWord=e;else e:for(let r=0;r<t.length;r++)for(let i=t.length;i>r;i--){const o=t.substring(r,i);if(e.includes(o)){n.matchPercentage=1*o.length/t.length,n.matchedWord=o;break e}}return n}function k(e){const t={};for(const n of Object.keys(e)){const r=n.replace(/(^Chi|^Eng)/,"");"object"==typeof e[n]?t[r]=k(e[n]):t[r]=e[n]}return t}function E(e,t){const n=e.match(/\d+/g);if(null===n)return!1;for(const e of n){if(parseInt(e,10)===t)return!0}return!1}function S(e,t,n,r){const i=e.match(/\d+/g);if(null===i)return!1;for(const e of i){const i=parseInt(e,10);if(i>=t&&i<=n&&i%2==1===r)return!0}return!1}function x(e){return/[^\u0000-\u00ff]/.test(e)}function R(e){if(x(e)&&/\s/.test(e)){const t=e.split(/\s/);return t[t.length-1]}return e}function A(e,t){return t.map(t=>e.includes(t)).reduce((e,t)=>e&&t,!0)}function T(e,t){return e*t*t*s}function L(e){let t=0;for(const n of e)t+=y[n.matchedKey]*n.confident;return t}function O(e,t,n,r,i){const s=new b(0,e,[]);if(t.includes(n))s.confident=o,s.matchedWords.push(n);else{const{matchPercentage:e,matchedWord:r}=w(t,n);e>0&&(s.confident=T(o,e),s.matchedWords.push(r))}if(r){const e=parseInt(r,10),n=i?parseInt(i,10):e,o=parseInt(r,10)%2==1;e===n?E(t,e)?(s.matchedWords.push(e+""),s.confident*=l):S(t,e,n,!o)?s.confident*=u:s.confident*=a:S(t,e,n,o)?s.confident*=l:S(t,e,n,!o)?s.confident*=u:s.confident*=a}else s.confident*=a;return s}function j(e,t,n){switch(t){case p:return function(e,{StreetName:t,BuildingNoFrom:n,BuildingNoTo:r}){const i=R(t);return O(p,e,i,n,r)}(e,n);case d:return function(e,{VillageName:t,BuildingNoFrom:n,BuildingNoTo:r}){const i=R(t);return O(d,e,i,n,r)}(e,n);case c:return function(e,{BlockDescriptor:t,BlockNo:n}){if(e.includes(n+t)){const r=new b(o,c,[n,t]);return n&&(E(e,parseInt(n,10))||(r.confident=a)),r}return null}(e,n);case f:return function(e,{PhaseNo:t,PhaseName:n}){if(e.includes(n+t)){const r=new b(o,f,[t,n]);return t&&(E(e,parseInt(t,10))||(r.confident=a)),r}return null}(e,n);case h:return function(e,{EstateName:t}){return e.includes(t)?new b(o,h,[t]):null}(e,n);case g:return function(e,t){return e.includes(t)?new b(o,g,[t]):null}(e,n);case m:return function(e,t){if(e.includes(t))return new b(o,m,[t]);{const{matchPercentage:n,matchedWord:r}=w(e,t);if(n>0){const e=new b(o,m,[r]);return e.confident=T(e.confident,n),e}}return null}(e,n)}return null}function B(e,t){const n=[];for(const r of v){if(void 0!==t.chi[r]&&x(e)){const i=j(e,r,t.chi[r]);if(null===i)continue;n.push(i)}if(void 0!==t.eng[r]&&!x(e)){const i=j(e,r,t.eng[r]);if(null===i)continue;n.push(i)}}return function e(t,n){if(1===n.length)return null!==n[0].matchedWord&&A(t,n[0].matchedWords)?n:[];let r=0,i=[];for(const o of n)if(A(t,o.matchedWords)){let a=t;o.matchedWords.forEach(e=>a=a.replace(e,""));const s=e(a,n.filter(e=>e.matchedKey!==o.matchedKey));s.push(o);const u=L(s);u>r&&(r=u,i=s)}return i}(e,n)}function N(e){return e.eng.District&&(e.eng.District.DcDistrict=_(e.eng.District.DcDistrict,!1)),e.chi.District&&(e.chi.District.DcDistrict=_(e.chi.District.DcDistrict,!0)),e.eng.Region&&(e.eng.Region=function(e){for(const t in r)if(t===e)return r[t].eng}(e.eng.Region)),e}var P={searchResult:function(e,t){return function(e,t){for(let n of t){const t=B(e,n);n.score=L(t),n.matches=t,n=N(n)}return(t=t.sort((e,t)=>t.score-e.score)).slice(0,200)}(function(e){return e.replace(/([0-9A-z\-\s]+[樓層]|[0-9A-z號\-\s]+[舖鋪]|地[下庫]|平台).*/g,"")}(e).toUpperCase(),function(e){return e.SuggestedAddress.map(e=>({chi:k(e.Address.PremisesAddress.ChiPremisesAddress),eng:k(e.Address.PremisesAddress.EngPremisesAddress),geo:e.Address.PremisesAddress.GeospatialInformation}))}(t))},calculateScoreFromMatches:L};class C{constructor(){}components(e){return[]}componentLabelForKey(e,t){const n=this.components(t).find(t=>t.key===e);return void 0===n?"":n.translatedLabel}componentValueForKey(e,t){const n=this.components(t).find(t=>t.key===e);return void 0===n?"":n.translatedValue}fullAddress(e){return null}coordinate(){return{lat:0,lng:0}}coordinates(){return[]}dataSource(){return null}confidence(){return 0}distanceTo(e){const n=t.point([this.coordinate().lng,this.coordinate().lat]),r=t.point([e.coordinate().lng,e.coordinate().lat]);return t.distance(n,r,{units:"kilometers"})}}C.LANG_EN="eng",C.LANG_ZH="chi";const z="Block",I="Phase",M="Estate",U="Street",D={eng:{[z]:"Block",[I]:"Phase",[M]:"Estate",Village:"Village",Region:"Region",District:"District",[U]:"Street",BuildingName:"Building Name","District.DcDistrict":"區議會分區",[`${U}.StreetName`]:"Street Name",[`${U}.BuildingNoFrom`]:"Street No. From",[`${U}.BuildingNoTo`]:"Street No. To",[`${M}.EstateName`]:"Estate Name"},chi:{[z]:"座數",[I]:"期數",[M]:"屋邨",Village:"鄉村",Region:"區域",District:"地區",[U]:"街道",BuildingName:"大廈名稱","District.DcDistrict":"區議會分區",[`${U}.StreetName`]:"街道",[`${U}.BuildingNoFrom`]:"街號",[`${U}.BuildingNoTo`]:"街號",[`${M}.EstateName`]:"屋邨"}};function F(e,t){return e&&e[t]?e[t]:""}function Z(e){return e&&(e.BuildingNoFrom||e.BuildingNoTo)?e.BuildingNoFrom&&e.BuildingNoTo?`${e.BuildingNoFrom}-${e.BuildingNoTo}`:`${e.BuildingNoTo?e.BuildingNoTo:e.BuildingNoFrom}`:""}function q(e){return e&&(e.BuildingNoFrom||e.BuildingNoTo)?e.BuildingNoFrom&&e.BuildingNoTo?`${e.BuildingNoFrom}至${e.BuildingNoTo}號`:`${e.BuildingNoTo?e.BuildingNoTo:e.BuildingNoFrom}號`:""}var H={topLevelKeys:()=>Object.keys(D.chi).map(e=>({key:e,value:D.chi[e]})).filter(e=>!e.key.includes(".")),textForKey:function(e,t){return D[t]&&D[t][e]?D[t][e]:e},textForValue:function(e,t,n){return e[n]?"string"==typeof e[n][t]?e[n][t]:t===M?function(e,t){let n=e.EstateName;const r=e[I];return"chi"===t?r&&(n=`${n}${F(e[I],"PhaseNo")}${F(e[I],"PhaseName")}`):"eng"===t&&r&&(n=`${F(e[I],"PhaseName")}${F(e[I],"PhaseNo")},${n}`),n}(e[n][t],n):t===z?function(e,t){return"chi"===t?`${e.BlockNo}${e.BlockDescriptor}`:"eng"===t?`${e.BlockDescriptor} ${e.BlockNo}`:void 0}(e[n][t],n):t===U?function(e,t){return"chi"===t?`${F(e,"StreetName")}${q(e)}`:"eng"===t?`${Z(e)} ${F(e,"StreetName")}`:void 0}(e[n][t],n):Object.values(e[n][t]).join():""},fullEnglishAddressFromResult:function(e){const{Street:t,Block:n,Phase:r,Estate:i,Village:o}=e,a=F(e,"Region"),s=F(t,"StreetName"),u=Z(t),l=F(o,"VillageName"),c=Z(o);return[F(e,"BuildingName"),F(i,"EstateName"),`${u} ${s}`,`${c} ${l}`,a].filter(e=>e.match(/\S/)).join(", ")},fullChineseAddressFromResult:function(e){const{Street:t,Block:n,Phase:r,Estate:i,Village:o}=e,a=F(e,"Region"),s=F(t,"StreetName"),u=q(t);return`${a}${F(o,"VillageName")}${q(o)}${s}${u}${F(i,"EstateName")}${F(e,"BuildingName")}`.trim()}};const $=e=>{if("number"==typeof e)return e;let t=parseFloat(e);return isNaN(t)?0:t};class W extends C{constructor(e){super(),this.record=e,this.flattenedComponents=null}components(e){return null===this.flattenedComponents&&(this.flattenedComponents=this.flattenComponents()),e===C.LANG_EN?this.flattenedComponents.eng:this.flattenedComponents.chi}flattenComponents(){const e={[C.LANG_EN]:[],[C.LANG_ZH]:[]},t=[C.LANG_ZH,C.LANG_EN];for(const n of t)for(const t of Object.keys(this.record[n]))e[n].push({key:t,translatedLabel:H.textForKey(t,n),translatedValue:H.textForValue(this.record,t,n)});return e}fullAddress(e){return e===C.LANG_EN?H.fullEnglishAddressFromResult(this.record.eng):H.fullChineseAddressFromResult(this.record.chi)}coordinate(){const e={lat:0,lng:0};return void 0!==this.record.geo&&this.record.geo.length>0&&(e.lat=$(this.record.geo[0].Latitude),e.lng=$(this.record.geo[0].Longitude)),e}coordinates(){return void 0!==this.record.geo&&this.record.geo.length>0?this.record.geo.map(e=>({lat:$(e.Latitude),lng:$(e.Longitude)})):[]}dataSource(){return"資科辦"}confidence(){return Math.min(4,5*this.record.matches.filter(e=>e.matchedKey===key).map(e=>e.confident).reduce((e,t)=>t,0)|0)}}class Y extends C{constructor(e){super(),this.record=e}components(e){return e===C.LANG_EN?[{translatedValue:this.record.nameEN,key:"name",translatedLabel:"Name"}]:e===C.LANG_ZH?[{translatedValue:this.record.nameZH,key:"name",translatedLabel:"Name"}]:void 0}fullAddress(e){return e===C.LANG_EN?this.record.addressEN:e===C.LANG_ZH?this.record.addressZH:void 0}coordinate(){return{lat:$(this.record.lat),lng:$(this.record.lng)}}coordinates(){return[{lat:$(this.record.lat),lng:$(this.record.lng)}]}dataSource(){return"地政總署"}confidence(){return 0}}const V=function(e,t){switch(e){case"ogcio":return new W(t);case"land":return new Y(t);default:return new C(t)}};n.defs([["EPSG:2326","+proj=tmerc +lat_0=22.31213333333334 +lon_0=114.1785555555556 +k=1 +x_0=836694.05 +y_0=819069.8 +ellps=intl +towgs84=-162.619,-276.959,-161.764,0.067753,-2.24365,-1.15883,-1.09425 +units=m +no_defs"],["EPSG:4326","+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"]]);var G={projTransform:(e,t,r)=>n(n(e),n(t),r)};const K=e=>e.replace(/,/g," "),X=(e,t)=>{const n=K(e),r=t.map(e=>({landAddress:e,lcs:Math.max(J(n,K(e.fullAddress("chi"))),J(n,K(e.fullAddress("eng"))))}));return r.sort((e,t)=>t.lcs-e.lcs),r.map(e=>e.landAddress)},J=(e,t)=>{const n=e.length+1,r=t.length+1,i=new Array(n);for(let e=0;e<n;e++)i[e]=new Array(r);for(let o=0;o<n;o++)for(let n=0;n<r;n++)0===o||0===n?i[o][n]=0:e[o]===t[n]?i[o][n]=1+i[o-1][n-1]:i[o][n]=Math.max(i[o-1][n],i[o][n-1]);return i[n-1][r-1]};var Q="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ee(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function te(e,t){return e(t={exports:{}},t.exports),t.exports}function ne(){}function re(){re.init.call(this)}function ie(e){return void 0===e._maxListeners?re.defaultMaxListeners:e._maxListeners}function oe(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new ne,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=ie(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[t]=n,++e._eventsCount;return e}function ae(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function se(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function ue(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function le(){throw new Error("setTimeout has not been defined")}function ce(){throw new Error("clearTimeout has not been defined")}ne.prototype=Object.create(null),re.EventEmitter=re,re.usingDomains=!1,re.prototype.domain=void 0,re.prototype._events=void 0,re.prototype._maxListeners=void 0,re.defaultMaxListeners=10,re.init=function(){this.domain=null,re.usingDomains&&(void 0).active&&(void 0).Domain,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new ne,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},re.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},re.prototype.getMaxListeners=function(){return ie(this)},re.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.error;else if(!u)return!1;if(s=this.domain,u){if(t=arguments[1],!s){if(t instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=s,t.domainThrown=!1,s.emit("error",t),!1}if(!(n=a[e]))return!1;var c="function"==typeof n;switch(r=arguments.length){case 1:!function(e,t,n){if(t)e.call(n);else for(var r=e.length,i=ue(e,r),o=0;o<r;++o)i[o].call(n)}(n,c,this);break;case 2:!function(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=ue(e,i),a=0;a<i;++a)o[a].call(n,r)}(n,c,this,arguments[1]);break;case 3:!function(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=ue(e,o),s=0;s<o;++s)a[s].call(n,r,i)}(n,c,this,arguments[1],arguments[2]);break;case 4:!function(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=ue(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}(n,c,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),o=1;o<r;o++)i[o-1]=arguments[o];!function(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=ue(e,i),a=0;a<i;++a)o[a].apply(n,r)}(n,c,this,i)}return!0},re.prototype.addListener=function(e,t){return oe(this,e,t,!1)},re.prototype.on=re.prototype.addListener,re.prototype.prependListener=function(e,t){return oe(this,e,t,!0)},re.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,ae(this,e,t)),this},re.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,ae(this,e,t)),this},re.prototype.removeListener=function(e,t){var n,r,i,o,a;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new ne:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new ne,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,a||t)}return this},re.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new ne,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new ne:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new ne,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},re.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},re.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):se.call(e,t)},re.prototype.listenerCount=se,re.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var fe=le,he=ce;function de(e){if(fe===setTimeout)return setTimeout(e,0);if((fe===le||!fe)&&setTimeout)return fe=setTimeout,setTimeout(e,0);try{return fe(e,0)}catch(t){try{return fe.call(null,e,0)}catch(t){return fe.call(this,e,0)}}}"function"==typeof global.setTimeout&&(fe=setTimeout),"function"==typeof global.clearTimeout&&(he=clearTimeout);var pe,ge=[],me=!1,ye=-1;function ve(){me&&pe&&(me=!1,pe.length?ge=pe.concat(ge):ye=-1,ge.length&&be())}function be(){if(!me){var e=de(ve);me=!0;for(var t=ge.length;t;){for(pe=ge,ge=[];++ye<t;)pe&&pe[ye].run();ye=-1,t=ge.length}pe=null,me=!1,function(e){if(he===clearTimeout)return clearTimeout(e);if((he===ce||!he)&&clearTimeout)return he=clearTimeout,clearTimeout(e);try{he(e)}catch(t){try{return he.call(null,e)}catch(t){return he.call(this,e)}}}(e)}}function _e(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];ge.push(new we(e,t)),1!==ge.length||me||de(be)}function we(e,t){this.fun=e,this.array=t}we.prototype.run=function(){this.fun.apply(null,this.array)};function ke(){}var Ee=ke,Se=ke,xe=ke,Re=ke,Ae=ke,Te=ke,Le=ke;var Oe=global.performance||{},je=Oe.now||Oe.mozNow||Oe.msNow||Oe.oNow||Oe.webkitNow||function(){return(new Date).getTime()};var Be=new Date;var Ne={nextTick:_e,title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:Ee,addListener:Se,once:xe,off:Re,removeListener:Ae,removeAllListeners:Te,emit:Le,binding:function(e){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(e){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(e){var t=.001*je.call(Oe),n=Math.floor(t),r=Math.floor(t%1*1e9);return e&&(n-=e[0],(r-=e[1])<0&&(n--,r+=1e9)),[n,r]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-Be)/1e3}},Pe="function"==typeof Object.create?function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e},Ce=/%[sdj%]/g;function ze(e,t){if(Ve(global.process))return function(){return ze(e,t).apply(this,arguments)};var n=!1;return function(){return n||(console.error(t),n=!0),e.apply(this,arguments)}}var Ie,Me={};function Ue(e,t){var n={seen:[],stylize:Fe};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),$e(t)?n.showHidden=t:t&&function(e,t){if(!t||!Ke(t))return e;var n=Object.keys(t),r=n.length;for(;r--;)e[n[r]]=t[n[r]]}(n,t),Ve(n.showHidden)&&(n.showHidden=!1),Ve(n.depth)&&(n.depth=2),Ve(n.colors)&&(n.colors=!1),Ve(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=De),Ze(n,e,n.depth)}function De(e,t){var n=Ue.styles[t];return n?"["+Ue.colors[n][0]+"m"+e+"["+Ue.colors[n][1]+"m":e}function Fe(e,t){return e}function Ze(e,t,n){if(e.customInspect&&t&&Qe(t.inspect)&&t.inspect!==Ue&&(!t.constructor||t.constructor.prototype!==t)){var r=t.inspect(n,e);return Ye(r)||(r=Ze(e,r,n)),r}var i=function(e,t){if(Ve(t))return e.stylize("undefined","undefined");if(Ye(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}if(r=t,"number"==typeof r)return e.stylize(""+t,"number");var r;if($e(t))return e.stylize(""+t,"boolean");if(We(t))return e.stylize("null","null")}(e,t);if(i)return i;var o=Object.keys(t),a=function(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}(o);if(e.showHidden&&(o=Object.getOwnPropertyNames(t)),Je(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return qe(t);if(0===o.length){if(Qe(t)){var s=t.name?": "+t.name:"";return e.stylize("[Function"+s+"]","special")}if(Ge(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(Xe(t))return e.stylize(Date.prototype.toString.call(t),"date");if(Je(t))return qe(t)}var u,l,c="",f=!1,h=["{","}"];(u=t,Array.isArray(u)&&(f=!0,h=["[","]"]),Qe(t))&&(c=" [Function"+(t.name?": "+t.name:"")+"]");return Ge(t)&&(c=" "+RegExp.prototype.toString.call(t)),Xe(t)&&(c=" "+Date.prototype.toUTCString.call(t)),Je(t)&&(c=" "+qe(t)),0!==o.length||f&&0!=t.length?n<0?Ge(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special"):(e.seen.push(t),l=f?function(e,t,n,r,i){for(var o=[],a=0,s=t.length;a<s;++a)tt(t,String(a))?o.push(He(e,t,n,r,String(a),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(He(e,t,n,r,i,!0))}),o}(e,t,n,a,o):o.map(function(r){return He(e,t,n,a,r,f)}),e.seen.pop(),function(e,t,n){if(e.reduce(function(e,t){return t.indexOf("\n"),e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1];return n[0]+t+" "+e.join(", ")+" "+n[1]}(l,c,h)):h[0]+c+h[1]}function qe(e){return"["+Error.prototype.toString.call(e)+"]"}function He(e,t,n,r,i,o){var a,s,u;if((u=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?s=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(s=e.stylize("[Setter]","special")),tt(r,i)||(a="["+i+"]"),s||(e.seen.indexOf(u.value)<0?(s=We(n)?Ze(e,u.value,null):Ze(e,u.value,n-1)).indexOf("\n")>-1&&(s=o?s.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+s.split("\n").map(function(e){return" "+e}).join("\n")):s=e.stylize("[Circular]","special")),Ve(a)){if(o&&i.match(/^\d+$/))return s;(a=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(a=a.substr(1,a.length-2),a=e.stylize(a,"name")):(a=a.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),a=e.stylize(a,"string"))}return a+": "+s}function $e(e){return"boolean"==typeof e}function We(e){return null===e}function Ye(e){return"string"==typeof e}function Ve(e){return void 0===e}function Ge(e){return Ke(e)&&"[object RegExp]"===et(e)}function Ke(e){return"object"==typeof e&&null!==e}function Xe(e){return Ke(e)&&"[object Date]"===et(e)}function Je(e){return Ke(e)&&("[object Error]"===et(e)||e instanceof Error)}function Qe(e){return"function"==typeof e}function et(e){return Object.prototype.toString.call(e)}function tt(e,t){return Object.prototype.hasOwnProperty.call(e,t)}Ue.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},Ue.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};var nt=[],rt=[],it="undefined"!=typeof Uint8Array?Uint8Array:Array,ot=!1;function at(){ot=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,n=e.length;t<n;++t)nt[t]=e[t],rt[e.charCodeAt(t)]=t;rt["-".charCodeAt(0)]=62,rt["_".charCodeAt(0)]=63}function st(e,t,n){for(var r,i,o=[],a=t;a<n;a+=3)r=(e[a]<<16)+(e[a+1]<<8)+e[a+2],o.push(nt[(i=r)>>18&63]+nt[i>>12&63]+nt[i>>6&63]+nt[63&i]);return o.join("")}function ut(e){var t;ot||at();for(var n=e.length,r=n%3,i="",o=[],a=0,s=n-r;a<s;a+=16383)o.push(st(e,a,a+16383>s?s:a+16383));return 1===r?(t=e[n-1],i+=nt[t>>2],i+=nt[t<<4&63],i+="=="):2===r&&(t=(e[n-2]<<8)+e[n-1],i+=nt[t>>10],i+=nt[t>>4&63],i+=nt[t<<2&63],i+="="),o.push(i),o.join("")}function lt(e,t,n,r,i){var o,a,s=8*i-r-1,u=(1<<s)-1,l=u>>1,c=-7,f=n?i-1:0,h=n?-1:1,d=e[t+f];for(f+=h,o=d&(1<<-c)-1,d>>=-c,c+=s;c>0;o=256*o+e[t+f],f+=h,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=r;c>0;a=256*a+e[t+f],f+=h,c-=8);if(0===o)o=1-l;else{if(o===u)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,r),o-=l}return(d?-1:1)*a*Math.pow(2,o-r)}function ct(e,t,n,r,i,o){var a,s,u,l=8*o-i-1,c=(1<<l)-1,f=c>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:o-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,a=c):(a=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-a))<1&&(a--,u*=2),(t+=a+f>=1?h/u:h*Math.pow(2,1-f))*u>=2&&(a++,u/=2),a+f>=c?(s=0,a=c):a+f>=1?(s=(t*u-1)*Math.pow(2,i),a+=f):(s=t*Math.pow(2,f-1)*Math.pow(2,i),a=0));i>=8;e[n+d]=255&s,d+=p,s/=256,i-=8);for(a=a<<i|s,l+=i;l>0;e[n+d]=255&a,d+=p,a/=256,l-=8);e[n+d-p]|=128*g}var ft={}.toString,ht=Array.isArray||function(e){return"[object Array]"==ft.call(e)};function dt(){return gt.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function pt(e,t){if(dt()<t)throw new RangeError("Invalid typed array length");return gt.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=gt.prototype:(null===e&&(e=new gt(t)),e.length=t),e}function gt(e,t,n){if(!(gt.TYPED_ARRAY_SUPPORT||this instanceof gt))return new gt(e,t,n);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return vt(this,e)}return mt(this,e,t,n)}function mt(e,t,n,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,n,r){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");t=void 0===n&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,n):new Uint8Array(t,n,r);gt.TYPED_ARRAY_SUPPORT?(e=t).__proto__=gt.prototype:e=bt(e,t);return e}(e,t,n,r):"string"==typeof t?function(e,t,n){"string"==typeof n&&""!==n||(n="utf8");if(!gt.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|kt(t,n),i=(e=pt(e,r)).write(t,n);i!==r&&(e=e.slice(0,i));return e}(e,t,n):function(e,t){if(wt(t)){var n=0|_t(t.length);return 0===(e=pt(e,n)).length?e:(t.copy(e,0,0,n),e)}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(r=t.length)!=r?pt(e,0):bt(e,t);if("Buffer"===t.type&&ht(t.data))return bt(e,t.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function yt(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function vt(e,t){if(yt(t),e=pt(e,t<0?0:0|_t(t)),!gt.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function bt(e,t){var n=t.length<0?0:0|_t(t.length);e=pt(e,n);for(var r=0;r<n;r+=1)e[r]=255&t[r];return e}function _t(e){if(e>=dt())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+dt().toString(16)+" bytes");return 0|e}function wt(e){return!(null==e||!e._isBuffer)}function kt(e,t){if(wt(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return Vt(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return Gt(e).length;default:if(r)return Vt(e).length;t=(""+t).toLowerCase(),r=!0}}function Et(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function St(e,t,n,r,i){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=gt.from(t,r)),wt(t))return 0===t.length?-1:xt(e,t,n,r,i);if("number"==typeof t)return t&=255,gt.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):xt(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function xt(e,t,n,r,i){var o,a=1,s=e.length,u=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;a=2,s/=2,u/=2,n/=2}function l(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(i){var c=-1;for(o=n;o<s;o++)if(l(e,o)===l(t,-1===c?0:o-c)){if(-1===c&&(c=o),o-c+1===u)return c*a}else-1!==c&&(o-=o-c),c=-1}else for(n+u>s&&(n=s-u),o=n;o>=0;o--){for(var f=!0,h=0;h<u;h++)if(l(e,o+h)!==l(t,h)){f=!1;break}if(f)return o}return-1}function Rt(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r))>i&&(r=i):r=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var a=0;a<r;++a){var s=parseInt(t.substr(2*a,2),16);if(isNaN(s))return a;e[n+a]=s}return a}function At(e,t,n,r){return Kt(Vt(t,e.length-n),e,n,r)}function Tt(e,t,n,r){return Kt(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function Lt(e,t,n,r){return Tt(e,t,n,r)}function Ot(e,t,n,r){return Kt(Gt(t),e,n,r)}function jt(e,t,n,r){return Kt(function(e,t){for(var n,r,i,o=[],a=0;a<e.length&&!((t-=2)<0);++a)n=e.charCodeAt(a),r=n>>8,i=n%256,o.push(i),o.push(r);return o}(t,e.length-n),e,n,r)}function Bt(e,t,n){return 0===t&&n===e.length?ut(e):ut(e.slice(t,n))}function Nt(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i<n;){var o,a,s,u,l=e[i],c=null,f=l>239?4:l>223?3:l>191?2:1;if(i+f<=n)switch(f){case 1:l<128&&(c=l);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&l)<<6|63&o)>127&&(c=u);break;case 3:o=e[i+1],a=e[i+2],128==(192&o)&&128==(192&a)&&(u=(15&l)<<12|(63&o)<<6|63&a)>2047&&(u<55296||u>57343)&&(c=u);break;case 4:o=e[i+1],a=e[i+2],s=e[i+3],128==(192&o)&&128==(192&a)&&128==(192&s)&&(u=(15&l)<<18|(63&o)<<12|(63&a)<<6|63&s)>65535&&u<1114112&&(c=u)}null===c?(c=65533,f=1):c>65535&&(c-=65536,r.push(c>>>10&1023|55296),c=56320|1023&c),r.push(c),i+=f}return function(e){var t=e.length;if(t<=Pt)return String.fromCharCode.apply(String,e);var n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=Pt));return n}(r)}gt.TYPED_ARRAY_SUPPORT=void 0===global.TYPED_ARRAY_SUPPORT||global.TYPED_ARRAY_SUPPORT,gt.poolSize=8192,gt._augment=function(e){return e.__proto__=gt.prototype,e},gt.from=function(e,t,n){return mt(null,e,t,n)},gt.TYPED_ARRAY_SUPPORT&&(gt.prototype.__proto__=Uint8Array.prototype,gt.__proto__=Uint8Array),gt.alloc=function(e,t,n){return function(e,t,n,r){return yt(t),t<=0?pt(e,t):void 0!==n?"string"==typeof r?pt(e,t).fill(n,r):pt(e,t).fill(n):pt(e,t)}(null,e,t,n)},gt.allocUnsafe=function(e){return vt(null,e)},gt.allocUnsafeSlow=function(e){return vt(null,e)},gt.isBuffer=Xt,gt.compare=function(e,t){if(!wt(e)||!wt(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,o=Math.min(n,r);i<o;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:r<n?1:0},gt.isEncoding=function(e){switch(String(e).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}},gt.concat=function(e,t){if(!ht(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return gt.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=gt.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){var o=e[n];if(!wt(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(r,i),i+=o.length}return r},gt.byteLength=kt,gt.prototype._isBuffer=!0,gt.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)Et(this,t,t+1);return this},gt.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)Et(this,t,t+3),Et(this,t+1,t+2);return this},gt.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)Et(this,t,t+7),Et(this,t+1,t+6),Et(this,t+2,t+5),Et(this,t+3,t+4);return this},gt.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?Nt(this,0,e):function(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return It(this,t,n);case"utf8":case"utf-8":return Nt(this,t,n);case"ascii":return Ct(this,t,n);case"latin1":case"binary":return zt(this,t,n);case"base64":return Bt(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Mt(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}.apply(this,arguments)},gt.prototype.equals=function(e){if(!wt(e))throw new TypeError("Argument must be a Buffer");return this===e||0===gt.compare(this,e)},gt.prototype.inspect=function(){var e="";return this.length>0&&(e=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(e+=" ... ")),"<Buffer "+e+">"},gt.prototype.compare=function(e,t,n,r,i){if(!wt(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(r>>>=0),a=(n>>>=0)-(t>>>=0),s=Math.min(o,a),u=this.slice(r,i),l=e.slice(t,n),c=0;c<s;++c)if(u[c]!==l[c]){o=u[c],a=l[c];break}return o<a?-1:a<o?1:0},gt.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},gt.prototype.indexOf=function(e,t,n){return St(this,e,t,n,!0)},gt.prototype.lastIndexOf=function(e,t,n){return St(this,e,t,n,!1)},gt.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return Rt(this,e,t,n);case"utf8":case"utf-8":return At(this,e,t,n);case"ascii":return Tt(this,e,t,n);case"latin1":case"binary":return Lt(this,e,t,n);case"base64":return Ot(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return jt(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},gt.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Pt=4096;function Ct(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(127&e[i]);return r}function zt(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function It(e,t,n){var r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);for(var i="",o=t;o<n;++o)i+=Yt(e[o]);return i}function Mt(e,t,n){for(var r=e.slice(t,n),i="",o=0;o<r.length;o+=2)i+=String.fromCharCode(r[o]+256*r[o+1]);return i}function Ut(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function Dt(e,t,n,r,i,o){if(!wt(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function Ft(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);i<o;++i)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function Zt(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);i<o;++i)e[n+i]=t>>>8*(r?i:3-i)&255}function qt(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function Ht(e,t,n,r,i){return i||qt(e,0,n,4),ct(e,t,n,r,23,4),n+4}function $t(e,t,n,r,i){return i||qt(e,0,n,8),ct(e,t,n,r,52,8),n+8}gt.prototype.slice=function(e,t){var n,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),gt.TYPED_ARRAY_SUPPORT)(n=this.subarray(e,t)).__proto__=gt.prototype;else{var i=t-e;n=new gt(i,void 0);for(var o=0;o<i;++o)n[o]=this[o+e]}return n},gt.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||Ut(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r},gt.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||Ut(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},gt.prototype.readUInt8=function(e,t){return t||Ut(e,1,this.length),this[e]},gt.prototype.readUInt16LE=function(e,t){return t||Ut(e,2,this.length),this[e]|this[e+1]<<8},gt.prototype.readUInt16BE=function(e,t){return t||Ut(e,2,this.length),this[e]<<8|this[e+1]},gt.prototype.readUInt32LE=function(e,t){return t||Ut(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},gt.prototype.readUInt32BE=function(e,t){return t||Ut(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},gt.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||Ut(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*t)),r},gt.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||Ut(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},gt.prototype.readInt8=function(e,t){return t||Ut(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},gt.prototype.readInt16LE=function(e,t){t||Ut(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},gt.prototype.readInt16BE=function(e,t){t||Ut(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},gt.prototype.readInt32LE=function(e,t){return t||Ut(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},gt.prototype.readInt32BE=function(e,t){return t||Ut(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},gt.prototype.readFloatLE=function(e,t){return t||Ut(e,4,this.length),lt(this,e,!0,23,4)},gt.prototype.readFloatBE=function(e,t){return t||Ut(e,4,this.length),lt(this,e,!1,23,4)},gt.prototype.readDoubleLE=function(e,t){return t||Ut(e,8,this.length),lt(this,e,!0,52,8)},gt.prototype.readDoubleBE=function(e,t){return t||Ut(e,8,this.length),lt(this,e,!1,52,8)},gt.prototype.writeUIntLE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||Dt(this,e,t,n,Math.pow(2,8*n)-1,0);var i=1,o=0;for(this[t]=255&e;++o<n&&(i*=256);)this[t+o]=e/i&255;return t+n},gt.prototype.writeUIntBE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||Dt(this,e,t,n,Math.pow(2,8*n)-1,0);var i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+n},gt.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,1,255,0),gt.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},gt.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,2,65535,0),gt.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):Ft(this,e,t,!0),t+2},gt.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,2,65535,0),gt.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):Ft(this,e,t,!1),t+2},gt.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,4,4294967295,0),gt.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):Zt(this,e,t,!0),t+4},gt.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,4,4294967295,0),gt.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Zt(this,e,t,!1),t+4},gt.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);Dt(this,e,t,n,i-1,-i)}var o=0,a=1,s=0;for(this[t]=255&e;++o<n&&(a*=256);)e<0&&0===s&&0!==this[t+o-1]&&(s=1),this[t+o]=(e/a>>0)-s&255;return t+n},gt.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);Dt(this,e,t,n,i-1,-i)}var o=n-1,a=1,s=0;for(this[t+o]=255&e;--o>=0&&(a*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/a>>0)-s&255;return t+n},gt.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,1,127,-128),gt.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},gt.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,2,32767,-32768),gt.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):Ft(this,e,t,!0),t+2},gt.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,2,32767,-32768),gt.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):Ft(this,e,t,!1),t+2},gt.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,4,2147483647,-2147483648),gt.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):Zt(this,e,t,!0),t+4},gt.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||Dt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),gt.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):Zt(this,e,t,!1),t+4},gt.prototype.writeFloatLE=function(e,t,n){return Ht(this,e,t,!0,n)},gt.prototype.writeFloatBE=function(e,t,n){return Ht(this,e,t,!1,n)},gt.prototype.writeDoubleLE=function(e,t,n){return $t(this,e,t,!0,n)},gt.prototype.writeDoubleBE=function(e,t,n){return $t(this,e,t,!1,n)},gt.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var i,o=r-n;if(this===e&&n<t&&t<r)for(i=o-1;i>=0;--i)e[i+t]=this[i+n];else if(o<1e3||!gt.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)e[i+t]=this[i+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+o),t);return o},gt.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!gt.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;var o;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(o=t;o<n;++o)this[o]=e;else{var a=wt(e)?e:Vt(new gt(e,r).toString()),s=a.length;for(o=0;o<n-t;++o)this[o+t]=a[o%s]}return this};var Wt=/[^+\/0-9A-Za-z-_]/g;function Yt(e){return e<16?"0"+e.toString(16):e.toString(16)}function Vt(e,t){var n;t=t||1/0;for(var r=e.length,i=null,o=[],a=0;a<r;++a){if((n=e.charCodeAt(a))>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(a+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function Gt(e){return function(e){var t,n,r,i,o,a;ot||at();var s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===e[s-2]?2:"="===e[s-1]?1:0,a=new it(3*s/4-o),r=o>0?s-4:s;var u=0;for(t=0,n=0;t<r;t+=4,n+=3)i=rt[e.charCodeAt(t)]<<18|rt[e.charCodeAt(t+1)]<<12|rt[e.charCodeAt(t+2)]<<6|rt[e.charCodeAt(t+3)],a[u++]=i>>16&255,a[u++]=i>>8&255,a[u++]=255&i;return 2===o?(i=rt[e.charCodeAt(t)]<<2|rt[e.charCodeAt(t+1)]>>4,a[u++]=255&i):1===o&&(i=rt[e.charCodeAt(t)]<<10|rt[e.charCodeAt(t+1)]<<4|rt[e.charCodeAt(t+2)]>>2,a[u++]=i>>8&255,a[u++]=255&i),a}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(Wt,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Kt(e,t,n,r){for(var i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function Xt(e){return null!=e&&(!!e._isBuffer||Jt(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&Jt(e.slice(0,0))}(e))}function Jt(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function Qt(){this.head=null,this.tail=null,this.length=0}Qt.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},Qt.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},Qt.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},Qt.prototype.clear=function(){this.head=this.tail=null,this.length=0},Qt.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n},Qt.prototype.concat=function(e){if(0===this.length)return gt.alloc(0);if(1===this.length)return this.head.data;for(var t=gt.allocUnsafe(e>>>0),n=this.head,r=0;n;)n.data.copy(t,r),r+=n.data.length,n=n.next;return t};var en=gt.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function tn(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),function(e){if(e&&!en(e))throw new Error("Unknown encoding: "+e)}(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=rn;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=on;break;default:return void(this.write=nn)}this.charBuffer=new gt(6),this.charReceived=0,this.charLength=0}function nn(e){return e.toString(this.encoding)}function rn(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function on(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}tn.prototype.write=function(e){for(var t="";this.charLength;){var n=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,n),this.charReceived+=n,this.charReceived<this.charLength)return"";if(e=e.slice(n,e.length),!((i=(t=this.charBuffer.slice(0,this.charLength).toString(this.encoding)).charCodeAt(t.length-1))>=55296&&i<=56319)){if(this.charReceived=this.charLength=0,0===e.length)return t;break}this.charLength+=this.surrogateSize,t=""}this.detectIncompleteChar(e);var r=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,r),r-=this.charReceived);var i;r=(t+=e.toString(this.encoding,0,r)).length-1;if((i=t.charCodeAt(r))>=55296&&i<=56319){var o=this.surrogateSize;return this.charLength+=o,this.charReceived+=o,this.charBuffer.copy(this.charBuffer,o,0,o),e.copy(this.charBuffer,0,0,o),t.substring(0,r)}return t},tn.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var n=e[e.length-t];if(1==t&&n>>5==6){this.charLength=2;break}if(t<=2&&n>>4==14){this.charLength=3;break}if(t<=3&&n>>3==30){this.charLength=4;break}}this.charReceived=t},tn.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var n=this.charReceived,r=this.charBuffer,i=this.encoding;t+=r.slice(0,n).toString(i)}return t},un.ReadableState=sn;var an=function(e){Ve(Ie)&&(Ie=Ne.env.NODE_DEBUG||""),e=e.toUpperCase(),Me[e]||(new RegExp("\\b"+e+"\\b","i").test(Ie)?Me[e]=function(){var t=function(e){if(!Ye(e)){for(var t=[],n=0;n<arguments.length;n++)t.push(Ue(arguments[n]));return t.join(" ")}n=1;for(var r=arguments,i=r.length,o=String(e).replace(Ce,function(e){if("%%"===e)return"%";if(n>=i)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return e}}),a=r[n];n<i;a=r[++n])We(a)||!Ke(a)?o+=" "+a:o+=" "+Ue(a);return o}.apply(null,arguments);console.error("%s %d: %s",e,0,t)}:Me[e]=function(){});return Me[e]}("stream");function sn(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof zn&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var n=e.highWaterMark,r=this.objectMode?16:16384;this.highWaterMark=n||0===n?n:r,this.highWaterMark=~~this.highWaterMark,this.buffer=new Qt,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(this.decoder=new tn(e.encoding),this.encoding=e.encoding)}function un(e){if(!(this instanceof un))return new un(e);this._readableState=new sn(e,this),this.readable=!0,e&&"function"==typeof e.read&&(this._read=e.read),re.call(this)}function ln(e,t,n,r,i){var o=function(e,t){var n=null;Buffer.isBuffer(t)||"string"==typeof t||null==t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk"));return n}(t,n);if(o)e.emit("error",o);else if(null===n)t.reading=!1,function(e,t){if(t.ended)return;if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.