import { ReaderError } from './errors'; /** * Reader configurations at the time of creation. * @typedef {Object} readerConfig */ export declare type readerConfig = { /** * The field delimiter. Default to comma character (','). * Comma must be a valid rune and must not be \r, \n, * or the Unicode replacement character (0xFFFD). */ comma?: string; /** * Comment, if defined, is the comment character. * Lines beginning with the comment character without preceding whitespace are ignored. * With leading whitespace the comment character becomes part of the * field, even if {@link trimLeadingSpace} is true. * Comment must be a valid rune and must not be \r, \n, * or the Unicode replacement character (0xFFFD). * It must also not be equal to {@link comma}. */ comment?: string; /** * The number of expected fields per record. * If fieldsPerRecord is positive, Read requires each record to * have the given number of fields. If fieldsPerRecord is 0, Read sets it to * the number of fields in the first record, so that future records must * have the same field count. If fieldsPerRecord is negative, no check is * made and records may have a variable number of fields. */ fieldsPerRecord?: number; /** * If lazyQuotes is true, * a quote may appear in an unquoted field and a * non-doubled quote may appear in a quoted field. */ lazyQuotes?: boolean; /** * If trimLeadingSpace is true, * leading white space in a field is ignored. * This is done even if the field delimiter, Comma, is white space. */ trimLeadingSpace?: boolean; }; /** * Called once for each record. If this callback returns `true` * then abort reading prematurely. * @param {string[]} record - Array of fields in this record. * @returns {boolean|void} true to abort iteration. */ export declare type recordCallback = (record: string[]) => boolean | void; export declare const errInvalidDelim: ReaderError; /** * @class */ export default class Reader { private comma; private comment; private commaLen; private lazyQuotes; private trimLeadingSpace; private r; private numLine; private line; private fullLine; private lastRecord; private parsingQuotedString; private recLine; private rawBuffer; private recordBuffer; /** * Create a new instance of Reader. * @constructor * @param input - CSV text string, bytes array or readable stream of those types. * @param config - If present then override default settings. */ constructor(input: ReadableStream | ReadableStream | string | Uint8Array, config?: readerConfig); /** * @ignore */ private _setComma; /** * @ignore */ private _setComment; private _readLine; private _validateCommaComment; private _handleEOF; private _processLine; private _parseQuotedString; private _readLineSkipEmpty; private _fillRecordBuffer; private _readRecord; /** * Read all the remaining records. * @param {recordCallback} cb - The callback that will be called with each record. * @returns {Promise} Resolve when there's no record left or if reading is aborted. */ readAll(cb: recordCallback): Promise; /** * Read at most N records. * @param {int} n - Maximum number of records to read. * @param {recordCallback} cb - The callback to be called with each record. * @returns {Promise} Resolve when there's no record left or the maximum number of records have been reached. */ readN(n: number, cb: recordCallback): Promise; }