mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-07-27 18:22:10 +10:00
chore: update public repo
This commit is contained in:
parent
3057b2a78c
commit
2b73e3b411
1 changed files with 5 additions and 5 deletions
10
utils/csv.ts
10
utils/csv.ts
|
@ -16,8 +16,8 @@ interface CsvReaderOptions {
|
|||
*/
|
||||
assumeEmptyValues: boolean
|
||||
|
||||
/** whether to treat header line as a data line */
|
||||
includeHeader: boolean
|
||||
/** whether to treat all data from the readable as data (requires `schema` to be set) */
|
||||
skipHeader: boolean
|
||||
}
|
||||
|
||||
export class CsvReader<const Fields extends string[] = string[]> {
|
||||
|
@ -29,7 +29,7 @@ export class CsvReader<const Fields extends string[] = string[]> {
|
|||
options: Partial<CsvReaderOptions> & {
|
||||
/** fields that are expected in the csv */
|
||||
schema?: Fields
|
||||
},
|
||||
} = {},
|
||||
) {
|
||||
this.options = {
|
||||
lineDelimiter: '\n',
|
||||
|
@ -37,14 +37,14 @@ export class CsvReader<const Fields extends string[] = string[]> {
|
|||
quote: '"',
|
||||
quoteEscape: '"',
|
||||
assumeEmptyValues: false,
|
||||
includeHeader: false,
|
||||
skipHeader: false,
|
||||
...options,
|
||||
}
|
||||
|
||||
this.#codec = new FramedReader(stream, new TextDelimiterCodec(this.options.lineDelimiter))
|
||||
this.#schema = options.schema
|
||||
|
||||
if (options.includeHeader) {
|
||||
if (options.skipHeader) {
|
||||
if (!options.schema) throw new Error('schema is required if includeHeader is true')
|
||||
this.#header = options.schema
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue