MCPcopy Create free account
hub / github.com/denoland/std / convertRowToObject

Function convertRowToObject

csv/_io.ts:227–244  ·  view source on GitHub ↗
(
  row: readonly string[],
  headers: readonly string[],
  zeroBasedLine: number,
)

Source from the content-addressed store, hash-verified

225}
226
227export function convertRowToObject(
228 row: readonly string[],
229 headers: readonly string[],
230 zeroBasedLine: number,
231) {
232 if (row.length !== headers.length) {
233 throw new Error(
234 `Syntax error on line ${
235 zeroBasedLine + 1
236 }: The record has ${row.length} fields, but the header has ${headers.length} fields`,
237 );
238 }
239 const out: Record<string, unknown> = {};
240 for (const [index, header] of headers.entries()) {
241 out[header] = row[index];
242 }
243 return out;
244}
245
246/** Parse result type for {@linkcode parse} and {@linkcode CsvParseStream}. */
247export type ParseResult<ParseOptions, T> =

Callers 2

#pullMethod · 0.90
parseFunction · 0.90

Calls 1

entriesMethod · 0.45

Tested by

no test coverage detected