Variable.resolveRelativeTimeFormat - sumup-oss/intl-js GitHub Wiki

@sumup-oss/intl / resolveRelativeTimeFormat

Variable: resolveRelativeTimeFormat

const resolveRelativeTimeFormat: (locales?, options?) => ResolvedRelativeTimeFormatOptions | null

Defined in: lib/relative-time-format/index.ts:190

Resolves the locale and collation options that are used to format a relative time.

Parameters

Parameter Type Description
locales? string | string[] Formatting locale. Omitting this is deprecated and will become required in a future major version. When omitted, formatting uses the runtime default (browser or server locale), which may not match your user.
options? RelativeTimeFormatOptions -

Returns

ResolvedRelativeTimeFormatOptions | null

Example

import { resolveRelativeTimeFormat } from '@sumup-oss/intl';

resolveRelativeTimeFormat('de-DE');
// {
//   "locale": "de-DE",
//   "numberingSystem": "latn",
//   "numeric": "always",
//   "style": "long",
// }
resolveRelativeTimeFormat(['pt-BR', 'pt']);
// {
//   "locale": "pt-BR",
//   "numberingSystem": "latn",
//   "numeric": "always",
//   "style": "long",
// }
resolveRelativeTimeFormat('en-GB', {
  style: 'narrow',
});
// {
//   "locale": "en-GB",
//   "numberingSystem": "latn",
//   "numeric": "always",
//   "style": "narrow",
// }

Remarks

In runtimes that don't support the Intl.RelativeTimeFormat.resolvedOptions API, null is returned.