Skip to content

Commit

Permalink
fix(csv2json): recognize "null" -> null
Browse files Browse the repository at this point in the history
  • Loading branch information
gadicc committed Jun 11, 2021
1 parent 6ed6a77 commit d077680
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/cs2json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ describe("csv2json", () => {
const csv = "one line file";
expect(() => csv2json(csv)).toThrow(/No newlines/);
});

it("handles nulls", () => {
const obj = csv2json("val\nnull")[0];
expect(obj.val).toBe(null);
});
});
1 change: 1 addition & 0 deletions src/lib/csv2json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function camelize(str: string): string {
function convert(input: any) {
if (input.match(/\d{4,4}-\d{2,2}-\d{2,2}/)) return new Date(input);
if (input.match(/^[0-9\.]+$/)) return parseFloat(input);
if (input === "null") return null;
return input;
}

Expand Down

0 comments on commit d077680

Please sign in to comment.