Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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);
}
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
static getLocalizedRelativeDate(date, options) {
const lang = this.getLanguage();
const formater = new IntlRelativeFormat(lang, options);
return formater.format(new Date(date), options);
}