diff --git a/src/lib/cs2json.spec.ts b/src/lib/cs2json.spec.ts index 8c9dbdd4..0f202992 100644 --- a/src/lib/cs2json.spec.ts +++ b/src/lib/cs2json.spec.ts @@ -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); + }); }); diff --git a/src/lib/csv2json.ts b/src/lib/csv2json.ts index 768ca4fb..afbac996 100644 --- a/src/lib/csv2json.ts +++ b/src/lib/csv2json.ts @@ -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; }