import { FieldType } from '@grafana/data' ; import moment from 'moment' ; /**
 * Detects the field type from an array of values.
 */ export const detectFieldType = ( values ) : FieldType => { if ( values . every ( ( _ ) => _ === null ) ) { return FieldType . string ; } const isValidISO = values . filter ( ( value ) => value !== null ) . every ( ( value ) => moment ( value , [ moment . defaultFormat , 'YYYY-MM-DD' ] , true ) . isValid ( ) ) ; if ( isValidISO ) { return FieldType . time ; } if ( values . every ( ( value ) => typeof value === 'number' ) ) { return FieldType . number ; } if ( values . every ( ( value ) => typeof value === 'boolean' ) ) { return FieldType . boolean ; } return FieldType . string ; } ;