Open sergeysolovev opened 7 months ago
just want to mention that this works if you pass the columns options
console.log(stringify(arr, { columns: ["a", "b"] }));
without it it errors with
error: Uncaught (in promise) StringifyError: No property accessor function was provided for object
throw new StringifyError(
@sigmaSd thank you for the suggestion! It helped me to simplify my little wrapper to auto-stringify an array of objects
export class Csv {
static stringify(array: Record<string, unknown>[]) {
const columns = Object.keys(array[0]);
return stringify(array, { columns }).trim();
}
}
I like this idea! Thoughts, @kt3k?
In the mean while, shouldn't columns
property be mandatory instead of optional ? because currently it feels weird that if you just use stringify(data)
it throws
Closing as duplicate of #2660.
@iuioiua This is a feature request for auto-inferring headers, the way mature CSV libraries do.
columns
option as mandatory. If this feature (#3857) is implemented, then #2660 can be closed. Until then, #2660 can be resolved independently. We should reopen this issue (#3857).@sergeysolovev: can you please rename this issue to "CSV - option to automatically infer headers" or something similar?
@dandv alright, ready
It would be amazing if this code worked, probably by passing something like
inferHeaders
option (suggested by @crowlKats).