packageDocumentation module import { Primitives , StandardTypeNames } from "@itwin/appui-abstract" ; import { LessGreaterOperatorProcessor , TypeConverter } from "./TypeConverter" ; import { TypeConverterManager } from "./TypeConverterManager" ; public export abstract class NumericTypeConverterBase extends TypeConverter implements LessGreaterOperatorProcessor { public override get isLessGreaterType ( ) : boolean { return true ; } public isLessThan ( a , b ) { return a < b ; } public isLessThanOrEqualTo ( a , b ) { return a <= b ; } public isGreaterThan ( a , b ) { return a > b ; } public isGreaterThanOrEqualTo ( a , b ) { return a >= b ; } public sortCompare ( a , b , _ignoreCase ? ) { return ( + a ) - ( + b ) ; } } public export class FloatTypeConverter extends NumericTypeConverterBase { public override convertToString ( value ? ) { if ( value === undefined ) return "" ; let numericValue = 0 ; if ( typeof value === "string" ) { if ( value === "-" || value === "" || value === "-0.0" || value === "-0" ) { numericValue = 0 ; } else { numericValue = parseFloat ( value ) ; } } else { numericValue = value ; } let stringValue = ( Math . round ( 100 * numericValue ) / 100 ) . toString ( ) ; if ( stringValue . indexOf ( "." ) === - 1 ) stringValue += ".0" ; return stringValue ; } public override convertFromString ( value ) { return parseFloat ( value ) ; } } TypeConverterManager . registerConverter ( StandardTypeNames . Float , FloatTypeConverter ) ; TypeConverterManager . registerConverter ( StandardTypeNames . Double , FloatTypeConverter ) ; TypeConverterManager . registerConverter ( StandardTypeNames . Number , FloatTypeConverter ) ; public export class IntTypeConverter extends NumericTypeConverterBase { public override convertToString ( value ? ) { if ( value === undefined ) return "" ; let numericValue = 0 ; if ( typeof value === "string" ) { if ( value === "-" || value === "" || value === "-0" ) { numericValue = 0 ; } else { numericValue = parseInt ( value , 10 ) ; } } else { numericValue = value ; } return Math . round ( numericValue ) . toString ( ) ; } public override convertFromString ( value ) { return parseInt ( value , 10 ) ; } } TypeConverterManager . registerConverter ( StandardTypeNames . Int , IntTypeConverter ) ; TypeConverterManager . registerConverter ( StandardTypeNames . Integer , IntTypeConverter ) ;