From 0941ff97a32fb2d77ad827b70367bef588d84cd8 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Fri, 22 Mar 2024 00:39:09 -0400 Subject: [PATCH] dta v0.0.2 --- CHANGELOG.md | 1 + bits/79_html.js | 2 +- package.json | 2 +- packages/dta/Makefile | 7 +++++-- packages/dta/README.md | 12 +++++++++--- packages/dta/dist/dta.js | 4 +++- packages/dta/dist/dta.min.js | 2 +- packages/dta/dist/dta.min.js.map | 4 ++-- packages/dta/dist/dta.mjs | 2 ++ packages/dta/dist/dta.mjs.map | 7 +++++++ packages/dta/dta.ts | 9 +++++---- packages/dta/package.json | 5 +++-- packages/dta/types/index.d.ts | 2 +- 13 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 packages/dta/dist/dta.mjs create mode 100644 packages/dta/dist/dta.mjs.map diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f64661..076c449 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ changes may not be included if they are not expected to break existing code. ## v0.20.2 +* HTML properly encode data-v attribute * SYLK read and write error cells ## v0.20.1 diff --git a/bits/79_html.js b/bits/79_html.js index fe77446..cd42016 100644 --- a/bits/79_html.js +++ b/bits/79_html.js @@ -84,7 +84,7 @@ function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o/*:Sheet2HT else if(cell) { sp["data-t"] = cell && cell.t || 'z'; // note: data-v is unaffected by the timezone interpretation - if(cell.v != null) sp["data-v"] = cell.v instanceof Date ? cell.v.toISOString() : cell.v; + if(cell.v != null) sp["data-v"] = escapehtml(cell.v instanceof Date ? cell.v.toISOString() : cell.v); if(cell.z != null) sp["data-z"] = cell.z; if(cell.l && (cell.l.Target || "#").charAt(0) != "#") w = '' + w + ''; } diff --git a/package.json b/package.json index 332f08c..2ead98e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xlsx", - "version": "0.20.1", + "version": "0.20.2", "author": "sheetjs", "description": "SheetJS Spreadsheet data parser and writer", "keywords": [ diff --git a/packages/dta/Makefile b/packages/dta/Makefile index 19bf738..205a888 100644 --- a/packages/dta/Makefile +++ b/packages/dta/Makefile @@ -17,7 +17,7 @@ types: dta.ts node: dist/dta.js dist/dta.js: dta.ts - npx esbuild@0.14.14 dta.ts --bundle --outdir=dist --platform=node + npx esbuild@0.14.14 $< --bundle --outfile=$@ --platform=node .PHONY: test-node test-node: dist/dta.js test.js @@ -28,5 +28,8 @@ test-node: dist/dta.js test.js browser: dist/dta.min.js dist/dta.min.js: dta.ts - npx esbuild@0.14.14 dta.ts --bundle --outfile=dist/dta.min.js --minify --sourcemap --global-name=DTA + npx esbuild@0.14.14 $< --bundle --outfile=$@ --minify --sourcemap --global-name=DTA + +dist/dta.mjs: dta.ts + npx esbuild@0.14.14 $< --bundle --outfile=$@ --minify --sourcemap --format=esm diff --git a/packages/dta/README.md b/packages/dta/README.md index 9ea525b..aa21c40 100644 --- a/packages/dta/README.md +++ b/packages/dta/README.md @@ -13,13 +13,13 @@ The codec will truncate data to 1048576 observations and 16384 variables. Using NodeJS package manager: ```bash -npm install --save https://cdn.sheetjs.com/dta-0.0.1/dta-0.0.1.tgz +npm install --save https://cdn.sheetjs.com/dta-0.0.2/dta-0.0.2.tgz ``` The standalone script is also hosted on the SheetJS CDN: ```html - + ``` ## Usage @@ -60,4 +60,10 @@ DTA.set_utils(XLSX.utils); out.innerHTML = html; })(); -``` \ No newline at end of file +``` + +`dist/dta.mjs` is a ECMAScript Module build designed to be used with bundlers: + +```js +import * as DTA from 'dta'; +``` diff --git a/packages/dta/dist/dta.js b/packages/dta/dist/dta.js index be3ccbe..e1940e3 100644 --- a/packages/dta/dist/dta.js +++ b/packages/dta/dist/dta.js @@ -28,7 +28,7 @@ __export(dta_exports, { set_utils: () => set_utils, version: () => version }); -var version = "0.0.1"; +var version = "0.0.2"; var _utils; function set_utils(utils) { _utils = utils; @@ -524,6 +524,7 @@ function parse_tagged(raw) { throw err; const wb = _utils.book_new(); _utils.book_append_sheet(wb, ws, "Sheet1"); + wb.bookType = "dta"; return wb; } function parse_legacy(raw) { @@ -668,6 +669,7 @@ function parse_legacy(raw) { } const wb = _utils.book_new(); _utils.book_append_sheet(wb, ws, "Sheet1"); + wb.bookType = "dta"; return wb; } function parse(data) { diff --git a/packages/dta/dist/dta.min.js b/packages/dta/dist/dta.min.js index 6a0f309..68a904c 100644 --- a/packages/dta/dist/dta.min.js +++ b/packages/dta/dist/dta.min.js @@ -1,2 +1,2 @@ -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,""))throw t;{if(!n(e,"
"))throw t;{if(!n(e,""))throw t;let a=P(e.raw.slice(e.ptr,e.ptr+3));if(e.ptr+=3,!n(e,""))throw t;if(te.indexOf(a)==-1)throw`Unsupported DTA ${a} file`;s=+a}{if(!n(e,""))throw t;let a=P(e.raw.slice(e.ptr,e.ptr+3));if(e.ptr+=3,!n(e,""))throw t;switch(a){case"MSF":o=!1;break;case"LSF":o=!0;break;default:throw`Unsupported byteorder ${a}`}}if(!n(e,"")||(b=s===119||s>=121?h(e,o):F(e,o),!n(e,"")))throw t;{if(!n(e,""))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,""))throw t}{if(!n(e,""))throw t}{if(!n(e,""))throw t;let a=T(e);if(C=P(e.raw.slice(e.ptr,e.ptr+a)),e.ptr+=a,!n(e,""))throw t}if(!n(e,"
"))throw t}if(!n(e,"")||(e.ptr+=8*14,!n(e,"")))throw t;let f=0;{if(!n(e,""))throw t;for(var w=0;w=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,""))throw t}{if(!n(e,""))throw t;let a=s>=118?129:33;for(let l=0;l"))throw t}if(!n(e,"")||(e.ptr+=(2*b+2)*(s==119||s==121?2:1),!n(e,"")))throw t;{if(!n(e,""))throw t;let a=s>=118?57:49;for(let l=0;l"))throw t}let p=[];{if(!n(e,""))throw t;let a=s>=118?129:33;for(let l=0;l"))throw t}{if(!n(e,""))throw t;let a=s>=118?321:81;if(e.ptr+=a*b,!n(e,""))throw t}{if(!n(e,""))throw t;for(;n(e,"");){let a=h(e,o);if(e.ptr+=a,!n(e,""))throw t}if(!n(e,""))throw t}let u=$.aoa_to_sheet([O],{dense:!0});var _=[];{if(!n(e,""))throw t;for(let a=0;a=1&&d<=2045){let c=U(e.raw.slice(e.ptr,e.ptr+d));c=c.replace(/\x00[\s\S]*/,""),l[i]=c,e.ptr+=d}else switch(d){case 65525:e.ptr+=0;break;case 65530:l[i]=K(e);break;case 65529:l[i]=j(e,o);break;case 65528:l[i]=I(e,o);break;case 65527:l[i]=G(e,o);break;case 65526:l[i]=V(e,o);break;case 32768:l[i]="##SheetJStrL##",_.push([a+1,i,e.raw.slice(e.ptr,e.ptr+8)]),e.ptr+=8;break;default:throw`Unsupported field type ${d} for ${O[i]}`}typeof l[i]=="number"&&W[i]&&(l[i]=L(l[i],W[i],d))}$.sheet_add_aoa(u,[l],{origin:-1,sheetStubs:!0})}if(!n(e,""))throw t}{if(!n(e,""))throw t;let a=[];for(;e.raw[e.ptr]==71;){if(!n(e,"GSO"))throw t;let l=h(e,o),i=0;if(s==117)i=h(e,o);else{let k=h(e,o),y=h(e,o);i=o?k+y*Math.pow(2,32):y+k*Math.pow(2,32),i>1e6&&console.error("More than 1 million observations -- data will be dropped")}let d=T(e),c=h(e,o);a[i]||(a[i]=[]);let x="";d==129?(x=new TextDecoder(s>=118?"utf8":"latin1").decode(e.raw.slice(e.ptr,e.ptr+c)),e.ptr+=c):(x=new TextDecoder(s>=118?"utf8":"latin1").decode(e.raw.slice(e.ptr,e.ptr+c)).replace(/\x00$/,""),e.ptr+=c),a[i][l]=x}if(!n(e,""))throw t;_.forEach(([l,i,d])=>{let c=B(d),x=0,k=0;switch(s){case 117:x=c.getUint32(0,o),k=c.getUint32(4,o);break;case 118:case 120:{x=c.getUint16(0,o);let y=c.getUint16(2,o),A=c.getUint32(4,o);k=o?y+A*65536:A+y*2**32}break;case 119:case 121:{let y=c.getUint16(0,o),A=d[2];x=o?y+(A<<16):A+(y<<8);let R=d[3],m=c.getUint32(4,o);k=o?R+m*256:m+R*2**32}}u["!data"][l][i].v=a[k][x]})}{let a=s>=118?129:33;if(!n(e,""))throw t;for(;n(e,"");){let l=h(e,o),i=P(e.raw.slice(e.ptr,e.ptr+a)).replace(/\x00.*$/,"");e.ptr+=a,e.ptr+=3;let d=[];{let x=h(e,o),k=h(e,o),y=[],A=[];for(let m=0;m"))throw t}if(!n(e,""))throw t}if(!n(e,"
"))throw t;let S=$.book_new();return $.book_append_sheet(S,u,"Sheet1"),S}function ae(r){let t=r[0];if(re.indexOf(t)==-1)throw new Error("Not a DTA file");let e={ptr:1,raw:r,dv:B(r)},s=!0,o=0,b=0,v="",D="",E=[],g=[],C=[];{let f=T(e);switch(f){case 1:s=!1;break;case 2:s=!0;break;default:throw`DTA ${t} Unexpected byteorder ${f}`}let w=T(e);if(w!=1)throw`DTA ${t} Unexpected filetype ${w}`;e.ptr++,o=F(e,s),b=h(e,s),e.ptr+=t>=108?81:t>=103?32:30,t>=105&&(e.ptr+=18)}let M=[];{let f=0;for(f=0;f=110?33:9;for(f=0;f=114?49:t>=105?12:7;for(f=0;f=110?33:9;for(let _=0;_=106?81:32)*o,t>=105)for(;e.ptr=110?h:F)(e,s);if(f==0&&w==0)break;e.ptr+=w}let O=$.aoa_to_sheet([g],{dense:!0});for(let f=0;f=113)&&u>=1&&u<=244){let _=U(e.raw.slice(e.ptr,e.ptr+u));_=_.replace(/\x00[\s\S]*/,""),w[p]=_,e.ptr+=u}else if((t==112||t<=110)&&u>=128){let _=U(e.raw.slice(e.ptr,e.ptr+u-127));_=_.replace(/\x00[\s\S]*/,""),w[p]=_,e.ptr+=u-127}else switch(u){case 251:case 98:w[p]=K(e);break;case 252:case 105:w[p]=j(e,s);break;case 253:case 108:w[p]=I(e,s);break;case 254:case 102:w[p]=G(e,s);break;case 255:case 100:w[p]=V(e,s);break;default:throw`Unsupported field type ${u} for ${g[p]}`}typeof w[p]=="number"&&C[p]&&(w[p]=L(w[p],C[p],u))}$.sheet_add_aoa(O,[w],{origin:-1,sheetStubs:!0})}if(t>=115)for(;e.ptr=102&&r[0]<=115)return ae(r);if(r[0]===60)return oe(r);throw new Error("Not a DTA file")}return X(ne);})(); +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 a of Y(t))!q.call(r,a)&&(e||a!=="default")&&N(r,a,{get:()=>t[a],enumerable:!(s=J(t,a))||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.2",$;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 h=L(-r,t,e);return h.w="-"+h.w,h}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 h=+(t.match(/%(\d+)/)||[])[1]||8,v=0;r<1&&++v,r<.1&&++v,r<.01&&++v,r<.001&&++v;let D=r.toExponential(),T=D.indexOf("e")==-1?0:+D.slice(D.indexOf("e")+1),y=h-2-T;y<0&&(y=0);var a=t.match(/%\d+\.(\d+)/);a&&+a[1]&&(y=+a[1]),s.w=(Math.round(r*10**y)/10**y).toFixed(y).replace(/^([-]?)0\./,"$1."),s.w=s.w.slice(0,h+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 b(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 W(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 ae(r){let t="Not a DTA file",e={ptr:0,raw:r,dv:B(r)},s=118,a=!0,h=0,v=0,D=0,T=0,y="",C="",M=[],O=[],E=[];if(!n(e,""))throw t;{if(!n(e,"
"))throw t;{if(!n(e,""))throw t;let o=P(e.raw.slice(e.ptr,e.ptr+3));if(e.ptr+=3,!n(e,""))throw t;if(te.indexOf(o)==-1)throw`Unsupported DTA ${o} file`;s=+o}{if(!n(e,""))throw t;let o=P(e.raw.slice(e.ptr,e.ptr+3));if(e.ptr+=3,!n(e,""))throw t;switch(o){case"MSF":a=!1;break;case"LSF":a=!0;break;default:throw`Unsupported byteorder ${o}`}}if(!n(e,"")||(h=s===119||s>=121?b(e,a):F(e,a),!n(e,"")))throw t;{if(!n(e,""))throw t;if(s==117)v=D=b(e,a);else{let o=b(e,a),l=b(e,a);v=a?(D=o)+(T=l)*Math.pow(2,32):(D=l)+(T=o)*Math.pow(2,32)}if(v>1e6&&console.error("More than 1 million observations -- extra rows will be dropped"),!n(e,""))throw t}{if(!n(e,""))throw t}{if(!n(e,""))throw t;let o=W(e);if(C=P(e.raw.slice(e.ptr,e.ptr+o)),e.ptr+=o,!n(e,""))throw t}if(!n(e,"
"))throw t}if(!n(e,"")||(e.ptr+=8*14,!n(e,"")))throw t;let f=0;{if(!n(e,""))throw t;for(var w=0;w=1&&o<=2045)f+=o;else switch(o){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 ${o}`}}if(!n(e,""))throw t}{if(!n(e,""))throw t;let o=s>=118?129:33;for(let l=0;l"))throw t}if(!n(e,"")||(e.ptr+=(2*h+2)*(s==119||s==121?2:1),!n(e,"")))throw t;{if(!n(e,""))throw t;let o=s>=118?57:49;for(let l=0;l"))throw t}let p=[];{if(!n(e,""))throw t;let o=s>=118?129:33;for(let l=0;l"))throw t}{if(!n(e,""))throw t;let o=s>=118?321:81;if(e.ptr+=o*h,!n(e,""))throw t}{if(!n(e,""))throw t;for(;n(e,"");){let o=b(e,a);if(e.ptr+=o,!n(e,""))throw t}if(!n(e,""))throw t}let u=$.aoa_to_sheet([O],{dense:!0});var _=[];{if(!n(e,""))throw t;for(let o=0;o=1&&d<=2045){let c=U(e.raw.slice(e.ptr,e.ptr+d));c=c.replace(/\x00[\s\S]*/,""),l[i]=c,e.ptr+=d}else switch(d){case 65525:e.ptr+=0;break;case 65530:l[i]=K(e);break;case 65529:l[i]=j(e,a);break;case 65528:l[i]=I(e,a);break;case 65527:l[i]=G(e,a);break;case 65526:l[i]=V(e,a);break;case 32768:l[i]="##SheetJStrL##",_.push([o+1,i,e.raw.slice(e.ptr,e.ptr+8)]),e.ptr+=8;break;default:throw`Unsupported field type ${d} for ${O[i]}`}typeof l[i]=="number"&&E[i]&&(l[i]=L(l[i],E[i],d))}$.sheet_add_aoa(u,[l],{origin:-1,sheetStubs:!0})}if(!n(e,""))throw t}{if(!n(e,""))throw t;let o=[];for(;e.raw[e.ptr]==71;){if(!n(e,"GSO"))throw t;let l=b(e,a),i=0;if(s==117)i=b(e,a);else{let x=b(e,a),g=b(e,a);i=a?x+g*Math.pow(2,32):g+x*Math.pow(2,32),i>1e6&&console.error("More than 1 million observations -- data will be dropped")}let d=W(e),c=b(e,a);o[i]||(o[i]=[]);let k="";d==129?(k=new TextDecoder(s>=118?"utf8":"latin1").decode(e.raw.slice(e.ptr,e.ptr+c)),e.ptr+=c):(k=new TextDecoder(s>=118?"utf8":"latin1").decode(e.raw.slice(e.ptr,e.ptr+c)).replace(/\x00$/,""),e.ptr+=c),o[i][l]=k}if(!n(e,""))throw t;_.forEach(([l,i,d])=>{let c=B(d),k=0,x=0;switch(s){case 117:k=c.getUint32(0,a),x=c.getUint32(4,a);break;case 118:case 120:{k=c.getUint16(0,a);let g=c.getUint16(2,a),A=c.getUint32(4,a);x=a?g+A*65536:A+g*2**32}break;case 119:case 121:{let g=c.getUint16(0,a),A=d[2];k=a?g+(A<<16):A+(g<<8);let R=d[3],m=c.getUint32(4,a);x=a?R+m*256:m+R*2**32}}u["!data"][l][i].v=o[x][k]})}{let o=s>=118?129:33;if(!n(e,""))throw t;for(;n(e,"");){let l=b(e,a),i=P(e.raw.slice(e.ptr,e.ptr+o)).replace(/\x00.*$/,"");e.ptr+=o,e.ptr+=3;let d=[];{let k=b(e,a),x=b(e,a),g=[],A=[];for(let m=0;m"))throw t}if(!n(e,""))throw t}if(!n(e,"
"))throw t;let S=$.book_new();return $.book_append_sheet(S,u,"Sheet1"),S.bookType="dta",S}function oe(r){let t=r[0];if(re.indexOf(t)==-1)throw new Error("Not a DTA file");let e={ptr:1,raw:r,dv:B(r)},s=!0,a=0,h=0,v="",D="",T=[],y=[],C=[];{let f=W(e);switch(f){case 1:s=!1;break;case 2:s=!0;break;default:throw`DTA ${t} Unexpected byteorder ${f}`}let w=W(e);if(w!=1)throw`DTA ${t} Unexpected filetype ${w}`;e.ptr++,a=F(e,s),h=b(e,s),e.ptr+=t>=108?81:t>=103?32:30,t>=105&&(e.ptr+=18)}let M=[];{let f=0;for(f=0;f=110?33:9;for(f=0;f=114?49:t>=105?12:7;for(f=0;f=110?33:9;for(let _=0;_=106?81:32)*a,t>=105)for(;e.ptr=110?b:F)(e,s);if(f==0&&w==0)break;e.ptr+=w}let O=$.aoa_to_sheet([y],{dense:!0});for(let f=0;f=113)&&u>=1&&u<=244){let _=U(e.raw.slice(e.ptr,e.ptr+u));_=_.replace(/\x00[\s\S]*/,""),w[p]=_,e.ptr+=u}else if((t==112||t<=110)&&u>=128){let _=U(e.raw.slice(e.ptr,e.ptr+u-127));_=_.replace(/\x00[\s\S]*/,""),w[p]=_,e.ptr+=u-127}else switch(u){case 251:case 98:w[p]=K(e);break;case 252:case 105:w[p]=j(e,s);break;case 253:case 108:w[p]=I(e,s);break;case 254:case 102:w[p]=G(e,s);break;case 255:case 100:w[p]=V(e,s);break;default:throw`Unsupported field type ${u} for ${y[p]}`}typeof w[p]=="number"&&C[p]&&(w[p]=L(w[p],C[p],u))}$.sheet_add_aoa(O,[w],{origin:-1,sheetStubs:!0})}if(t>=115)for(;e.ptr=102&&r[0]<=115)return oe(r);if(r[0]===60)return ae(r);throw new Error("Not a DTA file")}return X(ne);})(); //# sourceMappingURL=dta.min.js.map diff --git a/packages/dta/dist/dta.min.js.map b/packages/dta/dist/dta.min.js.map index a4fc13a..89cb4a1 100644 --- a/packages/dta/dist/dta.min.js.map +++ b/packages/dta/dist/dta.min.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../dta.ts"], - "sourcesContent": ["import { CellObject, DenseWorkSheet, WorkBook, type utils } from 'xlsx';\nexport { parse, set_utils, version };\n\nconst version = \"0.0.1\";\n\nlet _utils: typeof utils;\n/** Set internal instance of `utils`\n *\n * Usage:\n *\n * ```js\n * const XLSX = require(\"xlsx\");\n * const DTA = require(\"dta\");\n * DTA.set_utils(XLSX.utils);\n * ```\n *\n * @param utils utils object\n */\nfunction set_utils(utils: any): void {\n _utils = utils;\n}\n\nfunction u8_to_str(u8: Uint8Array): string {\n return new TextDecoder().decode(u8);\n}\n\n/* sadly the web zealots decided to abandon binary strings */\nfunction u8_to_latin1(u8: Uint8Array): string {\n return new TextDecoder(\"latin1\").decode(u8);\n}\n\n\n/* TODO: generalize and map to SSF */\nfunction format_number_dta(value: number, format: string, t: number): CellObject {\n if(value < 0) { const res = format_number_dta(-value, format, t); res.w = \"-\" + res.w; return res; }\n const o: CellObject = { t: \"n\", v: value };\n /* NOTE: The Stata CSV exporter appears to ignore the column formats, instead using these defaults */\n switch(t) {\n case 251: case 0x62: case 65530: format = \"%8.0g\"; break; // byte\n case 252: case 0x69: case 65529: format = \"%8.0g\"; break; // int\n case 253: case 0x6c: case 65528: format = \"%12.0g\"; break; // long\n case 254: case 0x66: case 65527: format = \"%9.0g\"; break; // float\n case 255: case 0x64: case 65526: format = \"%10.0g\"; break; // double\n default: throw t;\n }\n try {\n let w = +((format.match(/%(\\d+)/)||[])[1]) || 8;\n let k = 0;\n if(value < 1) ++k;\n if(value < 0.1) ++k;\n if(value < 0.01) ++k;\n if(value < 0.001) ++k;\n const e = value.toExponential();\n const exp = e.indexOf(\"e\") == -1 ? 0 : +e.slice(e.indexOf(\"e\")+1);\n let h = w - 2 - exp;\n if(h < 0) h = 0;\n var m = format.match(/%\\d+\\.(\\d+)/);\n if(m && +m[1]) h = +m[1];\n o.w = (Math.round(value * 10**(h))/10**(h)).toFixed(h).replace(/^([-]?)0\\./,\"$1.\");\n o.w = o.w.slice(0, w + k);\n if(o.w.indexOf(\".\") > -1) o.w = o.w.replace(/0+$/,\"\");\n o.w = o.w.replace(/\\.$/,\"\");\n if(o.w == \"\") o.w = \"0\";\n } catch(e) {}\n return o;\n}\n\ninterface Payload {\n /** Offset */\n ptr: number;\n\n /** Raw data */\n raw: Uint8Array;\n\n /** DataView */\n dv: DataView;\n}\n\nfunction u8_to_dataview(array: Uint8Array): DataView { return new DataView(array.buffer, array.byteOffset, array.byteLength); }\nfunction valid_inc(p: Payload, n: string): boolean {\n if(u8_to_str(p.raw.slice(p.ptr, p.ptr + n.length)) != n) return false;\n p.ptr += n.length;\n return true;\n}\n\nfunction read_f64(p: Payload, LE: boolean): number | null {\n p.ptr += 8;\n const d = p.dv.getFloat64(p.ptr - 8, LE);\n return d > 8.988e+307 ? null : d;\n}\nfunction read_f32(p: Payload, LE: boolean): number | null {\n p.ptr += 4;\n const d = p.dv.getFloat32(p.ptr - 4, LE);\n return d > 1.701e+38 ? null : d;\n\n}\nfunction read_u32(p: Payload, LE: boolean) {\n p.ptr += 4;\n return p.dv.getUint32(p.ptr - 4, LE);\n}\nfunction read_i32(p: Payload, LE: boolean): number | null {\n p.ptr += 4;\n const u = p.dv.getInt32(p.ptr - 4, LE);\n return u > 0x7fffffe4 ? null : u;\n}\nfunction read_u16(p: Payload, LE: boolean) {\n p.ptr += 2;\n return p.dv.getUint16(p.ptr - 2, LE);\n}\nfunction read_i16(p: Payload, LE: boolean): number | null {\n p.ptr += 2;\n const u = p.dv.getInt16(p.ptr - 2, LE);\n return u > 32740 ? null : u;\n}\nfunction read_u8(p: Payload) {\n return p.raw[p.ptr++];\n}\nfunction read_i8(p: Payload): number | null {\n let u = p.raw[p.ptr++];\n u = u < 128 ? u : u - 256;\n return u > 100 ? null : u;\n}\n\n/* the annotations are from `dtaversion` */\nconst SUPPORTED_VERSIONS_TAGGED = [\n \"117\", // stata 13\n \"118\", // stata 14-18\n \"119\", // stata 15-18 (> 32767 variables)\n \"120\", // stata 18 (<= 32767, with aliases)\n \"121\", // stata 18 (> 32767, with aliases)\n];\nconst SUPPORTED_VERSIONS_LEGACY = [\n 102, // stata 1\n 103, // stata 2/3\n 104, // stata 4\n 105, // stata 5\n 108, // stata 6\n 110, // stata 7\n 111, // stata 7\n 112, // stata 8/9\n 113, // stata 8/9\n 114, // stata 10/11\n 115, // stata 12\n];\n\nfunction parse_tagged(raw: Uint8Array): WorkBook {\n const err = (\"Not a DTA file\");\n\n const d: Payload = {\n ptr: 0,\n raw,\n dv: u8_to_dataview(raw)\n }\n\n let vers: number = 118;\n let LE: boolean = true;\n let nvar: number = 0, nobs: number = 0, nobs_lo = 0, nobs_hi = 0;\n let label: string = \"\", timestamp: string = \"\";\n const var_types: number[] = [];\n const var_names: string[] = [];\n const formats: string[] = [];\n\n /* 5. Dataset format definition */\n if(!valid_inc(d, \"\")) throw err;\n\n /* 5.1 Header
*/\n {\n if(!valid_inc(d, \"
\")) throw err;\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n /* NOTE: this assumes the version is 3 characters wide */\n const res = u8_to_latin1(d.raw.slice(d.ptr, d.ptr+3));\n d.ptr += 3;\n if(!valid_inc(d, \"\")) throw err;\n if(SUPPORTED_VERSIONS_TAGGED.indexOf(res) == -1) throw (`Unsupported DTA ${res} file`);\n vers = +res;\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n /* NOTE: this assumes the byte order is 3 characters wide */\n const res = u8_to_latin1(d.raw.slice(d.ptr, d.ptr+3));\n d.ptr += 3;\n if(!valid_inc(d, \"\")) throw err;\n switch(res) {\n case \"MSF\": LE = false; break;\n case \"LSF\": LE = true; break;\n default: throw (`Unsupported byteorder ${res}`);\n }\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n nvar = (vers === 119 || vers >= 121) ? read_u32(d, LE) : read_u16(d, LE);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n if(vers == 117) nobs = nobs_lo = read_u32(d, LE);\n else {\n const lo = read_u32(d, LE), hi = read_u32(d, LE);\n nobs = LE ? ((nobs_lo = lo) + (nobs_hi = hi) * Math.pow(2,32)) : ((nobs_lo = hi) + (nobs_hi = lo) * Math.pow(2,32));\n }\n if(nobs > 1e6) console.error(`More than 1 million observations -- extra rows will be dropped`);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /*
\")) throw err;\n }\n\n /* 5.2 Map */\n {\n /* TODO: validate map? */\n if(!valid_inc(d, \"\")) throw err;\n /* 14 8-byte offsets for:\n \n \n \n \n \n \n \n \n \n \n \n \n \n EOF\n */\n d.ptr += 8 * 14;\n if(!valid_inc(d, \"\")) throw err;\n }\n\n let stride = 0;\n /* 5.3 Variable types */\n {\n if(!valid_inc(d, \"\")) throw err;\n for(var i = 0; i < nvar; ++i) {\n const type = read_u16(d, LE);\n var_types.push(type);\n if(type >= 1 && type <= 2045) stride += type;\n else switch(type) {\n case 32768: stride += 8; break;\n case 65525: stride += 0; break; // alias\n case 65526: stride += 8; break;\n case 65527: stride += 4; break;\n case 65528: stride += 4; break;\n case 65529: stride += 2; break;\n case 65530: stride += 1; break;\n default: throw (`Unsupported field type ${type}`);\n }\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.4 Variable names */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 129 : 33;\n for(let i = 0; i < nvar; ++i) {\n const name = u8_to_str(d.raw.slice(d.ptr, d.ptr + w));\n d.ptr += w;\n var_names.push(name.replace(/\\x00[\\s\\S]*/,\"\"));\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.5 Sort order of observations */\n {\n /* TODO: check sort list? */\n if(!valid_inc(d, \"\")) throw err;\n d.ptr += (2 * nvar + 2) * ((vers == 119 || vers == 121) ? 2 : 1);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.6 Display formats */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 57 : 49;\n for(let i = 0; i < nvar; ++i) {\n const name = u8_to_str(d.raw.slice(d.ptr, d.ptr + w));\n d.ptr += w;\n formats.push(name.replace(/\\x00[\\s\\S]*/,\"\"));\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n const value_label_names: string[] = [];\n /* TODO: */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 129 : 33;\n for(let i = 0; i < nvar; ++i, d.ptr += w) value_label_names[i] = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* TODO: */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 321 : 81;\n d.ptr += w * nvar;\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.9 Characteristics */\n {\n if(!valid_inc(d, \"\")) throw err;\n while(valid_inc(d, \"\")) {\n const len = read_u32(d, LE);\n d.ptr += len;\n if(!valid_inc(d, \"\")) throw err;\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n const ws: DenseWorkSheet = (_utils.aoa_to_sheet([var_names], {dense: true} as any) as DenseWorkSheet);\n\n var ptrs: Array<[number, number, Uint8Array]> = []\n /* 5.10 Data */\n {\n if(!valid_inc(d, \"\")) throw err;\n for(let R = 0; R < nobs; ++R) {\n const row: any[] = [];\n for(let C = 0; C < nvar; ++C) {\n let t = var_types[C];\n // TODO: formats, dta_12{0,1} aliases?\n if(t >= 1 && t <= 2045) {\n /* NOTE: dta_117 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t;\n } else switch(t) {\n case 65525: d.ptr += 0; break; // alias\n case 65530: row[C] = read_i8(d); break; // byte\n case 65529: row[C] = read_i16(d, LE); break; // int\n case 65528: row[C] = read_i32(d, LE); break; // long\n case 65527: row[C] = read_f32(d, LE); break; // float\n case 65526: row[C] = read_f64(d, LE); break; // double\n case 32768: {\n row[C] = \"##SheetJStrL##\";\n ptrs.push([R+1,C, d.raw.slice(d.ptr, d.ptr + 8)]);\n d.ptr += 8;\n } break;\n default: throw (`Unsupported field type ${t} for ${var_names[C]}`);\n }\n if(typeof row[C] == \"number\" && formats[C]) row[C] = format_number_dta(row[C], formats[C], t);\n }\n _utils.sheet_add_aoa(ws, [row], {origin: -1, sheetStubs: true});\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.11 StrLs */\n {\n if(!valid_inc(d, \"\")) throw err;\n\n const strl_tbl: string[][] = [];\n while(d.raw[d.ptr] == 71 /* G */) {\n if(!valid_inc(d, \"GSO\")) throw err;\n const v = read_u32(d, LE);\n let o = 0;\n if(vers == 117) o = read_u32(d, LE);\n else {\n const lo = read_u32(d, LE), hi = read_u32(d, LE);\n o = LE ? (lo + hi * Math.pow(2,32)) : (hi + lo * Math.pow(2,32));\n if(o > 1e6) console.error(`More than 1 million observations -- data will be dropped`);\n }\n const t = read_u8(d);\n const len = read_u32(d, LE);\n if(!strl_tbl[o]) strl_tbl[o] = [];\n let str = \"\";\n if(t == 129) {\n // TODO: dta_117 codepage\n str = new TextDecoder(vers >= 118 ? \"utf8\" : \"latin1\").decode(d.raw.slice(d.ptr, d.ptr + len));\n d.ptr += len;\n } else {\n str = new TextDecoder(vers >= 118 ? \"utf8\" : \"latin1\").decode(d.raw.slice(d.ptr, d.ptr + len)).replace(/\\x00$/,\"\");\n d.ptr += len;\n }\n strl_tbl[o][v] = str;\n }\n if(!valid_inc(d, \"\")) throw err;\n\n ptrs.forEach(([R,C,buf]) => {\n const dv = u8_to_dataview(buf);\n let v = 0, o = 0;\n switch(vers) {\n case 117: { // v(4) o(4)\n v = dv.getUint32(0, LE);\n o = dv.getUint32(4, LE);\n } break;\n\n case 118: case 120: { // v(2) o(6)\n v = dv.getUint16(0, LE);\n const o1 = dv.getUint16(2, LE), o2 = dv.getUint32(4, LE);\n o = LE ? o1 + o2 * 65536 : o2 + o1 * (2**32);\n } break;\n\n case 119: case 121: { // v(3) o(5)\n const v1 = dv.getUint16(0, LE), v2 = buf[2];\n v = LE ? v1 + (v2 << 16) : v2 + (v1 << 8);\n const o1 = buf[3], o2 = dv.getUint32(4, LE);\n o = LE ? o1 + o2 * 256 : o2 + o1 * (2**32);\n }\n }\n ws[\"!data\"][R][C].v = strl_tbl[o][v];\n });\n }\n\n /* 5.12 Value labels */\n {\n const w = vers >= 118 ? 129 : 33;\n if(!valid_inc(d, \"\")) throw err;\n while(valid_inc(d, \"\")) {\n let len = read_u32(d, LE);\n const labname = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n d.ptr += w;\n d.ptr += 3; // padding\n const labels: string[] = [];\n {\n const n = read_u32(d, LE);\n const txtlen = read_u32(d, LE);\n const off: number[] = [], val: number[] = [];\n for(let i = 0; i < n; ++i) off.push(read_u32(d, LE));\n for(let i = 0; i < n; ++i) val.push(read_u32(d, LE));\n const str = u8_to_str(d.raw.slice(d.ptr, d.ptr + txtlen));\n d.ptr += txtlen;\n for(let i = 0; i < n; ++i) labels[val[i]] = str.slice(off[i], str.indexOf(\"\\x00\", off[i]));\n }\n const C = value_label_names.indexOf(labname);\n if(C == -1) throw new Error(`unexpected value label |${labname}|`);\n for(let R = 1; R < ws[\"!data\"].length; ++R) {\n const cell = ws[\"!data\"][R][C];\n cell.t = \"s\"; cell.v = cell.w = labels[(cell.v as number)||0];\n }\n //d.ptr += len; // value_label_table\n if(!valid_inc(d, \"\")) throw err;\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n if(!valid_inc(d, \"\")) throw err;\n const wb = _utils.book_new();\n _utils.book_append_sheet(wb, ws, \"Sheet1\");\n return wb;\n}\n\nfunction parse_legacy(raw: Uint8Array): WorkBook {\n let vers: number = raw[0];\n if(SUPPORTED_VERSIONS_LEGACY.indexOf(vers) == -1) throw new Error(\"Not a DTA file\");\n\n const d: Payload = {\n ptr: 1,\n raw,\n dv: u8_to_dataview(raw)\n }\n\n let LE: boolean = true;\n let nvar: number = 0, nobs: number = 0;\n let label: string = \"\", timestamp: string = \"\";\n const var_types: number[] = [];\n const var_names: string[] = [];\n const formats: string[] = [];\n\n /* 5.1 Header */\n {\n const byteorder = read_u8(d);\n switch(byteorder) {\n case 1: LE = false; break;\n case 2: LE = true; break;\n default: throw (`DTA ${vers} Unexpected byteorder ${byteorder}`);\n }\n\n let byte = read_u8(d);\n if(byte != 1) throw (`DTA ${vers} Unexpected filetype ${byte}`);\n // NOTE: dta_105 technically supports filetype 2\n\n d.ptr++; // \"unused\"\n nvar = read_u16(d, LE);\n nobs = read_u32(d, LE);\n d.ptr += (vers >= 108 ? 81 : vers >= 103 ? 32 : 30); // TODO: data_label\n if(vers >= 105) d.ptr += 18; // TODO: time_stamp\n }\n\n /* 5.2 Descriptors */\n const value_label_names: string[] = [];\n {\n let C = 0;\n\n // typlist\n for(C = 0; C < nvar; ++C) var_types.push(read_u8(d));\n\n // varlist\n const w = vers >= 110 ? 33 : 9;\n for(C = 0; C < nvar; ++C) {\n var_names.push(u8_to_str(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00[\\s\\S]*$/,\"\"));\n d.ptr += w;\n }\n\n // srtlist\n d.ptr += 2*(nvar + 1);\n\n // fmtlist\n const fw = (vers >= 114 ? 49 : vers >= 105 ? 12 : 7);\n for(C = 0; C < nvar; ++C) {\n formats.push(u8_to_str(d.raw.slice(d.ptr, d.ptr + fw)).replace(/\\x00[\\s\\S]*$/,\"\"));\n d.ptr += fw;\n }\n // lbllist\n const lw = vers >= 110 ? 33 : 9;\n for(let i = 0; i < nvar; ++i, d.ptr += lw) value_label_names[i] = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + lw)).replace(/\\x00.*$/,\"\");\n }\n\n /* 5.3 Variable labels */\n // TODO: should these names be used in the worksheet?\n d.ptr += (vers >= 106 ? 81 : 32) * nvar;\n\n /* 5.4 Expansion fields */\n if(vers >= 105) while(d.ptr < d.raw.length) {\n const dt = read_u8(d), len = (vers >= 110 ? read_u32 : read_u16)(d, LE);\n if(dt == 0 && len == 0) break;\n d.ptr += len;\n }\n\n const ws: DenseWorkSheet = (_utils.aoa_to_sheet([var_names], {dense: true} as any) as DenseWorkSheet);\n\n /* 5.5 Data */\n for(let R = 0; R < nobs; ++R) {\n const row: any[] = [];\n for(let C = 0; C < nvar; ++C) {\n let t = var_types[C];\n // TODO: data type processing\n if((vers == 111 || vers >= 113) && t >= 1 && t <= 244) {\n /* NOTE: dta_117 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t;\n } else if((vers == 112 || vers <= 110) && t >= 0x80) {\n /* NOTE: dta_105 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t - 0x7F));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t - 0x7F;\n } else switch(t) {\n case 251: case 0x62: row[C] = read_i8(d); break; // byte\n case 252: case 0x69: row[C] = read_i16(d, LE); break; // int\n case 253: case 0x6c: row[C] = read_i32(d, LE); break; // long\n case 254: case 0x66: row[C] = read_f32(d, LE); break; // float\n case 255: case 0x64: row[C] = read_f64(d, LE); break; // double\n default: throw (`Unsupported field type ${t} for ${var_names[C]}`);\n }\n if(typeof row[C] == \"number\" && formats[C]) row[C] = format_number_dta(row[C], formats[C], t);\n }\n _utils.sheet_add_aoa(ws, [row], {origin: -1, sheetStubs: true});\n }\n\n /* 5.6 Value labels */\n // TODO: < 115\n if(vers >= 115) while(d.ptr < d.raw.length) {\n const w = 33;\n let len = read_u32(d, LE);\n const labname = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n d.ptr += w;\n d.ptr += 3; // padding\n const labels: string[] = [];\n {\n const n = read_u32(d, LE);\n const txtlen = read_u32(d, LE);\n const off: number[] = [], val: number[] = [];\n for(let i = 0; i < n; ++i) off.push(read_u32(d, LE));\n for(let i = 0; i < n; ++i) val.push(read_u32(d, LE));\n const str = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + txtlen));\n d.ptr += txtlen;\n for(let i = 0; i < n; ++i) labels[val[i]] = str.slice(off[i], str.indexOf(\"\\x00\", off[i]));\n }\n const C = value_label_names.indexOf(labname);\n if(C == -1) throw new Error(`unexpected value label |${labname}|`);\n for(let R = 1; R < ws[\"!data\"].length; ++R) {\n const cell = ws[\"!data\"][R][C];\n cell.t = \"s\"; cell.v = cell.w = labels[(cell.v as number)||0];\n }\n\n }\n\n const wb: WorkBook = _utils.book_new();\n _utils.book_append_sheet(wb, ws, \"Sheet1\");\n return wb;\n}\n\n/** Parse DTA file\n *\n * NOTE: In NodeJS, `Buffer` extends `Uint8Array`\n *\n * @param {Uint8Array} data File data\n */\nfunction parse(data: Uint8Array): WorkBook {\n if(data[0] >= 102 && data[0] <= 115) return parse_legacy(data);\n if(data[0] === 60) return parse_tagged(data);\n throw new Error(\"Not a DTA file\");\n}\n"], - "mappings": "4hBAAA,8DAGA,GAAM,GAAU,QAEZ,EAaJ,YAAmB,EAAkB,CACnC,EAAS,EAGX,WAAmB,EAAwB,CACzC,MAAO,IAAI,eAAc,OAAO,GAIl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,GACvC,KAAM,IAAI,OAAM", + "sourcesContent": ["import { CellObject, DenseWorkSheet, WorkBook, type utils } from 'xlsx';\nexport { parse, set_utils, version };\n\nconst version = \"0.0.2\";\n\nlet _utils: typeof utils;\n/** Set internal instance of `utils`\n *\n * Usage:\n *\n * ```js\n * const XLSX = require(\"xlsx\");\n * const DTA = require(\"dta\");\n * DTA.set_utils(XLSX.utils);\n * ```\n *\n * @param utils utils object\n */\nfunction set_utils(utils: any): void {\n _utils = utils;\n}\n\nfunction u8_to_str(u8: Uint8Array): string {\n return new TextDecoder().decode(u8);\n}\n\n/* sadly the web zealots decided to abandon binary strings */\nfunction u8_to_latin1(u8: Uint8Array): string {\n return new TextDecoder(\"latin1\").decode(u8);\n}\n\n\n/* TODO: generalize and map to SSF */\nfunction format_number_dta(value: number, format: string, t: number): CellObject {\n if(value < 0) { const res = format_number_dta(-value, format, t); res.w = \"-\" + res.w; return res; }\n const o: CellObject = { t: \"n\", v: value };\n /* NOTE: The Stata CSV exporter appears to ignore the column formats, instead using these defaults */\n switch(t) {\n case 251: case 0x62: case 65530: format = \"%8.0g\"; break; // byte\n case 252: case 0x69: case 65529: format = \"%8.0g\"; break; // int\n case 253: case 0x6c: case 65528: format = \"%12.0g\"; break; // long\n case 254: case 0x66: case 65527: format = \"%9.0g\"; break; // float\n case 255: case 0x64: case 65526: format = \"%10.0g\"; break; // double\n default: throw t;\n }\n try {\n let w = +((format.match(/%(\\d+)/)||[])[1]) || 8;\n let k = 0;\n if(value < 1) ++k;\n if(value < 0.1) ++k;\n if(value < 0.01) ++k;\n if(value < 0.001) ++k;\n const e = value.toExponential();\n const exp = e.indexOf(\"e\") == -1 ? 0 : +e.slice(e.indexOf(\"e\")+1);\n let h = w - 2 - exp;\n if(h < 0) h = 0;\n var m = format.match(/%\\d+\\.(\\d+)/);\n if(m && +m[1]) h = +m[1];\n o.w = (Math.round(value * 10**(h))/10**(h)).toFixed(h).replace(/^([-]?)0\\./,\"$1.\");\n o.w = o.w.slice(0, w + k);\n if(o.w.indexOf(\".\") > -1) o.w = o.w.replace(/0+$/,\"\");\n o.w = o.w.replace(/\\.$/,\"\");\n if(o.w == \"\") o.w = \"0\";\n } catch(e) {}\n return o;\n}\n\ninterface Payload {\n /** Offset */\n ptr: number;\n\n /** Raw data */\n raw: Uint8Array;\n\n /** DataView */\n dv: DataView;\n}\n\nfunction u8_to_dataview(array: Uint8Array): DataView { return new DataView(array.buffer, array.byteOffset, array.byteLength); }\nfunction valid_inc(p: Payload, n: string): boolean {\n if(u8_to_str(p.raw.slice(p.ptr, p.ptr + n.length)) != n) return false;\n p.ptr += n.length;\n return true;\n}\n\nfunction read_f64(p: Payload, LE: boolean): number | null {\n p.ptr += 8;\n const d = p.dv.getFloat64(p.ptr - 8, LE);\n return d > 8.988e+307 ? null : d;\n}\nfunction read_f32(p: Payload, LE: boolean): number | null {\n p.ptr += 4;\n const d = p.dv.getFloat32(p.ptr - 4, LE);\n return d > 1.701e+38 ? null : d;\n}\nfunction read_u32(p: Payload, LE: boolean) {\n p.ptr += 4;\n return p.dv.getUint32(p.ptr - 4, LE);\n}\nfunction read_i32(p: Payload, LE: boolean): number | null {\n p.ptr += 4;\n const u = p.dv.getInt32(p.ptr - 4, LE);\n return u > 0x7fffffe4 ? null : u;\n}\nfunction read_u16(p: Payload, LE: boolean) {\n p.ptr += 2;\n return p.dv.getUint16(p.ptr - 2, LE);\n}\nfunction read_i16(p: Payload, LE: boolean): number | null {\n p.ptr += 2;\n const u = p.dv.getInt16(p.ptr - 2, LE);\n return u > 32740 ? null : u;\n}\nfunction read_u8(p: Payload) {\n return p.raw[p.ptr++];\n}\nfunction read_i8(p: Payload): number | null {\n let u = p.raw[p.ptr++];\n u = u < 128 ? u : u - 256;\n return u > 100 ? null : u;\n}\n\n/* the annotations are from `dtaversion` */\nconst SUPPORTED_VERSIONS_TAGGED = [\n \"117\", // stata 13\n \"118\", // stata 14-18\n \"119\", // stata 15-18 (> 32767 variables)\n \"120\", // stata 18 (<= 32767, with aliases)\n \"121\", // stata 18 (> 32767, with aliases)\n];\nconst SUPPORTED_VERSIONS_LEGACY = [\n 102, // stata 1\n 103, // stata 2/3\n 104, // stata 4\n 105, // stata 5\n 108, // stata 6\n 110, // stata 7\n 111, // stata 7\n 112, // stata 8/9\n 113, // stata 8/9\n 114, // stata 10/11\n 115, // stata 12\n];\n\nfunction parse_tagged(raw: Uint8Array): WorkBook {\n const err = (\"Not a DTA file\");\n\n const d: Payload = {\n ptr: 0,\n raw,\n dv: u8_to_dataview(raw)\n };\n\n let vers: number = 118;\n let LE: boolean = true;\n let nvar: number = 0, nobs: number = 0, nobs_lo = 0, nobs_hi = 0;\n let label: string = \"\", timestamp: string = \"\";\n const var_types: number[] = [];\n const var_names: string[] = [];\n const formats: string[] = [];\n\n /* 5. Dataset format definition */\n if(!valid_inc(d, \"\")) throw err;\n\n /* 5.1 Header
*/\n {\n if(!valid_inc(d, \"
\")) throw err;\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n /* NOTE: this assumes the version is 3 characters wide */\n const res = u8_to_latin1(d.raw.slice(d.ptr, d.ptr+3));\n d.ptr += 3;\n if(!valid_inc(d, \"\")) throw err;\n if(SUPPORTED_VERSIONS_TAGGED.indexOf(res) == -1) throw (`Unsupported DTA ${res} file`);\n vers = +res;\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n /* NOTE: this assumes the byte order is 3 characters wide */\n const res = u8_to_latin1(d.raw.slice(d.ptr, d.ptr+3));\n d.ptr += 3;\n if(!valid_inc(d, \"\")) throw err;\n switch(res) {\n case \"MSF\": LE = false; break;\n case \"LSF\": LE = true; break;\n default: throw (`Unsupported byteorder ${res}`);\n }\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n nvar = (vers === 119 || vers >= 121) ? read_u32(d, LE) : read_u16(d, LE);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n if(vers == 117) nobs = nobs_lo = read_u32(d, LE);\n else {\n const lo = read_u32(d, LE), hi = read_u32(d, LE);\n nobs = LE ? ((nobs_lo = lo) + (nobs_hi = hi) * Math.pow(2,32)) : ((nobs_lo = hi) + (nobs_hi = lo) * Math.pow(2,32));\n }\n if(nobs > 1e6) console.error(`More than 1 million observations -- extra rows will be dropped`);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /*
\")) throw err;\n }\n\n /* 5.2 Map */\n {\n /* TODO: validate map? */\n if(!valid_inc(d, \"\")) throw err;\n /* 14 8-byte offsets for:\n \n \n \n \n \n \n \n \n \n \n \n \n \n EOF\n */\n d.ptr += 8 * 14;\n if(!valid_inc(d, \"\")) throw err;\n }\n\n let stride = 0;\n /* 5.3 Variable types */\n {\n if(!valid_inc(d, \"\")) throw err;\n for(var i = 0; i < nvar; ++i) {\n const type = read_u16(d, LE);\n var_types.push(type);\n if(type >= 1 && type <= 2045) stride += type;\n else switch(type) {\n case 32768: stride += 8; break;\n case 65525: stride += 0; break; // alias\n case 65526: stride += 8; break;\n case 65527: stride += 4; break;\n case 65528: stride += 4; break;\n case 65529: stride += 2; break;\n case 65530: stride += 1; break;\n default: throw (`Unsupported field type ${type}`);\n }\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.4 Variable names */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 129 : 33;\n for(let i = 0; i < nvar; ++i) {\n const name = u8_to_str(d.raw.slice(d.ptr, d.ptr + w));\n d.ptr += w;\n var_names.push(name.replace(/\\x00[\\s\\S]*/,\"\"));\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.5 Sort order of observations */\n {\n /* TODO: check sort list? */\n if(!valid_inc(d, \"\")) throw err;\n d.ptr += (2 * nvar + 2) * ((vers == 119 || vers == 121) ? 2 : 1);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.6 Display formats */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 57 : 49;\n for(let i = 0; i < nvar; ++i) {\n const name = u8_to_str(d.raw.slice(d.ptr, d.ptr + w));\n d.ptr += w;\n formats.push(name.replace(/\\x00[\\s\\S]*/,\"\"));\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n const value_label_names: string[] = [];\n /* TODO: */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 129 : 33;\n for(let i = 0; i < nvar; ++i, d.ptr += w) value_label_names[i] = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* TODO: */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 321 : 81;\n d.ptr += w * nvar;\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.9 Characteristics */\n {\n if(!valid_inc(d, \"\")) throw err;\n while(valid_inc(d, \"\")) {\n const len = read_u32(d, LE);\n d.ptr += len;\n if(!valid_inc(d, \"\")) throw err;\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n const ws: DenseWorkSheet = (_utils.aoa_to_sheet([var_names], {dense: true} as any) as DenseWorkSheet);\n\n var ptrs: Array<[number, number, Uint8Array]> = []\n /* 5.10 Data */\n {\n if(!valid_inc(d, \"\")) throw err;\n for(let R = 0; R < nobs; ++R) {\n const row: any[] = [];\n for(let C = 0; C < nvar; ++C) {\n let t = var_types[C];\n // TODO: formats, dta_12{0,1} aliases?\n if(t >= 1 && t <= 2045) {\n /* NOTE: dta_117 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t;\n } else switch(t) {\n case 65525: d.ptr += 0; break; // alias\n case 65530: row[C] = read_i8(d); break; // byte\n case 65529: row[C] = read_i16(d, LE); break; // int\n case 65528: row[C] = read_i32(d, LE); break; // long\n case 65527: row[C] = read_f32(d, LE); break; // float\n case 65526: row[C] = read_f64(d, LE); break; // double\n case 32768: {\n row[C] = \"##SheetJStrL##\";\n ptrs.push([R+1,C, d.raw.slice(d.ptr, d.ptr + 8)]);\n d.ptr += 8;\n } break;\n default: throw (`Unsupported field type ${t} for ${var_names[C]}`);\n }\n if(typeof row[C] == \"number\" && formats[C]) row[C] = format_number_dta(row[C], formats[C], t);\n }\n _utils.sheet_add_aoa(ws, [row], {origin: -1, sheetStubs: true});\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.11 StrLs */\n {\n if(!valid_inc(d, \"\")) throw err;\n\n const strl_tbl: string[][] = [];\n while(d.raw[d.ptr] == 71 /* G */) {\n if(!valid_inc(d, \"GSO\")) throw err;\n const v = read_u32(d, LE);\n let o = 0;\n if(vers == 117) o = read_u32(d, LE);\n else {\n const lo = read_u32(d, LE), hi = read_u32(d, LE);\n o = LE ? (lo + hi * Math.pow(2,32)) : (hi + lo * Math.pow(2,32));\n if(o > 1e6) console.error(`More than 1 million observations -- data will be dropped`);\n }\n const t = read_u8(d);\n const len = read_u32(d, LE);\n if(!strl_tbl[o]) strl_tbl[o] = [];\n let str = \"\";\n if(t == 129) {\n // TODO: dta_117 codepage\n str = new TextDecoder(vers >= 118 ? \"utf8\" : \"latin1\").decode(d.raw.slice(d.ptr, d.ptr + len));\n d.ptr += len;\n } else {\n str = new TextDecoder(vers >= 118 ? \"utf8\" : \"latin1\").decode(d.raw.slice(d.ptr, d.ptr + len)).replace(/\\x00$/,\"\");\n d.ptr += len;\n }\n strl_tbl[o][v] = str;\n }\n if(!valid_inc(d, \"\")) throw err;\n\n ptrs.forEach(([R,C,buf]) => {\n const dv = u8_to_dataview(buf);\n let v = 0, o = 0;\n switch(vers) {\n case 117: { // v(4) o(4)\n v = dv.getUint32(0, LE);\n o = dv.getUint32(4, LE);\n } break;\n\n case 118: case 120: { // v(2) o(6)\n v = dv.getUint16(0, LE);\n const o1 = dv.getUint16(2, LE), o2 = dv.getUint32(4, LE);\n o = LE ? o1 + o2 * 65536 : o2 + o1 * (2**32);\n } break;\n\n case 119: case 121: { // v(3) o(5)\n const v1 = dv.getUint16(0, LE), v2 = buf[2];\n v = LE ? v1 + (v2 << 16) : v2 + (v1 << 8);\n const o1 = buf[3], o2 = dv.getUint32(4, LE);\n o = LE ? o1 + o2 * 256 : o2 + o1 * (2**32);\n }\n }\n ws[\"!data\"][R][C].v = strl_tbl[o][v];\n });\n }\n\n /* 5.12 Value labels */\n {\n const w = vers >= 118 ? 129 : 33;\n if(!valid_inc(d, \"\")) throw err;\n while(valid_inc(d, \"\")) {\n let len = read_u32(d, LE);\n const labname = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n d.ptr += w;\n d.ptr += 3; // padding\n const labels: string[] = [];\n {\n const n = read_u32(d, LE);\n const txtlen = read_u32(d, LE);\n const off: number[] = [], val: number[] = [];\n for(let i = 0; i < n; ++i) off.push(read_u32(d, LE));\n for(let i = 0; i < n; ++i) val.push(read_u32(d, LE));\n const str = u8_to_str(d.raw.slice(d.ptr, d.ptr + txtlen));\n d.ptr += txtlen;\n for(let i = 0; i < n; ++i) labels[val[i]] = str.slice(off[i], str.indexOf(\"\\x00\", off[i]));\n }\n const C = value_label_names.indexOf(labname);\n if(C == -1) throw new Error(`unexpected value label |${labname}|`);\n for(let R = 1; R < ws[\"!data\"].length; ++R) {\n const cell = ws[\"!data\"][R][C];\n cell.t = \"s\"; cell.v = cell.w = labels[(cell.v as number)||0];\n }\n //d.ptr += len; // value_label_table\n if(!valid_inc(d, \"\")) throw err;\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n if(!valid_inc(d, \"\")) throw err;\n const wb = _utils.book_new();\n _utils.book_append_sheet(wb, ws, \"Sheet1\");\n wb.bookType = \"dta\" as any;\n return wb;\n}\n\nfunction parse_legacy(raw: Uint8Array): WorkBook {\n let vers: number = raw[0];\n if(SUPPORTED_VERSIONS_LEGACY.indexOf(vers) == -1) throw new Error(\"Not a DTA file\");\n\n const d: Payload = {\n ptr: 1,\n raw,\n dv: u8_to_dataview(raw)\n };\n\n let LE: boolean = true;\n let nvar: number = 0, nobs: number = 0;\n let label: string = \"\", timestamp: string = \"\";\n const var_types: number[] = [];\n const var_names: string[] = [];\n const formats: string[] = [];\n\n /* 5.1 Header */\n {\n const byteorder = read_u8(d);\n switch(byteorder) {\n case 1: LE = false; break;\n case 2: LE = true; break;\n default: throw (`DTA ${vers} Unexpected byteorder ${byteorder}`);\n }\n\n let byte = read_u8(d);\n if(byte != 1) throw (`DTA ${vers} Unexpected filetype ${byte}`);\n // NOTE: dta_105 technically supports filetype 2\n\n d.ptr++; // \"unused\"\n nvar = read_u16(d, LE);\n nobs = read_u32(d, LE);\n d.ptr += (vers >= 108 ? 81 : vers >= 103 ? 32 : 30); // TODO: data_label\n if(vers >= 105) d.ptr += 18; // TODO: time_stamp\n }\n\n /* 5.2 Descriptors */\n const value_label_names: string[] = [];\n {\n let C = 0;\n\n // typlist\n for(C = 0; C < nvar; ++C) var_types.push(read_u8(d));\n\n // varlist\n const w = vers >= 110 ? 33 : 9;\n for(C = 0; C < nvar; ++C) {\n var_names.push(u8_to_str(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00[\\s\\S]*$/,\"\"));\n d.ptr += w;\n }\n\n // srtlist\n d.ptr += 2*(nvar + 1);\n\n // fmtlist\n const fw = (vers >= 114 ? 49 : vers >= 105 ? 12 : 7);\n for(C = 0; C < nvar; ++C) {\n formats.push(u8_to_str(d.raw.slice(d.ptr, d.ptr + fw)).replace(/\\x00[\\s\\S]*$/,\"\"));\n d.ptr += fw;\n }\n // lbllist\n const lw = vers >= 110 ? 33 : 9;\n for(let i = 0; i < nvar; ++i, d.ptr += lw) value_label_names[i] = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + lw)).replace(/\\x00.*$/,\"\");\n }\n\n /* 5.3 Variable labels */\n // TODO: should these names be used in the worksheet?\n d.ptr += (vers >= 106 ? 81 : 32) * nvar;\n\n /* 5.4 Expansion fields */\n if(vers >= 105) while(d.ptr < d.raw.length) {\n const dt = read_u8(d), len = (vers >= 110 ? read_u32 : read_u16)(d, LE);\n if(dt == 0 && len == 0) break;\n d.ptr += len;\n }\n\n const ws: DenseWorkSheet = (_utils.aoa_to_sheet([var_names], {dense: true} as any) as DenseWorkSheet);\n\n /* 5.5 Data */\n for(let R = 0; R < nobs; ++R) {\n const row: any[] = [];\n for(let C = 0; C < nvar; ++C) {\n let t = var_types[C];\n // TODO: data type processing\n if((vers == 111 || vers >= 113) && t >= 1 && t <= 244) {\n /* NOTE: dta_117 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t;\n } else if((vers == 112 || vers <= 110) && t >= 0x80) {\n /* NOTE: dta_105 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t - 0x7F));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t - 0x7F;\n } else switch(t) {\n case 251: case 0x62: row[C] = read_i8(d); break; // byte\n case 252: case 0x69: row[C] = read_i16(d, LE); break; // int\n case 253: case 0x6c: row[C] = read_i32(d, LE); break; // long\n case 254: case 0x66: row[C] = read_f32(d, LE); break; // float\n case 255: case 0x64: row[C] = read_f64(d, LE); break; // double\n default: throw (`Unsupported field type ${t} for ${var_names[C]}`);\n }\n if(typeof row[C] == \"number\" && formats[C]) row[C] = format_number_dta(row[C], formats[C], t);\n }\n _utils.sheet_add_aoa(ws, [row], {origin: -1, sheetStubs: true});\n }\n\n /* 5.6 Value labels */\n // TODO: < 115\n if(vers >= 115) while(d.ptr < d.raw.length) {\n const w = 33;\n let len = read_u32(d, LE);\n const labname = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n d.ptr += w;\n d.ptr += 3; // padding\n const labels: string[] = [];\n {\n const n = read_u32(d, LE);\n const txtlen = read_u32(d, LE);\n const off: number[] = [], val: number[] = [];\n for(let i = 0; i < n; ++i) off.push(read_u32(d, LE));\n for(let i = 0; i < n; ++i) val.push(read_u32(d, LE));\n const str = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + txtlen));\n d.ptr += txtlen;\n for(let i = 0; i < n; ++i) labels[val[i]] = str.slice(off[i], str.indexOf(\"\\x00\", off[i]));\n }\n const C = value_label_names.indexOf(labname);\n if(C == -1) throw new Error(`unexpected value label |${labname}|`);\n for(let R = 1; R < ws[\"!data\"].length; ++R) {\n const cell = ws[\"!data\"][R][C];\n cell.t = \"s\"; cell.v = cell.w = labels[(cell.v as number)||0];\n }\n\n }\n\n const wb: WorkBook = _utils.book_new();\n _utils.book_append_sheet(wb, ws, \"Sheet1\");\n wb.bookType = \"dta\" as any;\n return wb;\n}\n\n/** Parse DTA file\n *\n * NOTE: In NodeJS, `Buffer` extends `Uint8Array`\n *\n * @param {Uint8Array} data File data\n */\nfunction parse(data: Uint8Array): WorkBook {\n if(data[0] >= 102 && data[0] <= 115) return parse_legacy(data);\n if(data[0] === 60) return parse_tagged(data);\n throw new Error(\"Not a DTA file\");\n}\n"], + "mappings": "4hBAAA,8DAGA,GAAM,GAAU,QAEZ,EAaJ,YAAmB,EAAkB,CACnC,EAAS,EAGX,WAAmB,EAAwB,CACzC,MAAO,IAAI,eAAc,OAAO,GAIlC,WAAsB,EAAwB,CAC5C,MAAO,IAAI,aAAY,UAAU,OAAO,GAK1C,WAA2B,EAAe,EAAgB,EAAuB,CAC/E,GAAG,EAAQ,EAAG,CAAE,GAAM,GAAM,EAAkB,CAAC,EAAO,EAAQ,GAAI,SAAI,EAAI,IAAM,EAAI,EAAU,EAC9F,GAAM,GAAgB,CAAE,EAAG,IAAK,EAAG,GAEnC,OAAO,OACA,SAAU,QAAW,OAAO,EAAS,QAAS,UAC9C,SAAU,SAAW,OAAO,EAAS,QAAS,UAC9C,SAAU,SAAW,OAAO,EAAS,SAAU,UAC/C,SAAU,SAAW,OAAO,EAAS,Q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AI,EAAS,EAAG,GAChB,EAAS,EAAS,EAAG,GACrB,EAAgB,GAAI,EAAgB,GAC1C,OAAQ,GAAI,EAAG,EAAI,EAAG,EAAE,EAAG,EAAI,KAAK,EAAS,EAAG,IAChD,OAAQ,GAAI,EAAG,EAAI,EAAG,EAAE,EAAG,EAAI,KAAK,EAAS,EAAG,IAChD,GAAM,GAAM,EAAa,EAAE,IAAI,MAAM,EAAE,IAAK,EAAE,IAAM,IACpD,EAAE,KAAO,EACT,OAAQ,GAAI,EAAG,EAAI,EAAG,EAAE,EAAG,EAAO,EAAI,IAAM,EAAI,MAAM,EAAI,GAAI,EAAI,QAAQ,KAAQ,EAAI,KAExF,GAAM,GAAI,EAAkB,QAAQ,GACpC,GAAG,GAAK,GAAI,KAAM,IAAI,OAAM,2BAA2B,MACvD,OAAQ,GAAI,EAAG,EAAI,EAAG,SAAS,OAAQ,EAAE,EAAG,CAC1C,GAAM,GAAO,EAAG,SAAS,GAAG,GAC5B,EAAK,EAAI,IAAK,EAAK,EAAI,EAAK,EAAI,EAAQ,EAAK,GAAc,IAK/D,GAAM,GAAe,EAAO,WAC5B,SAAO,kBAAkB,EAAI,EAAI,UACjC,EAAG,SAAW,MACP,EAST,YAAe,EAA4B,CACzC,GAAG,EAAK,IAAM,KAAO,EAAK,IAAM,IAAK,MAAO,IAAa,GACzD,GAAG,EAAK,KAAO,GAAI,MAAO,IAAa,GACvC,KAAM,IAAI,OAAM", "names": [] } diff --git a/packages/dta/dist/dta.mjs b/packages/dta/dist/dta.mjs new file mode 100644 index 0000000..c6644d3 --- /dev/null +++ b/packages/dta/dist/dta.mjs @@ -0,0 +1,2 @@ +var z="0.0.2",$;function H(r){$=r}function U(r){return new TextDecoder().decode(r)}function P(r){return new TextDecoder("latin1").decode(r)}function N(r,t,e){if(r<0){let h=N(-r,t,e);return h.w="-"+h.w,h}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 h=+(t.match(/%(\d+)/)||[])[1]||8,v=0;r<1&&++v,r<.1&&++v,r<.01&&++v,r<.001&&++v;let D=r.toExponential(),T=D.indexOf("e")==-1?0:+D.slice(D.indexOf("e")+1),y=h-2-T;y<0&&(y=0);var o=t.match(/%\d+\.(\d+)/);o&&+o[1]&&(y=+o[1]),s.w=(Math.round(r*10**y)/10**y).toFixed(y).replace(/^([-]?)0\./,"$1."),s.w=s.w.slice(0,h+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 L(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 B(r,t){r.ptr+=8;let e=r.dv.getFloat64(r.ptr-8,t);return e>8988e304?null:e}function V(r,t){r.ptr+=4;let e=r.dv.getFloat32(r.ptr-4,t);return e>1701e35?null:e}function b(r,t){return r.ptr+=4,r.dv.getUint32(r.ptr-4,t)}function G(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 I(r,t){r.ptr+=2;let e=r.dv.getInt16(r.ptr-2,t);return e>32740?null:e}function W(r){return r.raw[r.ptr++]}function j(r){let t=r.raw[r.ptr++];return t=t<128?t:t-256,t>100?null:t}var K=["117","118","119","120","121"],J=[102,103,104,105,108,110,111,112,113,114,115];function Y(r){let t="Not a DTA file",e={ptr:0,raw:r,dv:L(r)},s=118,o=!0,h=0,v=0,D=0,T=0,y="",C="",M=[],O=[],E=[];if(!n(e,""))throw t;{if(!n(e,"
"))throw t;{if(!n(e,""))throw t;let a=P(e.raw.slice(e.ptr,e.ptr+3));if(e.ptr+=3,!n(e,""))throw t;if(K.indexOf(a)==-1)throw`Unsupported DTA ${a} file`;s=+a}{if(!n(e,""))throw t;let a=P(e.raw.slice(e.ptr,e.ptr+3));if(e.ptr+=3,!n(e,""))throw t;switch(a){case"MSF":o=!1;break;case"LSF":o=!0;break;default:throw`Unsupported byteorder ${a}`}}if(!n(e,"")||(h=s===119||s>=121?b(e,o):F(e,o),!n(e,"")))throw t;{if(!n(e,""))throw t;if(s==117)v=D=b(e,o);else{let a=b(e,o),l=b(e,o);v=o?(D=a)+(T=l)*Math.pow(2,32):(D=l)+(T=a)*Math.pow(2,32)}if(v>1e6&&console.error("More than 1 million observations -- extra rows will be dropped"),!n(e,""))throw t}{if(!n(e,""))throw t}{if(!n(e,""))throw t;let a=W(e);if(C=P(e.raw.slice(e.ptr,e.ptr+a)),e.ptr+=a,!n(e,""))throw t}if(!n(e,"
"))throw t}if(!n(e,"")||(e.ptr+=8*14,!n(e,"")))throw t;let f=0;{if(!n(e,""))throw t;for(var w=0;w=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,""))throw t}{if(!n(e,""))throw t;let a=s>=118?129:33;for(let l=0;l"))throw t}if(!n(e,"")||(e.ptr+=(2*h+2)*(s==119||s==121?2:1),!n(e,"")))throw t;{if(!n(e,""))throw t;let a=s>=118?57:49;for(let l=0;l"))throw t}let p=[];{if(!n(e,""))throw t;let a=s>=118?129:33;for(let l=0;l"))throw t}{if(!n(e,""))throw t;let a=s>=118?321:81;if(e.ptr+=a*h,!n(e,""))throw t}{if(!n(e,""))throw t;for(;n(e,"");){let a=b(e,o);if(e.ptr+=a,!n(e,""))throw t}if(!n(e,""))throw t}let u=$.aoa_to_sheet([O],{dense:!0});var _=[];{if(!n(e,""))throw t;for(let a=0;a=1&&d<=2045){let c=U(e.raw.slice(e.ptr,e.ptr+d));c=c.replace(/\x00[\s\S]*/,""),l[i]=c,e.ptr+=d}else switch(d){case 65525:e.ptr+=0;break;case 65530:l[i]=j(e);break;case 65529:l[i]=I(e,o);break;case 65528:l[i]=G(e,o);break;case 65527:l[i]=V(e,o);break;case 65526:l[i]=B(e,o);break;case 32768:l[i]="##SheetJStrL##",_.push([a+1,i,e.raw.slice(e.ptr,e.ptr+8)]),e.ptr+=8;break;default:throw`Unsupported field type ${d} for ${O[i]}`}typeof l[i]=="number"&&E[i]&&(l[i]=N(l[i],E[i],d))}$.sheet_add_aoa(u,[l],{origin:-1,sheetStubs:!0})}if(!n(e,""))throw t}{if(!n(e,""))throw t;let a=[];for(;e.raw[e.ptr]==71;){if(!n(e,"GSO"))throw t;let l=b(e,o),i=0;if(s==117)i=b(e,o);else{let x=b(e,o),g=b(e,o);i=o?x+g*Math.pow(2,32):g+x*Math.pow(2,32),i>1e6&&console.error("More than 1 million observations -- data will be dropped")}let d=W(e),c=b(e,o);a[i]||(a[i]=[]);let k="";d==129?(k=new TextDecoder(s>=118?"utf8":"latin1").decode(e.raw.slice(e.ptr,e.ptr+c)),e.ptr+=c):(k=new TextDecoder(s>=118?"utf8":"latin1").decode(e.raw.slice(e.ptr,e.ptr+c)).replace(/\x00$/,""),e.ptr+=c),a[i][l]=k}if(!n(e,""))throw t;_.forEach(([l,i,d])=>{let c=L(d),k=0,x=0;switch(s){case 117:k=c.getUint32(0,o),x=c.getUint32(4,o);break;case 118:case 120:{k=c.getUint16(0,o);let g=c.getUint16(2,o),A=c.getUint32(4,o);x=o?g+A*65536:A+g*2**32}break;case 119:case 121:{let g=c.getUint16(0,o),A=d[2];k=o?g+(A<<16):A+(g<<8);let R=d[3],m=c.getUint32(4,o);x=o?R+m*256:m+R*2**32}}u["!data"][l][i].v=a[x][k]})}{let a=s>=118?129:33;if(!n(e,""))throw t;for(;n(e,"");){let l=b(e,o),i=P(e.raw.slice(e.ptr,e.ptr+a)).replace(/\x00.*$/,"");e.ptr+=a,e.ptr+=3;let d=[];{let k=b(e,o),x=b(e,o),g=[],A=[];for(let m=0;m"))throw t}if(!n(e,""))throw t}if(!n(e,"
"))throw t;let S=$.book_new();return $.book_append_sheet(S,u,"Sheet1"),S.bookType="dta",S}function q(r){let t=r[0];if(J.indexOf(t)==-1)throw new Error("Not a DTA file");let e={ptr:1,raw:r,dv:L(r)},s=!0,o=0,h=0,v="",D="",T=[],y=[],C=[];{let f=W(e);switch(f){case 1:s=!1;break;case 2:s=!0;break;default:throw`DTA ${t} Unexpected byteorder ${f}`}let w=W(e);if(w!=1)throw`DTA ${t} Unexpected filetype ${w}`;e.ptr++,o=F(e,s),h=b(e,s),e.ptr+=t>=108?81:t>=103?32:30,t>=105&&(e.ptr+=18)}let M=[];{let f=0;for(f=0;f=110?33:9;for(f=0;f=114?49:t>=105?12:7;for(f=0;f=110?33:9;for(let _=0;_=106?81:32)*o,t>=105)for(;e.ptr=110?b:F)(e,s);if(f==0&&w==0)break;e.ptr+=w}let O=$.aoa_to_sheet([y],{dense:!0});for(let f=0;f=113)&&u>=1&&u<=244){let _=U(e.raw.slice(e.ptr,e.ptr+u));_=_.replace(/\x00[\s\S]*/,""),w[p]=_,e.ptr+=u}else if((t==112||t<=110)&&u>=128){let _=U(e.raw.slice(e.ptr,e.ptr+u-127));_=_.replace(/\x00[\s\S]*/,""),w[p]=_,e.ptr+=u-127}else switch(u){case 251:case 98:w[p]=j(e);break;case 252:case 105:w[p]=I(e,s);break;case 253:case 108:w[p]=G(e,s);break;case 254:case 102:w[p]=V(e,s);break;case 255:case 100:w[p]=B(e,s);break;default:throw`Unsupported field type ${u} for ${y[p]}`}typeof w[p]=="number"&&C[p]&&(w[p]=N(w[p],C[p],u))}$.sheet_add_aoa(O,[w],{origin:-1,sheetStubs:!0})}if(t>=115)for(;e.ptr=102&&r[0]<=115)return q(r);if(r[0]===60)return Y(r);throw new Error("Not a DTA file")}export{Q as parse,H as set_utils,z as version}; +//# sourceMappingURL=dta.mjs.map diff --git a/packages/dta/dist/dta.mjs.map b/packages/dta/dist/dta.mjs.map new file mode 100644 index 0000000..4ee4165 --- /dev/null +++ b/packages/dta/dist/dta.mjs.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["../dta.ts"], + "sourcesContent": ["import { CellObject, DenseWorkSheet, WorkBook, type utils } from 'xlsx';\nexport { parse, set_utils, version };\n\nconst version = \"0.0.2\";\n\nlet _utils: typeof utils;\n/** Set internal instance of `utils`\n *\n * Usage:\n *\n * ```js\n * const XLSX = require(\"xlsx\");\n * const DTA = require(\"dta\");\n * DTA.set_utils(XLSX.utils);\n * ```\n *\n * @param utils utils object\n */\nfunction set_utils(utils: any): void {\n _utils = utils;\n}\n\nfunction u8_to_str(u8: Uint8Array): string {\n return new TextDecoder().decode(u8);\n}\n\n/* sadly the web zealots decided to abandon binary strings */\nfunction u8_to_latin1(u8: Uint8Array): string {\n return new TextDecoder(\"latin1\").decode(u8);\n}\n\n\n/* TODO: generalize and map to SSF */\nfunction format_number_dta(value: number, format: string, t: number): CellObject {\n if(value < 0) { const res = format_number_dta(-value, format, t); res.w = \"-\" + res.w; return res; }\n const o: CellObject = { t: \"n\", v: value };\n /* NOTE: The Stata CSV exporter appears to ignore the column formats, instead using these defaults */\n switch(t) {\n case 251: case 0x62: case 65530: format = \"%8.0g\"; break; // byte\n case 252: case 0x69: case 65529: format = \"%8.0g\"; break; // int\n case 253: case 0x6c: case 65528: format = \"%12.0g\"; break; // long\n case 254: case 0x66: case 65527: format = \"%9.0g\"; break; // float\n case 255: case 0x64: case 65526: format = \"%10.0g\"; break; // double\n default: throw t;\n }\n try {\n let w = +((format.match(/%(\\d+)/)||[])[1]) || 8;\n let k = 0;\n if(value < 1) ++k;\n if(value < 0.1) ++k;\n if(value < 0.01) ++k;\n if(value < 0.001) ++k;\n const e = value.toExponential();\n const exp = e.indexOf(\"e\") == -1 ? 0 : +e.slice(e.indexOf(\"e\")+1);\n let h = w - 2 - exp;\n if(h < 0) h = 0;\n var m = format.match(/%\\d+\\.(\\d+)/);\n if(m && +m[1]) h = +m[1];\n o.w = (Math.round(value * 10**(h))/10**(h)).toFixed(h).replace(/^([-]?)0\\./,\"$1.\");\n o.w = o.w.slice(0, w + k);\n if(o.w.indexOf(\".\") > -1) o.w = o.w.replace(/0+$/,\"\");\n o.w = o.w.replace(/\\.$/,\"\");\n if(o.w == \"\") o.w = \"0\";\n } catch(e) {}\n return o;\n}\n\ninterface Payload {\n /** Offset */\n ptr: number;\n\n /** Raw data */\n raw: Uint8Array;\n\n /** DataView */\n dv: DataView;\n}\n\nfunction u8_to_dataview(array: Uint8Array): DataView { return new DataView(array.buffer, array.byteOffset, array.byteLength); }\nfunction valid_inc(p: Payload, n: string): boolean {\n if(u8_to_str(p.raw.slice(p.ptr, p.ptr + n.length)) != n) return false;\n p.ptr += n.length;\n return true;\n}\n\nfunction read_f64(p: Payload, LE: boolean): number | null {\n p.ptr += 8;\n const d = p.dv.getFloat64(p.ptr - 8, LE);\n return d > 8.988e+307 ? null : d;\n}\nfunction read_f32(p: Payload, LE: boolean): number | null {\n p.ptr += 4;\n const d = p.dv.getFloat32(p.ptr - 4, LE);\n return d > 1.701e+38 ? null : d;\n}\nfunction read_u32(p: Payload, LE: boolean) {\n p.ptr += 4;\n return p.dv.getUint32(p.ptr - 4, LE);\n}\nfunction read_i32(p: Payload, LE: boolean): number | null {\n p.ptr += 4;\n const u = p.dv.getInt32(p.ptr - 4, LE);\n return u > 0x7fffffe4 ? null : u;\n}\nfunction read_u16(p: Payload, LE: boolean) {\n p.ptr += 2;\n return p.dv.getUint16(p.ptr - 2, LE);\n}\nfunction read_i16(p: Payload, LE: boolean): number | null {\n p.ptr += 2;\n const u = p.dv.getInt16(p.ptr - 2, LE);\n return u > 32740 ? null : u;\n}\nfunction read_u8(p: Payload) {\n return p.raw[p.ptr++];\n}\nfunction read_i8(p: Payload): number | null {\n let u = p.raw[p.ptr++];\n u = u < 128 ? u : u - 256;\n return u > 100 ? null : u;\n}\n\n/* the annotations are from `dtaversion` */\nconst SUPPORTED_VERSIONS_TAGGED = [\n \"117\", // stata 13\n \"118\", // stata 14-18\n \"119\", // stata 15-18 (> 32767 variables)\n \"120\", // stata 18 (<= 32767, with aliases)\n \"121\", // stata 18 (> 32767, with aliases)\n];\nconst SUPPORTED_VERSIONS_LEGACY = [\n 102, // stata 1\n 103, // stata 2/3\n 104, // stata 4\n 105, // stata 5\n 108, // stata 6\n 110, // stata 7\n 111, // stata 7\n 112, // stata 8/9\n 113, // stata 8/9\n 114, // stata 10/11\n 115, // stata 12\n];\n\nfunction parse_tagged(raw: Uint8Array): WorkBook {\n const err = (\"Not a DTA file\");\n\n const d: Payload = {\n ptr: 0,\n raw,\n dv: u8_to_dataview(raw)\n };\n\n let vers: number = 118;\n let LE: boolean = true;\n let nvar: number = 0, nobs: number = 0, nobs_lo = 0, nobs_hi = 0;\n let label: string = \"\", timestamp: string = \"\";\n const var_types: number[] = [];\n const var_names: string[] = [];\n const formats: string[] = [];\n\n /* 5. Dataset format definition */\n if(!valid_inc(d, \"\")) throw err;\n\n /* 5.1 Header
*/\n {\n if(!valid_inc(d, \"
\")) throw err;\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n /* NOTE: this assumes the version is 3 characters wide */\n const res = u8_to_latin1(d.raw.slice(d.ptr, d.ptr+3));\n d.ptr += 3;\n if(!valid_inc(d, \"\")) throw err;\n if(SUPPORTED_VERSIONS_TAGGED.indexOf(res) == -1) throw (`Unsupported DTA ${res} file`);\n vers = +res;\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n /* NOTE: this assumes the byte order is 3 characters wide */\n const res = u8_to_latin1(d.raw.slice(d.ptr, d.ptr+3));\n d.ptr += 3;\n if(!valid_inc(d, \"\")) throw err;\n switch(res) {\n case \"MSF\": LE = false; break;\n case \"LSF\": LE = true; break;\n default: throw (`Unsupported byteorder ${res}`);\n }\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n nvar = (vers === 119 || vers >= 121) ? read_u32(d, LE) : read_u16(d, LE);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* */\n {\n if(!valid_inc(d, \"\")) throw err;\n if(vers == 117) nobs = nobs_lo = read_u32(d, LE);\n else {\n const lo = read_u32(d, LE), hi = read_u32(d, LE);\n nobs = LE ? ((nobs_lo = lo) + (nobs_hi = hi) * Math.pow(2,32)) : ((nobs_lo = hi) + (nobs_hi = lo) * Math.pow(2,32));\n }\n if(nobs > 1e6) console.error(`More than 1 million observations -- extra rows will be dropped`);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /*
\")) throw err;\n }\n\n /* 5.2 Map */\n {\n /* TODO: validate map? */\n if(!valid_inc(d, \"\")) throw err;\n /* 14 8-byte offsets for:\n \n \n \n \n \n \n \n \n \n \n \n \n \n EOF\n */\n d.ptr += 8 * 14;\n if(!valid_inc(d, \"\")) throw err;\n }\n\n let stride = 0;\n /* 5.3 Variable types */\n {\n if(!valid_inc(d, \"\")) throw err;\n for(var i = 0; i < nvar; ++i) {\n const type = read_u16(d, LE);\n var_types.push(type);\n if(type >= 1 && type <= 2045) stride += type;\n else switch(type) {\n case 32768: stride += 8; break;\n case 65525: stride += 0; break; // alias\n case 65526: stride += 8; break;\n case 65527: stride += 4; break;\n case 65528: stride += 4; break;\n case 65529: stride += 2; break;\n case 65530: stride += 1; break;\n default: throw (`Unsupported field type ${type}`);\n }\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.4 Variable names */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 129 : 33;\n for(let i = 0; i < nvar; ++i) {\n const name = u8_to_str(d.raw.slice(d.ptr, d.ptr + w));\n d.ptr += w;\n var_names.push(name.replace(/\\x00[\\s\\S]*/,\"\"));\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.5 Sort order of observations */\n {\n /* TODO: check sort list? */\n if(!valid_inc(d, \"\")) throw err;\n d.ptr += (2 * nvar + 2) * ((vers == 119 || vers == 121) ? 2 : 1);\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.6 Display formats */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 57 : 49;\n for(let i = 0; i < nvar; ++i) {\n const name = u8_to_str(d.raw.slice(d.ptr, d.ptr + w));\n d.ptr += w;\n formats.push(name.replace(/\\x00[\\s\\S]*/,\"\"));\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n const value_label_names: string[] = [];\n /* TODO: */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 129 : 33;\n for(let i = 0; i < nvar; ++i, d.ptr += w) value_label_names[i] = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* TODO: */\n {\n if(!valid_inc(d, \"\")) throw err;\n const w = vers >= 118 ? 321 : 81;\n d.ptr += w * nvar;\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.9 Characteristics */\n {\n if(!valid_inc(d, \"\")) throw err;\n while(valid_inc(d, \"\")) {\n const len = read_u32(d, LE);\n d.ptr += len;\n if(!valid_inc(d, \"\")) throw err;\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n const ws: DenseWorkSheet = (_utils.aoa_to_sheet([var_names], {dense: true} as any) as DenseWorkSheet);\n\n var ptrs: Array<[number, number, Uint8Array]> = []\n /* 5.10 Data */\n {\n if(!valid_inc(d, \"\")) throw err;\n for(let R = 0; R < nobs; ++R) {\n const row: any[] = [];\n for(let C = 0; C < nvar; ++C) {\n let t = var_types[C];\n // TODO: formats, dta_12{0,1} aliases?\n if(t >= 1 && t <= 2045) {\n /* NOTE: dta_117 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t;\n } else switch(t) {\n case 65525: d.ptr += 0; break; // alias\n case 65530: row[C] = read_i8(d); break; // byte\n case 65529: row[C] = read_i16(d, LE); break; // int\n case 65528: row[C] = read_i32(d, LE); break; // long\n case 65527: row[C] = read_f32(d, LE); break; // float\n case 65526: row[C] = read_f64(d, LE); break; // double\n case 32768: {\n row[C] = \"##SheetJStrL##\";\n ptrs.push([R+1,C, d.raw.slice(d.ptr, d.ptr + 8)]);\n d.ptr += 8;\n } break;\n default: throw (`Unsupported field type ${t} for ${var_names[C]}`);\n }\n if(typeof row[C] == \"number\" && formats[C]) row[C] = format_number_dta(row[C], formats[C], t);\n }\n _utils.sheet_add_aoa(ws, [row], {origin: -1, sheetStubs: true});\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n /* 5.11 StrLs */\n {\n if(!valid_inc(d, \"\")) throw err;\n\n const strl_tbl: string[][] = [];\n while(d.raw[d.ptr] == 71 /* G */) {\n if(!valid_inc(d, \"GSO\")) throw err;\n const v = read_u32(d, LE);\n let o = 0;\n if(vers == 117) o = read_u32(d, LE);\n else {\n const lo = read_u32(d, LE), hi = read_u32(d, LE);\n o = LE ? (lo + hi * Math.pow(2,32)) : (hi + lo * Math.pow(2,32));\n if(o > 1e6) console.error(`More than 1 million observations -- data will be dropped`);\n }\n const t = read_u8(d);\n const len = read_u32(d, LE);\n if(!strl_tbl[o]) strl_tbl[o] = [];\n let str = \"\";\n if(t == 129) {\n // TODO: dta_117 codepage\n str = new TextDecoder(vers >= 118 ? \"utf8\" : \"latin1\").decode(d.raw.slice(d.ptr, d.ptr + len));\n d.ptr += len;\n } else {\n str = new TextDecoder(vers >= 118 ? \"utf8\" : \"latin1\").decode(d.raw.slice(d.ptr, d.ptr + len)).replace(/\\x00$/,\"\");\n d.ptr += len;\n }\n strl_tbl[o][v] = str;\n }\n if(!valid_inc(d, \"\")) throw err;\n\n ptrs.forEach(([R,C,buf]) => {\n const dv = u8_to_dataview(buf);\n let v = 0, o = 0;\n switch(vers) {\n case 117: { // v(4) o(4)\n v = dv.getUint32(0, LE);\n o = dv.getUint32(4, LE);\n } break;\n\n case 118: case 120: { // v(2) o(6)\n v = dv.getUint16(0, LE);\n const o1 = dv.getUint16(2, LE), o2 = dv.getUint32(4, LE);\n o = LE ? o1 + o2 * 65536 : o2 + o1 * (2**32);\n } break;\n\n case 119: case 121: { // v(3) o(5)\n const v1 = dv.getUint16(0, LE), v2 = buf[2];\n v = LE ? v1 + (v2 << 16) : v2 + (v1 << 8);\n const o1 = buf[3], o2 = dv.getUint32(4, LE);\n o = LE ? o1 + o2 * 256 : o2 + o1 * (2**32);\n }\n }\n ws[\"!data\"][R][C].v = strl_tbl[o][v];\n });\n }\n\n /* 5.12 Value labels */\n {\n const w = vers >= 118 ? 129 : 33;\n if(!valid_inc(d, \"\")) throw err;\n while(valid_inc(d, \"\")) {\n let len = read_u32(d, LE);\n const labname = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n d.ptr += w;\n d.ptr += 3; // padding\n const labels: string[] = [];\n {\n const n = read_u32(d, LE);\n const txtlen = read_u32(d, LE);\n const off: number[] = [], val: number[] = [];\n for(let i = 0; i < n; ++i) off.push(read_u32(d, LE));\n for(let i = 0; i < n; ++i) val.push(read_u32(d, LE));\n const str = u8_to_str(d.raw.slice(d.ptr, d.ptr + txtlen));\n d.ptr += txtlen;\n for(let i = 0; i < n; ++i) labels[val[i]] = str.slice(off[i], str.indexOf(\"\\x00\", off[i]));\n }\n const C = value_label_names.indexOf(labname);\n if(C == -1) throw new Error(`unexpected value label |${labname}|`);\n for(let R = 1; R < ws[\"!data\"].length; ++R) {\n const cell = ws[\"!data\"][R][C];\n cell.t = \"s\"; cell.v = cell.w = labels[(cell.v as number)||0];\n }\n //d.ptr += len; // value_label_table\n if(!valid_inc(d, \"\")) throw err;\n }\n if(!valid_inc(d, \"\")) throw err;\n }\n\n if(!valid_inc(d, \"\")) throw err;\n const wb = _utils.book_new();\n _utils.book_append_sheet(wb, ws, \"Sheet1\");\n wb.bookType = \"dta\" as any;\n return wb;\n}\n\nfunction parse_legacy(raw: Uint8Array): WorkBook {\n let vers: number = raw[0];\n if(SUPPORTED_VERSIONS_LEGACY.indexOf(vers) == -1) throw new Error(\"Not a DTA file\");\n\n const d: Payload = {\n ptr: 1,\n raw,\n dv: u8_to_dataview(raw)\n };\n\n let LE: boolean = true;\n let nvar: number = 0, nobs: number = 0;\n let label: string = \"\", timestamp: string = \"\";\n const var_types: number[] = [];\n const var_names: string[] = [];\n const formats: string[] = [];\n\n /* 5.1 Header */\n {\n const byteorder = read_u8(d);\n switch(byteorder) {\n case 1: LE = false; break;\n case 2: LE = true; break;\n default: throw (`DTA ${vers} Unexpected byteorder ${byteorder}`);\n }\n\n let byte = read_u8(d);\n if(byte != 1) throw (`DTA ${vers} Unexpected filetype ${byte}`);\n // NOTE: dta_105 technically supports filetype 2\n\n d.ptr++; // \"unused\"\n nvar = read_u16(d, LE);\n nobs = read_u32(d, LE);\n d.ptr += (vers >= 108 ? 81 : vers >= 103 ? 32 : 30); // TODO: data_label\n if(vers >= 105) d.ptr += 18; // TODO: time_stamp\n }\n\n /* 5.2 Descriptors */\n const value_label_names: string[] = [];\n {\n let C = 0;\n\n // typlist\n for(C = 0; C < nvar; ++C) var_types.push(read_u8(d));\n\n // varlist\n const w = vers >= 110 ? 33 : 9;\n for(C = 0; C < nvar; ++C) {\n var_names.push(u8_to_str(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00[\\s\\S]*$/,\"\"));\n d.ptr += w;\n }\n\n // srtlist\n d.ptr += 2*(nvar + 1);\n\n // fmtlist\n const fw = (vers >= 114 ? 49 : vers >= 105 ? 12 : 7);\n for(C = 0; C < nvar; ++C) {\n formats.push(u8_to_str(d.raw.slice(d.ptr, d.ptr + fw)).replace(/\\x00[\\s\\S]*$/,\"\"));\n d.ptr += fw;\n }\n // lbllist\n const lw = vers >= 110 ? 33 : 9;\n for(let i = 0; i < nvar; ++i, d.ptr += lw) value_label_names[i] = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + lw)).replace(/\\x00.*$/,\"\");\n }\n\n /* 5.3 Variable labels */\n // TODO: should these names be used in the worksheet?\n d.ptr += (vers >= 106 ? 81 : 32) * nvar;\n\n /* 5.4 Expansion fields */\n if(vers >= 105) while(d.ptr < d.raw.length) {\n const dt = read_u8(d), len = (vers >= 110 ? read_u32 : read_u16)(d, LE);\n if(dt == 0 && len == 0) break;\n d.ptr += len;\n }\n\n const ws: DenseWorkSheet = (_utils.aoa_to_sheet([var_names], {dense: true} as any) as DenseWorkSheet);\n\n /* 5.5 Data */\n for(let R = 0; R < nobs; ++R) {\n const row: any[] = [];\n for(let C = 0; C < nvar; ++C) {\n let t = var_types[C];\n // TODO: data type processing\n if((vers == 111 || vers >= 113) && t >= 1 && t <= 244) {\n /* NOTE: dta_117 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t;\n } else if((vers == 112 || vers <= 110) && t >= 0x80) {\n /* NOTE: dta_105 restricts strf to ASCII */\n let s = u8_to_str(d.raw.slice(d.ptr, d.ptr + t - 0x7F));\n s = s.replace(/\\x00[\\s\\S]*/,\"\");\n row[C] = s;\n d.ptr += t - 0x7F;\n } else switch(t) {\n case 251: case 0x62: row[C] = read_i8(d); break; // byte\n case 252: case 0x69: row[C] = read_i16(d, LE); break; // int\n case 253: case 0x6c: row[C] = read_i32(d, LE); break; // long\n case 254: case 0x66: row[C] = read_f32(d, LE); break; // float\n case 255: case 0x64: row[C] = read_f64(d, LE); break; // double\n default: throw (`Unsupported field type ${t} for ${var_names[C]}`);\n }\n if(typeof row[C] == \"number\" && formats[C]) row[C] = format_number_dta(row[C], formats[C], t);\n }\n _utils.sheet_add_aoa(ws, [row], {origin: -1, sheetStubs: true});\n }\n\n /* 5.6 Value labels */\n // TODO: < 115\n if(vers >= 115) while(d.ptr < d.raw.length) {\n const w = 33;\n let len = read_u32(d, LE);\n const labname = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + w)).replace(/\\x00.*$/,\"\");\n d.ptr += w;\n d.ptr += 3; // padding\n const labels: string[] = [];\n {\n const n = read_u32(d, LE);\n const txtlen = read_u32(d, LE);\n const off: number[] = [], val: number[] = [];\n for(let i = 0; i < n; ++i) off.push(read_u32(d, LE));\n for(let i = 0; i < n; ++i) val.push(read_u32(d, LE));\n const str = u8_to_latin1(d.raw.slice(d.ptr, d.ptr + txtlen));\n d.ptr += txtlen;\n for(let i = 0; i < n; ++i) labels[val[i]] = str.slice(off[i], str.indexOf(\"\\x00\", off[i]));\n }\n const C = value_label_names.indexOf(labname);\n if(C == -1) throw new Error(`unexpected value label |${labname}|`);\n for(let R = 1; R < ws[\"!data\"].length; ++R) {\n const cell = ws[\"!data\"][R][C];\n cell.t = \"s\"; cell.v = cell.w = labels[(cell.v as number)||0];\n }\n\n }\n\n const wb: WorkBook = _utils.book_new();\n _utils.book_append_sheet(wb, ws, \"Sheet1\");\n wb.bookType = \"dta\" as any;\n return wb;\n}\n\n/** Parse DTA file\n *\n * NOTE: In NodeJS, `Buffer` extends `Uint8Array`\n *\n * @param {Uint8Array} data File data\n */\nfunction parse(data: Uint8Array): WorkBook {\n if(data[0] >= 102 && data[0] <= 115) return parse_legacy(data);\n if(data[0] === 60) return parse_tagged(data);\n throw new Error(\"Not a DTA file\");\n}\n"], + "mappings": "AAGA,GAAM,GAAU,QAEZ,EAaJ,WAAmB,EAAkB,CACnC,EAAS,EAGX,WAAmB,EAAwB,CACzC,MAAO,IAAI,eAAc,OAAO,GAIlC,WAAsB,EAAwB,CAC5C,MAAO,IAAI,aAAY,UAAU,OAAO,GAK1C,WAA2B,EAAe,EAAgB,EAAuB,CAC/E,GAAG,EAAQ,EAAG,CAAE,GAAM,GAAM,EAAkB,CAAC,EAAO,EAAQ,GAAI,SAAI,EAAI,IAAM,EAAI,EAAU,EAC9F,GAAM,GAAgB,CAAE,EAAG,IAAK,EAAG,GAEnC,OAAO,OACA,SAAU,QAAW,OAAO,EAAS,QA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IAAK,EAAE,IAAM,IAAI,QAAQ,UAAU,IAC9E,EAAE,KAAO,EACT,EAAE,KAAO,EACT,GAAM,GAAmB,GACzB,CACE,GAAM,GAAI,EAAS,EAAG,GAChB,EAAS,EAAS,EAAG,GACrB,EAAgB,GAAI,EAAgB,GAC1C,OAAQ,GAAI,EAAG,EAAI,EAAG,EAAE,EAAG,EAAI,KAAK,EAAS,EAAG,IAChD,OAAQ,GAAI,EAAG,EAAI,EAAG,EAAE,EAAG,EAAI,KAAK,EAAS,EAAG,IAChD,GAAM,GAAM,EAAa,EAAE,IAAI,MAAM,EAAE,IAAK,EAAE,IAAM,IACpD,EAAE,KAAO,EACT,OAAQ,GAAI,EAAG,EAAI,EAAG,EAAE,EAAG,EAAO,EAAI,IAAM,EAAI,MAAM,EAAI,GAAI,EAAI,QAAQ,KAAQ,EAAI,KAExF,GAAM,GAAI,EAAkB,QAAQ,GACpC,GAAG,GAAK,GAAI,KAAM,IAAI,OAAM,2BAA2B,MACvD,OAAQ,GAAI,EAAG,EAAI,EAAG,SAAS,OAAQ,EAAE,EAAG,CAC1C,GAAM,GAAO,EAAG,SAAS,GAAG,GAC5B,EAAK,EAAI,IAAK,EAAK,EAAI,EAAK,EAAI,EAAQ,EAAK,GAAc,IAK/D,GAAM,GAAe,EAAO,WAC5B,SAAO,kBAAkB,EAAI,EAAI,UACjC,EAAG,SAAW,MACP,EAST,WAAe,EAA4B,CACzC,GAAG,EAAK,IAAM,KAAO,EAAK,IAAM,IAAK,MAAO,GAAa,GACzD,GAAG,EAAK,KAAO,GAAI,MAAO,GAAa,GACvC,KAAM,IAAI,OAAM", + "names": [] +} diff --git a/packages/dta/dta.ts b/packages/dta/dta.ts index 77b4b69..692186d 100644 --- a/packages/dta/dta.ts +++ b/packages/dta/dta.ts @@ -1,7 +1,7 @@ import { CellObject, DenseWorkSheet, WorkBook, type utils } from 'xlsx'; export { parse, set_utils, version }; -const version = "0.0.1"; +const version = "0.0.2"; let _utils: typeof utils; /** Set internal instance of `utils` @@ -92,7 +92,6 @@ function read_f32(p: Payload, LE: boolean): number | null { p.ptr += 4; const d = p.dv.getFloat32(p.ptr - 4, LE); return d > 1.701e+38 ? null : d; - } function read_u32(p: Payload, LE: boolean) { p.ptr += 4; @@ -150,7 +149,7 @@ function parse_tagged(raw: Uint8Array): WorkBook { ptr: 0, raw, dv: u8_to_dataview(raw) - } + }; let vers: number = 118; let LE: boolean = true; @@ -469,6 +468,7 @@ function parse_tagged(raw: Uint8Array): WorkBook { if(!valid_inc(d, "")) throw err; const wb = _utils.book_new(); _utils.book_append_sheet(wb, ws, "Sheet1"); + wb.bookType = "dta" as any; return wb; } @@ -480,7 +480,7 @@ function parse_legacy(raw: Uint8Array): WorkBook { ptr: 1, raw, dv: u8_to_dataview(raw) - } + }; let LE: boolean = true; let nvar: number = 0, nobs: number = 0; @@ -612,6 +612,7 @@ function parse_legacy(raw: Uint8Array): WorkBook { const wb: WorkBook = _utils.book_new(); _utils.book_append_sheet(wb, ws, "Sheet1"); + wb.bookType = "dta" as any; return wb; } diff --git a/packages/dta/package.json b/packages/dta/package.json index cfa9ad3..a0c07dd 100644 --- a/packages/dta/package.json +++ b/packages/dta/package.json @@ -1,12 +1,13 @@ { "name": "dta", - "version": "0.0.1", + "version": "0.0.2", "author": "sheetjs", "description": "Stata .dta codecs for SheetJS Common Spreadsheet Format", "bin": { "dta2csv": "./bin/dta2csv.njs" }, "main": "dist/dta.js", + "module": "dist/dta.mjs", "types": "types", "files": [ "bin/", @@ -33,6 +34,6 @@ "node": ">=12.0" }, "devDependencies": { - "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz" + "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.1/xlsx-0.20.1.tgz" } } diff --git a/packages/dta/types/index.d.ts b/packages/dta/types/index.d.ts index 9a10e7c..4304560 100644 --- a/packages/dta/types/index.d.ts +++ b/packages/dta/types/index.d.ts @@ -1,6 +1,6 @@ import { WorkBook } from 'xlsx'; export { parse, set_utils, version }; -declare const version = "0.0.1"; +declare const version = "0.0.2"; /** Set internal instance of `utils` * * Usage: