import merge from './core/utils/merge' ; import isObject from './core/utils/is-object' ; import isString from './core/utils/is-string' ; import isFunction from './core/utils/is-function' ; import { NumerableLocale } from './locale/types/numerable-locale' ; import formatFunctionFromSourceCode from './formatter/format/format' ; import { NumerableFormatNumberOptions } from './formatter/types/format-number-options' ; example param number param pattern param options function format ( number , pattern , options ? ) ; function format ( number , options ) ; function format ( number ) ; function format ( number , arg2 ? , arg3 ? ) { const pattern = isString ( arg2 ) ? arg2 : null ; const options = isObject ( arg2 ) ? arg2 : ( isObject ( arg3 ) ? arg3 : { } ) ; return formatFunctionFromSourceCode ( number , pattern , options ) ; } interface NumerableFormatNumberWithOptionsOptions extends Omit < NumerableFormatNumberOptions , 'locale' > { locale ? : NumerableLocale | string | ( ( ) => NumerableLocale | string ) ; } export const createFormatFunction = ( options ) : typeof format => { const baseOptions = merge ( options , { locale : isFunction ( options . locale ) ? options . locale ( ) : options . locale , } ) ; return ( ( value , arg2 ? , arg3 ? ) => { const pattern = isString ( arg2 ) ? arg2 : null ; const optionsFromArguments = isObject ( arg2 ) ? arg2 : ( isObject ( arg3 ) ? arg3 : { } ) ; return formatFunctionFromSourceCode ( value , pattern , merge ( baseOptions , optionsFromArguments ) ) ; } ) as any ; } ; format . withOptions = createFormatFunction ; export default format ;