/** * File generator. * * `` in the DSL: load a list * of string values from a file (one per line, empty lines skipped) and * pick uniformly from them for each cell. * * `` switches * into CSV-column mode. The first row is treated as a header for named * columns. Numeric columns are 1-based and may skip a header row with * `header="true"`. * * The loader is kept separate from the generator so that: * - the module stays testable without touching the filesystem * (inject an in-memory loader in unit tests); * - the same loader can be shared across multiple generators that * reference the same file path (caching happens at a higher layer); * - alternate sources (e.g. HTTP, npm-packaged locale data) can be * plugged in without changing generator code. * * See docs/vision/10-generators.md for the strategy around user-supplied * data files and future expansion to per-locale npm packs. */ import type { Generator } from './generator.js'; export interface FileSourceOptions { readonly column?: string | undefined; readonly header?: string | boolean | undefined; readonly delimiter?: string | undefined; } export type FileValueLoader = (path: string, options: FileSourceOptions) => string[]; export type LegacyListLoader = (path: string) => string[]; export interface CsvColumnSource { readonly rows: readonly (readonly string[])[]; /** The header row as read, kept so a SECOND column can still be resolved by name. */ readonly headerRow: readonly string[]; readonly column: string; readonly columnIndex: number; readonly delimiter: string; readonly skipHeader: boolean; } /** * Read a list file from disk and return its trimmed non-empty lines. * Used as the default loader by `fileUniform` but exported for reuse. */ export declare function loadListFile(path: string): string[]; export declare function loadFileValues(path: string, options?: FileSourceOptions): string[]; export declare function loadCsvColumnFile(path: string, options: FileSourceOptions): string[]; export declare function loadCsvColumnSource(path: string, options: FileSourceOptions): CsvColumnSource; export declare function parseCsvRows(content: string, delimiter?: string): string[][]; /** * Build a Generator that reads a list file and picks uniformly from its * lines for each cell. The file is loaded eagerly at generator-build * time (so the cost is amortised across all `count` picks). * * An explicit loader may be supplied in place of `loadListFile` for * testing or to plug in alternate sources. */ export declare function fileUniform(path: string, optionsOrLoader?: FileSourceOptions | LegacyListLoader, loader?: FileValueLoader): Generator; export declare function parseDelimiter(value: string | undefined): string; export declare function resolveCsvColumnIndex(headerRow: readonly string[], column: string): number; export declare function csvColumnCell(row: readonly string[], columnIndex: number): string; //# sourceMappingURL=file.d.ts.map