import chalk from 'chalk' ; import { boolish } from 'getenv' ; const isProfiling = boolish ( 'EXPO_PROFILE' , false ) ; const consoleTime = isProfiling ? console . time : ( ) => { } ; const consoleTimeEnd = isProfiling ? console . timeEnd : ( ) => { } ; param fn param functionName export const profileMethod = < T extends any [ ] , U > ( fn , functionName ? ) => { const name = chalk . dim ( `⏱  [profile] ${ functionName ?? ( fn . name || 'unknown' ) }` ) ; return ( ... args ) : U => { consoleTime ( name ) ; const results = fn ( ... args ) ; if ( results instanceof Promise ) { return new Promise < U > ( ( resolve , reject ) => { results . then ( results => { resolve ( results ) ; consoleTimeEnd ( name ) ; } ) . catch ( error => { reject ( error ) ; consoleTimeEnd ( name ) ; } ) ; } ) ; } else { consoleTimeEnd ( name ) ; } return results ; } ; } ;