| 103 | ]; |
| 104 | |
| 105 | export function buildLocalizeFn< |
| 106 | Value extends LocaleUnitValue, |
| 107 | ArgCallback extends LocalizeFnArgCallback<Value> | undefined, |
| 108 | >(args: BuildLocalizeFnArgs<Value, ArgCallback>): LocalizeFn<Value> { |
| 109 | return (value, options) => { |
| 110 | const context = options?.context ? String(options.context) : class="st">"standalone"; |
| 111 | |
| 112 | let valuesArray: LocalizeValues<Value>; |
| 113 | if (context === class="st">"formatting" && args.formattingValues) { |
| 114 | const defaultWidth = args.defaultFormattingWidth || args.defaultWidth; |
| 115 | const width = ( |
| 116 | options?.width ? String(options.width) : defaultWidth |
| 117 | ) as LocaleWidth; |
| 118 | valuesArray = (args.formattingValues[width] || |
| 119 | args.formattingValues[defaultWidth]) as LocalizeValues<Value>; |
| 120 | } else { |
| 121 | const defaultWidth = args.defaultWidth; |
| 122 | const width = ( |
| 123 | options?.width ? String(options.width) : args.defaultWidth |
| 124 | ) as LocaleWidth; |
| 125 | valuesArray = (args.values[width] || |
| 126 | args.values[defaultWidth]) as LocalizeValues<Value>; |
| 127 | } |
| 128 | const index = ( |
| 129 | args.argumentCallback ? args.argumentCallback(value as Value) : value |
| 130 | ) as LocalizeUnitIndex<Value>; |
| 131 | class="cm">// @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it! |
| 132 | return valuesArray[index]; |
| 133 | }; |
| 134 | } |