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
it('delegates to IntlRelativeFormat', () => {
emptyLocaleData();
expect(registry.hasLocaleData('en')).toBe(false);
IntlRelativeFormat.__addLocaleData(IRF_LOCALE_DATA.en);
expect(registry.hasLocaleData('en')).toBe(true);
});
const emptyLocaleData = () => {
const emptyObject = (obj) => {
Object.keys(obj).forEach((prop) => delete obj[prop]);
};
emptyObject(IntlRelativeFormat.__localeData__);
};
const restoreLocaleData = () => {
emptyLocaleData();
Object.assign(IntlRelativeFormat.__localeData__, IRF_LOCALE_DATA);
};
describe('locale data registry', () => {
const IRF_LOCALE_DATA = {...IntlRelativeFormat.__localeData__};
const emptyLocaleData = () => {
const emptyObject = (obj) => {
Object.keys(obj).forEach((prop) => delete obj[prop]);
};
emptyObject(IntlRelativeFormat.__localeData__);
};
const restoreLocaleData = () => {
emptyLocaleData();
Object.assign(IntlRelativeFormat.__localeData__, IRF_LOCALE_DATA);
};
afterEach(() => {
restoreLocaleData();
function hasIMFAndIRFLocaleData(locale) {
let normalizedLocale = locale && locale.toLowerCase();
return !!IntlRelativeFormat.__localeData__[normalizedLocale];
}
static getLocalizedRelativeDate(date, options) {
const lang = this.getLanguage();
const formater = new IntlRelativeFormat(lang, options);
return formater.format(new Date(date), options);
}
export function addLocaleData(data = []) {
let locales = Array.isArray(data) ? data : [data];
IntlRelativeFormat.__addLocaleData(...locales.filter(l => !!l.locale));
}