How to use the intl-relativeformat function in intl-relativeformat

To help you get started, we’ve selected a few intl-relativeformat 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 magicshifter / MS3000-Firmware / React / FirstIteration / src / client / intl / store.js View on Github external
import IntlMessageFormat from 'intl-messageformat';
import IntlRelativeFormat from 'intl-relativeformat';
import {i18nCursor} from '../state';
import {register} from '../dispatcher';
import {List, Map} from 'immutable';

const cachedInstances = Object.create(null);
const intlRelativeFormat = new IntlRelativeFormat;

function getCachedInstanceOf(message) {
  if (message in cachedInstances)
    return cachedInstances[message];

  // TODO: Add locales support.
  cachedInstances[message] = new IntlMessageFormat(message);
  return cachedInstances[message];
}

export function msg(path, values = null): string {
  const pathParts = ['messages'].concat(path.split('.'));
  const message = i18nCursor(pathParts);

  if (message == null) {
    throw new ReferenceError('Could not find Intl message: ' + path);
github este / este / src / common / intl / format.js View on Github external
import IntlMessageFormat from 'intl-messageformat';
import IntlRelativeFormat from 'intl-relativeformat';

// TODO: Memoize all.
const cachedFormatters = Object.create(null);
const intlRelativeFormat = new IntlRelativeFormat;

function getCachedFormatter(message) {
  if (message in cachedFormatters) return cachedFormatters[message];
  cachedFormatters[message] = new IntlMessageFormat(message);
  return cachedFormatters[message];
}

export function format(msg, options = null) {
  if (!options) return msg;
  return getCachedFormatter(msg).format(options);
}

export function dateFormat(date, locales, options) {
  const dateTimeFormat = new Intl.DateTimeFormat(locales, options); // eslint-disable-line no-undef
  return dateTimeFormat.format(date);
}
github hiroppy / fusuma / packages / client / src / components / CommentsList.js View on Github external
import React, { memo, useState, useEffect } from 'react';
import posed, { PoseGroup } from 'react-pose';
import IntlRelativeFormat from 'intl-relativeformat';
import '../../assets/style/commentsList.css';

const Ul = posed.ul({});
const Li = posed.li({
  enter: { opacity: 1 },
  exit: { opacity: 0 }
});
const rf = new IntlRelativeFormat();
let ws;

export const CommentsList = memo(() => {
  const [comments, updateComments] = useState([]);

  useEffect(() => {
    if (!ws) {
      ws = new WebSocket(`ws://${window.location.hostname}:${process.env.SERVER_PORT}`);
      ws.onmessage = ({ data }) => {
        const fetchedComments = JSON.parse(data);

        if (Array.isArray(fetchedComments) && fetchedComments.length !== 0) {
          if (fetchedComments[0].message === 'Rate limit exceeded') {
            // TODO: implement
          } else if (fetchedComments[0].message === 'hello:)') {
            // TODO: implement
github bitnami-labs / cabin / src / utils / LocalesUtils.js View on Github external
static getLocalizedRelativeDate(date, options) {
    const lang = this.getLanguage();
    const formater = new IntlRelativeFormat(lang, options);
    return formater.format(new Date(date), options);
  }

intl-relativeformat

Formats JavaScript dates to relative time strings.

BSD-3-Clause
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis