Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/csv-stringify/lib/api/normalize_columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const normalize_columns = function (columns) {
column !== null &&
!Array.isArray(column)
) {
if (!column.key) {
if (!column.key && column.key !== "") {
return [
Error('Invalid column definition: property "key" is required'),
];
Expand Down
15 changes: 15 additions & 0 deletions packages/csv-stringify/test/option.columns.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import "should";
import { stringify } from "../lib/index.js";
import { stringify as stringifySync } from "../lib/sync.js";

describe("Option `columns`", function () {
describe("definition", function () {
it("accepts an empty record key with an explicit header", function () {
stringifySync([{ "": "value" }], {
columns: [{ key: "", header: "blank" }],
header: true,
}).should.eql("blank\nvalue\n");
});

it("accepts an empty record key with the default header", function () {
stringifySync([{ "": "value" }], {
columns: [{ key: "" }],
header: true,
}).should.eql("\nvalue\n");
});

it("validates option types", function () {
(() => {
stringify([], { columns: true }, () => {});
Expand Down