sheetjs/packages/dta/dist/dta.mjs.map

8 lines
32 KiB
Plaintext
Raw Normal View History

2024-03-22 04:39:09 +00:00
{
"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, //
"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,QAAS,UAC9C,SAAU,SAAW,OAAO,EAAS,QAAS,UAC9C,SAAU,SAAW,OAAO,EAAS,SAAU,UAC/C,SAAU,SAAW,OAAO,EAAS,QAAS,UAC9C,SAAU,SAAW,OAAO,EAAS,SAAU,cAC3C,KAAM,GAEjB,GAAI,CACF,GAAI,GAAI,CAAG,GAAO,MAAM,WAAW,IAAI,IAAO,EAC1C,EAAI,EACR,AAAG,EAAQ,GAAG,EAAE,EACb,EAAQ,IAAK,EAAE,EACf,EAAQ,KAAM,EAAE,EAChB,EAAQ,MAAO,EAAE,EACpB,GAAM,GAAI,EAAM,gBACV,EAAM,EAAE,QAAQ,MAAQ,GAAK,EAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,KAAK,GAC3D,EAAI,EAAI,EAAI,EAChB,AAAG,EAAI,GAAG,GAAI,GACd,GAAI,GAAI,EAAO,MAAM,eACrB,AAAG,GAAK,CAAC,EAAE,IAAI,GAAI,CAAC,EAAE,IACtB,EAAE,EAAK,MAAK,MAAM,EAAQ,IA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