return defaultValue for null and undefined#543
return defaultValue for null and undefined#543etwillbefine wants to merge 1 commit intozemirco:masterfrom
Conversation
- treat null and undefined as missing - apply same behaviour as in https://github.com/zemirco/json2csv/blob/2ea1c3c3c1259725a8b43458ef788ef30ef6d0a8/lib/JSON2CSVBase.js#L94-L106
|
I'll leave it to @juanjoDiaz to comment, since it might be that way for a reason. Otherwise the code looks fine. |
|
Hi all, The reason for it to be like this is that In any case, this breaks the API since we don't know if our users are currently that actually expect to get the null back. I'd be happy to add a new property Al alternative is to use a transform to convert |
|
Hi @juanjoDiaz I agree with you that introducing an additional option (useDefaultValueOnNull) makes sense. I'll free some time for it during next week hopefully.
This makes sense but it is actually inconsistent. As described when using a function as fieldInfo value the behaviour is different to using the column key as fieldInfo value. So I guess this should then also be unified? That would still be some kind of breaking change but could be merged into the upcoming v6.x version, right?
Imo the better way is to introduce useDefaultValueOnNull as converting null to undefined using a transformer requires us to hook into the object transformer.
I'm not 100% sure I get what you mean by caching. Maybe registering different converters with null/undefined check and one with undefined only? |
json2csv/lib/JSON2CSVBase.js
Lines 94 to 106 in 2ea1c3c
Current behaviour:
Converts only
undefinedtodefaultValue(see getProp)Converts
nullandundefinedtodefaultValue(see here)