/** * @fileoverview Minimal RFC-4180 CSV reader tuned for the OurAirports dumps. * Parses by HEADER NAME (not column position) because the live CSV column order * differs from the published data dictionary (e.g. icao_code precedes gps_code * in the real file). Handles quoted fields, embedded commas, embedded newlines, * and doubled `""` escapes — all of which appear in OurAirports name/keyword * columns. * * Streaming, not array-materializing: `forEachRow` hands each row to a visitor * as soon as it is parsed, reusing a single cell buffer and a single row view. * It never builds the whole `string[][]` or a `Record` per row, * so parsing the 12.6 MB airports.csv holds one row's cells live — not 85k row * objects and their strings stacked on top of the raw file. Cells are built by * character accumulation (flat, self-owned strings) rather than by slicing the * raw buffer — a slice-view would pin the whole multi-MB file string alive for * as long as any parsed field is retained, re-inflating the steady-state heap. * @module src/services/airport-data/csv */ /** * One parsed CSV row. `get(column)` returns the raw cell for a header column, or * `''` when the column is absent from the header or the row is short. The * instance is reused across rows — read what you need during the visit; do not * retain the row or its values beyond the callback. */ export interface CsvRow { get(column: string): string; } /** * Stream CSV rows to `visit`, keyed by the header row. Consumes the header row * (never visited), skips a stray fully-empty trailing line, and reads absent * trailing cells as `''` — matching the previous parseRows+parseCsv semantics * byte-for-byte (verified against the six bundled CSVs and a battery of quoting * / line-ending edge cases). * * State machine over the full string: a `"` toggles quoted mode where commas and * newlines are literal and `""` is a single quote; a top-level comma closes a * field; LF, bare CR, or CRLF closes the row; a trailing field/row with no * terminator is flushed at end-of-input. */ export declare function forEachRow(text: string, visit: (row: CsvRow) => void): void; /** Trimmed string, or `undefined` when the cell is empty. */ export declare function str(v: string | undefined): string | undefined; /** Required trimmed string — throws when absent (use only for guaranteed PK-like columns). */ export declare function reqStr(v: string | undefined, field: string): string; /** Parsed integer, or `undefined` when the cell is empty or non-numeric. */ export declare function int(v: string | undefined): number | undefined; /** * Parsed positive integer, or `undefined` when the cell is empty, non-numeric, * or ≤ 0 — for columns where upstream writes `-1` as an "unknown" placeholder. */ export declare function positiveInt(v: string | undefined): number | undefined; /** Required parsed integer — throws when absent or non-numeric. */ export declare function reqInt(v: string | undefined, field: string): number; /** Parsed float, or `undefined` when the cell is empty or non-numeric. */ export declare function num(v: string | undefined): number | undefined; /** * OurAirports boolean columns are `"1"`/`"0"` (and occasionally `"yes"`/`"no"` * or `"true"`/`"false"`). Anything else (including empty) is `false`. */ export declare function bool(v: string | undefined): boolean; /** * Strip keys whose value is `undefined`, returning the object with those keys * made optional. Lets a domain object be assembled as a flat literal (with * `undefined` for absent CSV cells) and then satisfy an interface declared under * `exactOptionalPropertyTypes` — absent fields are genuinely omitted, not set to * `undefined`. The runtime delete makes the cast sound. */ export declare function compact>(obj: T): { [K in keyof T]?: Exclude; }; //# sourceMappingURL=csv.d.ts.map