packageDocumentation module import { EnumerationChoice , EnumerationChoicesInfo , Primitives , PropertyDescription , StandardTypeNames } from "@itwin/appui-abstract" ; import { TypeConverter } from "./TypeConverter" ; import { TypeConverterManager } from "./TypeConverterManager" ; public export class EnumTypeConverter extends TypeConverter { public override convertPropertyToString ( propertyDescription , value ? ) { if ( value === undefined ) return "" ; if ( propertyDescription . enum ) { return this . getMatchingStringValue ( propertyDescription . enum , value ) ; } return super . convertToString ( value ) ; } private async getMatchingStringValue ( enumVal , value ) { let choices = [ ] ; if ( enumVal . choices instanceof Promise ) { choices = await enumVal . choices ; } else { choices = enumVal . choices ; } const pos = this . getPosition ( choices , value ) ; if ( - 1 !== pos ) return choices [ pos ] . label ; return this . convertToString ( value ) ; } private getPosition ( choices , value ) { for ( let i = 0 ; i < choices . length ; ++ i ) { if ( choices [ i ] . value === value ) return i ; } return - 1 ; } public sortCompare ( a , b , ignoreCase ? ) { if ( isNaN ( + a ) || isNaN ( + b ) ) { return TypeConverterManager . getConverter ( "string" ) . sortCompare ( a , b , ignoreCase ) ; } return ( + a ) - ( + b ) ; } } TypeConverterManager . registerConverter ( StandardTypeNames . Enum , EnumTypeConverter ) ;