File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,12 @@ export interface IFullOptions extends ISharedOptions {
82
82
*/
83
83
useLocaleFormat ?: boolean ;
84
84
85
+ /**
86
+ * Should dates be output in ISO 8601 "Z" format:
87
+ * @default false
88
+ */
89
+ useDateIso8601Format ?: boolean ;
90
+
85
91
}
86
92
87
93
export function json2csv ( data : object [ ] ,
Original file line number Diff line number Diff line change @@ -272,12 +272,15 @@ const Json2Csv = function(options) {
272
272
* @returns {* }
273
273
*/
274
274
function recordFieldValueToString ( fieldValue ) {
275
- if ( Array . isArray ( fieldValue ) || utils . isObject ( fieldValue ) && ! utils . isDate ( fieldValue ) ) {
275
+ const isD = utils . isDate ( fieldValue ) ; // store to avoid checking twice
276
+ if ( Array . isArray ( fieldValue ) || utils . isObject ( fieldValue ) && ! isD ) {
276
277
return JSON . stringify ( fieldValue ) ;
277
278
} else if ( utils . isUndefined ( fieldValue ) ) {
278
279
return 'undefined' ;
279
280
} else if ( utils . isNull ( fieldValue ) ) {
280
281
return 'null' ;
282
+ } else if ( isD && options . useDateIso8601Format ) {
283
+ return new Date ( fieldValue ) . toISOString ( ) ;
281
284
} else {
282
285
return ! options . useLocaleFormat ? fieldValue . toString ( ) : fieldValue . toLocaleString ( ) ;
283
286
}
You can’t perform that action at this time.
0 commit comments