import { BigNumber } from 'ethers' ; import { isPojo } from './serdes' ; const timeWords = [ null , 'once' , 'twice' , 'thrice' ] ; export function humanizeTimes ( count ) { return timeWords [ count ] || `${ count || 0 } times` ; } param obj param prefix param result returns export function flatten ( obj , prefix = '' , result = { } ) { return Object . entries ( obj ) . reduce ( ( acc , [ key , val ] ) => { const subKey = `${ prefix }${ key }` ; if ( BigNumber . isBigNumber ( val ) || typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' ) { result [ subKey ] = val ; } else if ( Array . isArray ( val ) ) { val . forEach ( ( valItem , index ) => flatten ( valItem , ! prefix ? `${ index }` : `${ prefix }${ index }.` , acc ) ) ; } else if ( isPojo ( val ) ) { flatten ( val , `${ subKey }.` , acc ) ; } else { throw new Error ( 'Cannot flatten unsupported object type' ) ; } return acc ; } , result ) ; }