MCPcopy
hub / github.com/date-fns/date-fns / buildLocalizeFn

Function buildLocalizeFn

pkgs/core/src/locale/_lib/buildLocalizeFn/index.ts:105–134  ·  pkgs/core/src/locale/_lib/buildLocalizeFn/index.ts::buildLocalizeFn
(args: BuildLocalizeFnArgs<Value, ArgCallback>)

Source from the content-addressed store, hash-verified

103];
104
105export 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}

Callers 15

index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
index.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected