@@ -42,6 +42,11 @@ import { warn, isString, isBoolean, isPlainObject, isNumber } from '../utils'
4242 *
4343 * // if you specify `part` options, you can get an array of objects containing the formatted number in parts
4444 * number(context, value, { key: 'currenty', part: true })
45+ *
46+ * // orverride context.numberFormats[locale] options with functino options
47+ * number(cnotext, value, 'currency', { currency: 'EUR' })
48+ * number(cnotext, value, 'currency', 'ja-JP', { currency: 'EUR' })
49+ * number(context, value, { key: 'currenty', part: true }, { currency: 'EUR'})
4550 */
4651
4752export type NumberOptions = {
@@ -95,7 +100,7 @@ export function number(
95100 return MISSING_RESOLVE_VALUE
96101 }
97102
98- const [ value , options ] = parseNumberArgs ( ...args )
103+ const [ value , options , orverrides ] = parseNumberArgs ( ...args )
99104 const { key } = options
100105 const missingWarn = isBoolean ( options . missingWarn )
101106 ? options . missingWarn
@@ -137,18 +142,24 @@ export function number(
137142 return unresolving ? NOT_REOSLVED : key
138143 }
139144
140- const id = `${ targetLocale } __${ key } `
145+ const id = `${ targetLocale } __${ key } __ ${ JSON . stringify ( orverrides ) } `
141146 let formatter = _numberFormatters . get ( id )
142147 if ( ! formatter ) {
143- formatter = new Intl . NumberFormat ( targetLocale , format )
148+ formatter = new Intl . NumberFormat (
149+ targetLocale ,
150+ Object . assign ( { } , format , orverrides )
151+ )
144152 _numberFormatters . set ( id , formatter )
145153 }
146154 return ! part ? formatter . format ( value ) : formatter . formatToParts ( value )
147155}
148156
149- export function parseNumberArgs ( ...args : unknown [ ] ) : [ number , NumberOptions ] {
150- const [ arg1 , arg2 , arg3 ] = args
157+ export function parseNumberArgs (
158+ ...args : unknown [ ]
159+ ) : [ number , NumberOptions , Intl . NumberFormatOptions ] {
160+ const [ arg1 , arg2 , arg3 , arg4 ] = args
151161 let options = { } as NumberOptions
162+ let orverrides = { } as Intl . NumberFormatOptions
152163
153164 if ( ! isNumber ( arg1 ) ) {
154165 throw new Error ( 'TODO' )
@@ -163,9 +174,15 @@ export function parseNumberArgs(...args: unknown[]): [number, NumberOptions] {
163174
164175 if ( isString ( arg3 ) ) {
165176 options . locale = arg3
177+ } else if ( isPlainObject ( arg3 ) ) {
178+ orverrides = arg3
179+ }
180+
181+ if ( isPlainObject ( arg4 ) ) {
182+ orverrides = arg4
166183 }
167184
168- return [ value , options ]
185+ return [ value , options , orverrides ]
169186}
170187
171188export function clearNumberFormat (
0 commit comments