How to use @formatjs/intl-utils - 10 common examples

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 alephdata / aleph / ui / src / components / Notification / Notification.jsx View on Github external
// TODO: Could be done with Array.prototype.reducer very nicely
    parts.forEach((token) => {
      if (token === '{{') {
        paramActive = true;
      } else if (token === '}}') {
        paramActive = false;
      } else if (paramActive) {
        const param = this.getParam(token);
        message.push((<span>{param}</span>));
      } else {
        message.push(token);
      }
    });

    const createdDate = this.convertUTCDateToLocalDate(new Date(createdAt));
    const { value, unit } = selectUnit(createdDate, Date.now());
    return (
      <li>
        <div>
          
        </div>
        {message}
      </li>
    );
  }
}
github itchio / itch / src / renderer / basics / TimeAgo.tsx View on Github external
export const TimeAgo = (props: Props) =&gt; {
  const { className, before, date } = props;

  let dateNumber: number = typeof date === "number" ? date : +new Date(date);
  let dateString: string =
    typeof date === "number" ? new Date(date).toISOString() : date;
  const { value, unit } = selectUnit(dateNumber);

  // TODO: since we're passing a relative value, do we need to update it
  // ourselves now? If so, do we want to? Using hooks maybe?
  // TODO: review react-hint usage
  return (
    <span title="{dateString}">
      {before ? &lt;&gt;{before}  : null}
      
    </span>
  );
};
github formatjs / react-intl / src / formatters / message.ts View on Github external
| 'defaultLocale'
    | 'defaultFormats'
    | 'onError'
    | 'timeZone'
  &gt;,
  state: Formatters,
  messageDescriptor: MessageDescriptor = {id: ''},
  values: Record&lt;
    string,
    PrimitiveType | React.ReactElement | FormatXMLElementFn
  &gt; = {}
): 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 &amp;&amp; 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 zeit / next.js / examples / with-react-intl / pages / about.js View on Github external
export default () =&gt; {
  const { value, unit } = selectUnit(Date.now())
  return (
    
      <p>
        
      </p>
    
  )
}
github ia-toki / judgels / judgels-frontends / raphael / src / components / FormattedRelative / FormattedRelative.tsx View on Github external
export const FormattedRelative = (props: FormattedRelativeProps) =&gt; {
  const { value, unit } = selectUnit(props.value);
  return ;
};