import { i18n } from '@osd/i18n' ; import { truncate } from 'lodash' ; import { OSD_FIELD_TYPES } from '../../osd_field_types/types' ; import { FieldFormat } from '../field_format' ; import { TextContextTypeConvert , FIELD_FORMAT_IDS } from '../types' ; const omission = '...' ; export class TruncateFormat extends FieldFormat { static id = FIELD_FORMAT_IDS . TRUNCATE ; static title = i18n . translate ( 'data.fieldFormats.truncated_string.title' , { defaultMessage : 'Truncated string' , } ) ; static fieldType = OSD_FIELD_TYPES . STRING ; textConvert : TextContextTypeConvert = ( val ) => { const length = this . param ( 'fieldLength' ) ; if ( length > 0 ) { return truncate ( val , { length : length + omission . length , omission , } ) ; } return val ; } ; }