import { ReadStatType, ReadStatMeasure, ReadStatAlignment, ReadStatCompress, ReadStatMetadata } from "./types.js"; export type CellValue = number | string | null; export interface ValueLabelPair { value: CellValue; label: string; } export interface DatasetVariable { index: number; name: string; label: string | null; type: ReadStatType; format: string | null; measure: ReadStatMeasure; alignment: ReadStatAlignment; displayWidth: number; storageWidth: number; valueLabelsName: string | null; valueLabels: ValueLabelPair[] | null; missingRanges: { lo: CellValue; hi: CellValue; }[]; } export interface Dataset { metadata: ReadStatMetadata; variables: DatasetVariable[]; rows: CellValue[][]; notes: string[]; /** Convert rows into an array of `{ [varName]: value }` objects. */ toObjects(): Record[]; } export type ReadableFormat = "sav" | "zsav" | "dta" | "por" | "sas7bdat" | "xport"; export interface ReadOptions { /** Override the file's declared character encoding (iconv-style name). */ inputEncoding?: string | null; rowLimit?: number; rowOffset?: number; } /** Parse an in-memory data file into a fully materialized Dataset. */ export declare function readData(format: ReadableFormat, data: Uint8Array, options?: ReadOptions): Dataset; /** Auto-detect the format from the file's magic bytes. */ export declare function detectFormat(data: Uint8Array): ReadableFormat | null; export declare function readSav(data: Uint8Array, options?: ReadOptions): Dataset; export declare function readDta(data: Uint8Array, options?: ReadOptions): Dataset; export type WritableFormat = "sav" | "zsav" | "dta" | "por" | "xport" | "sas7bdat"; export interface WriteVariable { name: string; type: ReadStatType; /** For strings: storage width in bytes. For SAS XPORT doubles: 3-8. */ storageWidth?: number; label?: string; format?: string; measure?: ReadStatMeasure; alignment?: ReadStatAlignment; displayWidth?: number; /** Named value-label set (must match a key in `valueLabelSets`). */ valueLabels?: string; missingValues?: number[]; missingRanges?: [number, number][]; } export interface WriteValueLabel { value: number | string; label: string; tag?: string; } export interface WriteSpec { variables: WriteVariable[]; rows: CellValue[][]; valueLabelSets?: Record; fileLabel?: string; notes?: string[]; timestamp?: number; version?: number; compression?: ReadStatCompress; } /** Serialize a dataset spec into an in-memory data file. */ export declare function writeData(format: WritableFormat, spec: WriteSpec): Uint8Array; export declare function writeSav(spec: WriteSpec): Uint8Array; export declare function writeZsav(spec: WriteSpec): Uint8Array; export declare function writeDta(spec: WriteSpec): Uint8Array; export declare function writePor(spec: WriteSpec): Uint8Array; export declare function readPor(data: Uint8Array, options?: ReadOptions): Dataset; export declare function writeXport(spec: WriteSpec): Uint8Array; export declare function readXport(data: Uint8Array, options?: ReadOptions): Dataset; export declare function readSas7bdat(data: Uint8Array, options?: ReadOptions): Dataset; export declare function writeSas7bdat(spec: WriteSpec): Uint8Array; export type SchemaFormat = "stata" | "spss" | "sas"; /** * Read a plain-text data file described by an external schema file * (Stata dictionary `.dct`, SPSS command file `.sps`, or SAS command file * `.sas`). */ export declare function readTxt(data: Uint8Array, schemaBytes: Uint8Array, schemaFormat: SchemaFormat, options?: ReadOptions): Dataset;