1
1
import {
2
2
assign ,
3
+ create ,
3
4
isNumber ,
4
5
isFunction ,
5
6
toDisplayString ,
@@ -16,10 +17,10 @@ type ExtractToStringKey<T> = Extract<keyof T, 'toString'>
16
17
type ExtractToStringFunction < T > = T [ ExtractToStringKey < T > ]
17
18
// prettier-ignore
18
19
type StringConvertable < T > = ExtractToStringKey < T > extends never
19
- ? unknown
20
- : ExtractToStringFunction < T > extends ( ...args : any ) => string // eslint-disable-line @typescript-eslint/no-explicit-any
21
- ? T
22
- : unknown
20
+ ? unknown
21
+ : ExtractToStringFunction < T > extends ( ...args : any ) => string // eslint-disable-line @typescript-eslint/no-explicit-any
22
+ ? T
23
+ : unknown
23
24
24
25
/** @VueI 18nGeneral */
25
26
export type Locale = string
@@ -279,27 +280,27 @@ function pluralDefault(choice: number, choicesLength: number): number {
279
280
if ( choicesLength === 2 ) {
280
281
// prettier-ignore
281
282
return choice
282
- ? choice > 1
283
- ? 1
284
- : 0
285
- : 1
283
+ ? choice > 1
284
+ ? 1
285
+ : 0
286
+ : 1
286
287
}
287
288
return choice ? Math . min ( choice , 2 ) : 0
288
289
}
289
290
290
291
function getPluralIndex < T , N > ( options : MessageContextOptions < T , N > ) : number {
291
292
// prettier-ignore
292
293
const index = isNumber ( options . pluralIndex )
293
- ? options . pluralIndex
294
- : - 1
294
+ ? options . pluralIndex
295
+ : - 1
295
296
// prettier-ignore
296
297
return options . named && ( isNumber ( options . named . count ) || isNumber ( options . named . n ) )
297
- ? isNumber ( options . named . count )
298
- ? options . named . count
299
- : isNumber ( options . named . n )
300
- ? options . named . n
301
- : index
302
- : index
298
+ ? isNumber ( options . named . count )
299
+ ? options . named . count
300
+ : isNumber ( options . named . n )
301
+ ? options . named . n
302
+ : index
303
+ : index
303
304
}
304
305
305
306
function normalizeNamed ( pluralIndex : number , props : PluralizationProps ) : void {
@@ -336,17 +337,17 @@ export function createMessageContext<T = string, N = {}>(
336
337
const list = ( index : number ) : unknown => _list [ index ]
337
338
338
339
// eslint-disable-next-line @typescript-eslint/no-explicit-any
339
- const _named = options . named || ( { } as any )
340
+ const _named = options . named || ( create ( ) as any )
340
341
isNumber ( options . pluralIndex ) && normalizeNamed ( pluralIndex , _named )
341
342
const named = ( key : string ) : unknown => _named [ key ]
342
343
343
344
function message ( key : Path ) : MessageFunction < T > {
344
345
// prettier-ignore
345
346
const msg = isFunction ( options . messages )
346
- ? options . messages ( key )
347
- : isObject ( options . messages )
348
- ? options . messages [ key ]
349
- : false
347
+ ? options . messages ( key )
348
+ : isObject ( options . messages )
349
+ ? options . messages [ key ]
350
+ : false
350
351
return ! msg
351
352
? options . parent
352
353
? options . parent . message ( key ) // resolve from parent messages
@@ -412,7 +413,7 @@ export function createMessageContext<T = string, N = {}>(
412
413
[ HelperNameMap . TYPE ] : type ,
413
414
[ HelperNameMap . INTERPOLATE ] : interpolate ,
414
415
[ HelperNameMap . NORMALIZE ] : normalize ,
415
- [ HelperNameMap . VALUES ] : assign ( { } , _list , _named )
416
+ [ HelperNameMap . VALUES ] : assign ( create ( ) , _list , _named )
416
417
}
417
418
418
419
return ctx
0 commit comments