xsheetjs/packages/dta/dist/dta.min.js

3 lines
9.2 KiB
JavaScript
Raw Normal View History

2023-12-05 08:19:42 +00:00
var DTA=(()=>{var N=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var z=r=>N(r,"__esModule",{value:!0});var H=(r,t)=>{for(var e in t)N(r,e,{get:t[e],enumerable:!0})},Q=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Y(t))!q.call(r,o)&&(e||o!=="default")&&N(r,o,{get:()=>t[o],enumerable:!(s=J(t,o))||s.enumerable});return r};var X=(r=>(t,e)=>r&&r.get(t)||(e=Q(z({}),t,1),r&&r.set(t,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var ne={};H(ne,{parse:()=>se,set_utils:()=>ee,version:()=>Z});var Z="0.0.1",$;function ee(r){$=r}function U(r){return new TextDecoder().decode(r)}function P(r){return new TextDecoder("latin1").decode(r)}function L(r,t,e){if(r<0){let b=L(-r,t,e);return b.w="-"+b.w,b}let s={t:"n",v:r};switch(e){case 251:case 98:case 65530:t="%8.0g";break;case 252:case 105:case 65529:t="%8.0g";break;case 253:case 108:case 65528:t="%12.0g";break;case 254:case 102:case 65527:t="%9.0g";break;case 255:case 100:case 65526:t="%10.0g";break;default:throw e}try{let b=+(t.match(/%(\d+)/)||[])[1]||8,v=0;r<1&&++v,r<.1&&++v,r<.01&&++v,r<.001&&++v;let D=r.toExponential(),E=D.indexOf("e")==-1?0:+D.slice(D.indexOf("e")+1),g=b-2-E;g<0&&(g=0);var o=t.match(/%\d+\.(\d+)/);o&&+o[1]&&(g=+o[1]),s.w=(Math.round(r*10**g)/10**g).toFixed(g).replace(/^([-]?)0\./,"$1."),s.w=s.w.slice(0,b+v),s.w.indexOf(".")>-1&&(s.w=s.w.replace(/0+$/,"")),s.w=s.w.replace(/\.$/,""),s.w==""&&(s.w="0")}catch{}return s}function B(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function n(r,t){return U(r.raw.slice(r.ptr,r.ptr+t.length))!=t?!1:(r.ptr+=t.length,!0)}function V(r,t){r.ptr+=8;let e=r.dv.getFloat64(r.ptr-8,t);return e>8988e304?null:e}function G(r,t){r.ptr+=4;let e=r.dv.getFloat32(r.ptr-4,t);return e>1701e35?null:e}function h(r,t){return r.ptr+=4,r.dv.getUint32(r.ptr-4,t)}function I(r,t){r.ptr+=4;let e=r.dv.getInt32(r.ptr-4,t);return e>2147483620?null:e}function F(r,t){return r.ptr+=2,r.dv.getUint16(r.ptr-2,t)}function j(r,t){r.ptr+=2;let e=r.dv.getInt16(r.ptr-2,t);return e>32740?null:e}function T(r){return r.raw[r.ptr++]}function K(r){let t=r.raw[r.ptr++];return t=t<128?t:t-256,t>100?null:t}var te=["117","118","119","120","121"],re=[102,103,104,105,108,110,111,112,113,114,115];function oe(r){let t="Not a DTA file",e={ptr:0,raw:r,dv:B(r)},s=118,o=!0,b=0,v=0,D=0,E=0,g="",C="",M=[],O=[],W=[];if(!n(e,"<stata_dta>"))throw t;{if(!n(e,"<header>"))throw t;{if(!n(e,"<release>"))throw t;let a=P(e.raw.slice(e.ptr,e.ptr+3));if(e.ptr+=3,!n(e,"</release>"))throw t;if(te.indexOf(a)==-1)throw`Unsupported DTA ${a} file`;s=+a}{if(!n(e,"<byteorder>"))throw t;let a=P(e.raw.slice(e.ptr,e.ptr+3));if(e.ptr+=3,!n(e,"</byteorder>"))throw t;switch(a){case"MSF":o=!1;break;case"LSF":o=!0;break;default:throw`Unsupported byteorder ${a}`}}if(!n(e,"<K>")||(b=s===119||s>=121?h(e,o):F(e,o),!n(e,"</K>")))throw t;{if(!n(e,"<N>"))throw t;if(s==117)v=D=h(e,o);else{let a=h(e,o),l=h(e,o);v=o?(D=a)+(E=l)*Math.pow(2,32):(D=l)+(E=a)*Math.pow(2,32)}if(v>1e6&&console.error("More than 1 million observations -- extra rows will be dropped"),!n(e,"</N>"))throw t}{if(!n(e,"<label>"))throw t;let a=s>=118?2:1,l=a==1?T(e):F(e,o);if(l>0&&(g=U(e.raw.slice(e.ptr,e.ptr+a))),e.ptr+=l,!n(e,"</label>"))throw t}{if(!n(e,"<timestamp>"))throw t;let a=T(e);if(C=P(e.raw.slice(e.ptr,e.ptr+a)),e.ptr+=a,!n(e,"</timestamp>"))throw t}if(!n(e,"</header>"))throw t}if(!n(e,"<map>")||(e.ptr+=8*14,!n(e,"</map>")))throw t;let f=0;{if(!n(e,"<variable_types>"))throw t;for(var w=0;w<b;++w){let a=F(e,o);if(M.push(a),a>=1&&a<=2045)f+=a;else switch(a){case 32768:f+=8;break;case 65525:f+=0;break;case 65526:f+=8;break;case 65527:f+=4;break;case 65528:f+=4;break;case 65529:f+=2;break;case 65530:f+=1;break;default:throw`Unsupported field type ${a}`}}if(!n(e,"</variable_types>"))throw t}{if(!n(e,"<varnames>"))throw t;let a=s>=118?129:33;for(let l=0;l<b;++l){let i=U(e.raw.slice(e.ptr,e.ptr+a));e.ptr+=a,O.push(i.replace(/\x00[\s\S]*/,""))}if(!n(e,"</varnames>"))throw t}if(!n(e,"<sortlist>")||(e.ptr+=(2*b+2)*(s==119||s==121?
2023-11-13 11:03:35 +00:00
//# sourceMappingURL=dta.min.js.map