Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
({descriptor}, {resourceIndex, headers, rows}) => {
descriptor = cloneDeep(descriptor)
const schemaDescriptor = descriptor.resources[resourceIndex].schema
// Get columns
const columns = []
for (const [index, header] of headers.entries()) {
columns[index] = columns[index] || {header, values: []}
for (const row of rows) {
columns[index].values.push(row[index])
}
}
// Infer columns
for (const column of columns) {
const schema = new Schema()
schema.infer(column.values, {headers: [column.header]})
column.descriptor = schema.descriptor.fields[0]
}
// Update descriptor
schemaDescriptor._columns = columns
for (const [index, column] of columns.entries()) {
const field = schemaDescriptor.fields[index]
if (field) schemaDescriptor.fields[index] = {...field, ...column.descriptor}
}
return {descriptor}
},
const descriptor = this._currentDescriptor
options.format = descriptor.format || 'csv'
options.encoding = descriptor.encoding
const dialect = descriptor.dialect
if (dialect) {
if (dialect.header === false || config.DEFAULT_DIALECT.header === false) {
const fields = (descriptor.schema || {}).fields || []
options.headers = fields.length ? fields.map(field => field.name) : null
}
helpers.validateDialect(dialect)
for (const key of DIALECT_KEYS) {
if (dialect[key]) options[key.toLowerCase()] = dialect[key]
}
}
const schemaDescriptor = this._currentDescriptor.schema
const schema = schemaDescriptor ? new Schema(schemaDescriptor) : null
this._table = new Table(this.source, {schema, ...options})
}
return this._table
}