Skip to content

Commit 2ada510

Browse files
committed
fix(csv-stringify): infinity is not defined in get (fix #475)
1 parent 22e2a93 commit 2ada510

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

packages/csv-stringify/lib/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export type Cast<T> = (
3232
export type PlainObject<T> = Record<string, T>;
3333
export type Input = any[];
3434
export interface ColumnOption {
35-
key: string;
35+
key: string | (string | number)[];
3636
header?: string;
3737
}
3838
export interface CastingContext {

packages/csv-stringify/lib/utils/get.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ const castPath = function (value, object) {
8484
const toKey = function (value) {
8585
if (typeof value === "string" || isSymbol(value)) return value;
8686
const result = `${value}`;
87-
// eslint-disable-next-line
88-
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
87+
return result == "0" && 1 / value == -Infinity ? "-0" : result;
8988
};
9089

9190
const get = function (object, path) {

packages/csv-stringify/test/option.columns.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ describe("Option `columns`", function () {
8484
);
8585
});
8686

87+
it("Is an array of object with key defined as an array", function (next) {
88+
stringify(
89+
[{ a: "a value", b: [{ c: "c value", d: "d value" }] }],
90+
{
91+
columns: [{ key: ["b", 0, "c"] }],
92+
},
93+
(err, records) => {
94+
if (!err) records.should.eql("c value\n");
95+
next(err);
96+
},
97+
);
98+
});
99+
87100
it("can still access fields with dots", function (next) {
88101
stringify(
89102
[{ "foo.bar": "1" }, { "foo.bar": "2" }],

0 commit comments

Comments
 (0)