import { IntPretty , IntPrettyOptions } from "./int-pretty" ; import { Dec } from "./decimal" ; import { DeepReadonly } from "utility-types" ; import bigInteger from "big-integer" ; export type RatePrettyOptions = { separator : string ; symbol : string ; } ; /**
 * RatePretty treats `Dec` in rate form for easy calculation, and displays it as a percentage to the user by using toString().
 * By default, if the value is less than maxDeciamls, it is displayed using an inequality sign (Ex. < 0.001%)
 */ export class RatePretty { protected intPretty : IntPretty ; protected _options : RatePrettyOptions = { separator : "" , symbol : "%" , } ; constructor ( protected amount ) { this . intPretty = new IntPretty ( amount ) ; this . intPretty = this . intPretty . maxDecimals ( 3 ) . shrink ( false ) . trim ( true ) . locale ( true ) . inequalitySymbol ( true ) ; } get options ( ) : DeepReadonly < Omit < IntPrettyOptions , "locale" > & RatePrettyOptions > { return { ... this . intPretty . options , ... this . _options , } ; } separator ( str ) { const pretty = this . clone ( ) ; pretty . _options . separator = str ; return pretty ; } symbol ( str ) { const pretty = this . clone ( ) ; pretty . _options . symbol = str ; return pretty ; } moveDecimalPointLeft ( delta ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . moveDecimalPointLeft ( delta ) ; return pretty ; } moveDecimalPointRight ( delta ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . moveDecimalPointRight ( delta ) ; return pretty ; } maxDecimals ( max ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . maxDecimals ( max ) ; return pretty ; } inequalitySymbol ( bool ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . inequalitySymbol ( bool ) ; return pretty ; } inequalitySymbolSeparator ( str ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . inequalitySymbolSeparator ( str ) ; return pretty ; } trim ( bool ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . trim ( bool ) ; return pretty ; } shrink ( bool ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . shrink ( bool ) ; return pretty ; } locale ( locale ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . locale ( locale ) ; return pretty ; } param bool ready ( bool ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . ready ( bool ) ; return pretty ; } get isReady ( ) : boolean { return this . intPretty . isReady ; } add ( target ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . add ( target ) ; return pretty ; } sub ( target ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . sub ( target ) ; return pretty ; } mul ( target ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . mul ( target ) ; return pretty ; } quo ( target ) { const pretty = this . clone ( ) ; pretty . intPretty = pretty . intPretty . quo ( target ) ; return pretty ; } toDec ( ) { return this . intPretty . toDec ( ) ; } toString ( ) { return this . intPretty . moveDecimalPointRight ( 2 ) . toStringWithSymbols ( "" , `${ this . _options . separator }${ this . _options . symbol }` ) ; } clone ( ) { const pretty = new RatePretty ( this . amount ) ; pretty . _options = { ... this . _options , } ; pretty . intPretty = this . intPretty . clone ( ) ; return pretty ; } }