How to use the @formatjs/intl-utils.invariant function in @formatjs/intl-utils

To help you get started, we’ve selected a few @formatjs/intl-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github formatjs / react-intl / src / formatters / message.ts View on Github external
| 'defaultLocale'
    | 'defaultFormats'
    | 'onError'
    | 'timeZone'
  >,
  state: Formatters,
  messageDescriptor: MessageDescriptor = {id: ''},
  values: Record<
    string,
    PrimitiveType | React.ReactElement | FormatXMLElementFn
  > = {}
): string | React.ReactNodeArray {
  const {id, defaultMessage} = messageDescriptor;

  // `id` is a required field of a Message Descriptor.
  invariant(!!id, '[React Intl] An `id` must be provided to format a message.');
  const message = messages && messages[id];
  formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
  defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);

  let formattedMessageParts: Array = [];

  if (message) {
    try {
      const formatter = state.getMessageFormat(message, locale, formats, {
        formatters: state,
      });

      formattedMessageParts = formatter.formatHTMLMessage(values);
    } catch (e) {
      onError(
        createError(
github formatjs / react-intl / src / components / relative.tsx View on Github external
constructor(props: Props) {
    super(props);
    invariant(
      !props.updateIntervalInSeconds || !!(props.updateIntervalInSeconds && canIncrement(props.unit)),
      'Cannot schedule update with unit longer than hour'
    );
  }
github formatjs / react-intl / src / utils.ts View on Github external
export function invariantIntlContext(intl?: any): asserts intl {
  invariant(
    intl,
    '[React Intl] Could not find required `intl` object. ' +
      ' needs to exist in the component ancestry.'
  );
}