MCPcopy Create free account
hub / github.com/formatjs/formatjs / getFormatter

Function getFormatter

packages/intl/relativeTime.ts:16–40  ·  view source on GitHub ↗
(
  {
    locale,
    formats,
    onError,
  }: {
    locale: string
    formats: CustomFormats
    onError: OnErrorFn
  },
  getRelativeTimeFormat: Formatters['getRelativeTimeFormat'],
  options: Parameters<IntlFormatters['formatRelativeTime']>[2] = {}
)

Source from the content-addressed store, hash-verified

14> = ['numeric', 'style']
15
16function getFormatter(
17 {
18 locale,
19 formats,
20 onError,
21 }: {
22 locale: string
23 formats: CustomFormats
24 onError: OnErrorFn
25 },
26 getRelativeTimeFormat: Formatters['getRelativeTimeFormat'],
27 options: Parameters<IntlFormatters['formatRelativeTime']>[2] = {}
28): Intl.RelativeTimeFormat {
29 const {format} = options
30
31 const defaults =
32 (!!format && getNamedFormat(formats, 'relative', format, onError)) || {}
33 const filteredOptions = filterProps(
34 options,
35 RELATIVE_TIME_FORMAT_OPTIONS,
36 defaults as Intl.RelativeTimeFormatOptions
37 ) as Intl.RelativeTimeFormatOptions
38
39 return getRelativeTimeFormat(locale, filteredOptions)
40}
41
42export function formatRelativeTime(
43 config: {

Callers 1

formatRelativeTimeFunction · 0.70

Calls 2

getNamedFormatFunction · 0.85
filterPropsFunction · 0.85

Tested by

no test coverage detected