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
|
assumeEmptyValues: boolean
|
||||||
|
|
||||||
/** whether to treat header line as a data line */
|
/** whether to treat all data from the readable as data (requires `schema` to be set) */
|
||||||
includeHeader: boolean
|
skipHeader: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CsvReader<const Fields extends string[] = string[]> {
|
export class CsvReader<const Fields extends string[] = string[]> {
|
||||||
|
@ -29,7 +29,7 @@ export class CsvReader<const Fields extends string[] = string[]> {
|
||||||
options: Partial<CsvReaderOptions> & {
|
options: Partial<CsvReaderOptions> & {
|
||||||
/** fields that are expected in the csv */
|
/** fields that are expected in the csv */
|
||||||
schema?: Fields
|
schema?: Fields
|
||||||
},
|
} = {},
|
||||||
) {
|
) {
|
||||||
this.options = {
|
this.options = {
|
||||||
lineDelimiter: '\n',
|
lineDelimiter: '\n',
|
||||||
|
@ -37,14 +37,14 @@ export class CsvReader<const Fields extends string[] = string[]> {
|
||||||
quote: '"',
|
quote: '"',
|
||||||
quoteEscape: '"',
|
quoteEscape: '"',
|
||||||
assumeEmptyValues: false,
|
assumeEmptyValues: false,
|
||||||
includeHeader: false,
|
skipHeader: false,
|
||||||
...options,
|
...options,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#codec = new FramedReader(stream, new TextDelimiterCodec(this.options.lineDelimiter))
|
this.#codec = new FramedReader(stream, new TextDelimiterCodec(this.options.lineDelimiter))
|
||||||
this.#schema = options.schema
|
this.#schema = options.schema
|
||||||
|
|
||||||
if (options.includeHeader) {
|
if (options.skipHeader) {
|
||||||
if (!options.schema) throw new Error('schema is required if includeHeader is true')
|
if (!options.schema) throw new Error('schema is required if includeHeader is true')
|
||||||
this.#header = options.schema
|
this.#header = options.schema
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue