@@ -35,6 +35,11 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
3535 * list of field names.
3636 */
3737 function processSchemas ( documentSchemas : string [ ] [ ] ) {
38+ // If there are no document schemas then there is nothing to diff and no unqiue fields to get
39+ if ( documentSchemas . length === 0 ) {
40+ return [ ] ;
41+ }
42+
3843 // If the user wants to check for the same schema (regardless of schema ordering)
3944 if ( options . checkSchemaDifferences ) {
4045 return checkSchemaDifferences ( documentSchemas ) ;
@@ -53,8 +58,8 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
5358 function checkSchemaDifferences ( documentSchemas : string [ ] [ ] ) {
5459 // have multiple documents - ensure only one schema (regardless of field ordering)
5560 const firstDocSchema = documentSchemas [ 0 ] ,
56- restOfDocumentSchemas = documentSchemas . slice ( 1 ) ,
57- schemaDifferences = computeNumberOfSchemaDifferences ( firstDocSchema , restOfDocumentSchemas ) ;
61+ restOfDocumentSchemas = documentSchemas . slice ( 1 ) ,
62+ schemaDifferences = computeNumberOfSchemaDifferences ( firstDocSchema , restOfDocumentSchemas ) ;
5863
5964 // If there are schema inconsistencies, throw a schema not the same error
6065 if ( schemaDifferences ) {
@@ -457,7 +462,7 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
457462 */
458463 function convert ( data : object [ ] ) {
459464 // Single document, not an array
460- if ( utils . isObject ( data ) && ! data . length ) {
465+ if ( ! Array . isArray ( data ) ) {
461466 data = [ data ] ; // Convert to an array of the given document
462467 }
463468
0 commit comments