From 66de68e7d6a627e05915319fb00e2502ad8f8532 Mon Sep 17 00:00:00 2001 From: Tim Gatzemeier Date: Thu, 23 Sep 2021 16:49:29 +0200 Subject: [PATCH] return defaultValue for null and undefined - treat null and undefined as missing - apply same behaviour as in https://github.com/zemirco/json2csv/blob/2ea1c3c3c1259725a8b43458ef788ef30ef6d0a8/lib/JSON2CSVBase.js#L94-L106 --- lib/utils.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index a6752d8..be3f636 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,7 +1,8 @@ 'use strict'; function getProp(obj, path, defaultValue) { - return obj[path] === undefined ? defaultValue : obj[path]; + const value = obj[path]; + return (value === null || value === undefined) ? defaultValue : value; } function setProp(obj, path, value) { @@ -34,4 +35,4 @@ module.exports = { getProp, setProp, unsetProp, -}; \ No newline at end of file +};