| 99 | opts: Partial<ParseOptions> & { output: 'objects' } |
| 100 | ): { [k: string]: Value }[]; |
| 101 | function parse( |
| 102 | input: string, |
| 103 | sepOrOpts?: Comma | Partial<ParseOptions>, |
| 104 | quo?: Quote |
| 105 | ): Value[][] | { [k: string]: Value }[] { |
| 106 | // Create an options hash, using positional parameters or the passed in options hash for values |
| 107 | const opts: Partial<ParseOptions> = typeof sepOrOpts === "object" ? sepOrOpts : {}; |
| 108 | if (typeof sepOrOpts === "string") { |
| 109 | opts.comma = sepOrOpts as Comma; |
| 110 | } |
| 111 | if (quo) { |
| 112 | opts.quote = quo as Quote; |
| 113 | } |
| 114 | |
| 115 | // try to detect the separator if not provided |
| 116 | if (opts.comma === undefined) { |
| 117 | opts.comma = detect(input); |
| 118 | } |
| 119 | |
| 120 | // Clean characters, if necessary |
| 121 | // TODO: We should probably throw an error here to signal bad input to the user |
| 122 | if (opts.comma) { |
| 123 | opts.comma = opts.comma[0] as Comma; |
| 124 | } |
| 125 | if (opts.quote) { |
| 126 | opts.quote = opts.quote[0] as Quote; |
| 127 | } |
| 128 | |
| 129 | const csv = new Parser(input, opts.comma, opts.quote); |
| 130 | return csv.File(opts.output); |
| 131 | }; |
| 132 | |
| 133 | function read(input: string, callback: ReadCallback): number; |
| 134 | function read(input: string, sep: Comma, callback: ReadCallback): number; |