react-intl
Advanced tools
Comparing version 6.5.5 to 6.6.0
@@ -8,3 +8,4 @@ import * as React from 'react'; | ||
import useIntl from './src/components/useIntl'; | ||
import IntlProvider, { createIntl } from './src/components/provider'; | ||
import IntlProvider from './src/components/provider'; | ||
import { createIntl } from './src/components/createIntl'; | ||
import FormattedRelativeTime from './src/components/relative'; | ||
@@ -11,0 +12,0 @@ import FormattedPlural from './src/components/plural'; |
@@ -12,5 +12,6 @@ "use strict"; | ||
exports.useIntl = useIntl_1.default; | ||
var provider_1 = tslib_1.__importStar(require("./src/components/provider")); | ||
var provider_1 = tslib_1.__importDefault(require("./src/components/provider")); | ||
exports.IntlProvider = provider_1.default; | ||
Object.defineProperty(exports, "createIntl", { enumerable: true, get: function () { return provider_1.createIntl; } }); | ||
var createIntl_1 = require("./src/components/createIntl"); | ||
Object.defineProperty(exports, "createIntl", { enumerable: true, get: function () { return createIntl_1.createIntl; } }); | ||
var relative_1 = tslib_1.__importDefault(require("./src/components/relative")); | ||
@@ -17,0 +18,0 @@ exports.FormattedRelativeTime = relative_1.default; |
@@ -8,3 +8,4 @@ import * as React from 'react'; | ||
import useIntl from './src/components/useIntl'; | ||
import IntlProvider, { createIntl } from './src/components/provider'; | ||
import IntlProvider from './src/components/provider'; | ||
import { createIntl } from './src/components/createIntl'; | ||
import FormattedRelativeTime from './src/components/relative'; | ||
@@ -11,0 +12,0 @@ import FormattedPlural from './src/components/plural'; |
import { createFormattedComponent, createFormattedDateTimePartsComponent, } from './src/components/createFormattedComponent'; | ||
import injectIntl, { Provider as RawIntlProvider, Context as IntlContext, } from './src/components/injectIntl'; | ||
import useIntl from './src/components/useIntl'; | ||
import IntlProvider, { createIntl } from './src/components/provider'; | ||
import IntlProvider from './src/components/provider'; | ||
import { createIntl } from './src/components/createIntl'; | ||
import FormattedRelativeTime from './src/components/relative'; | ||
@@ -6,0 +7,0 @@ import FormattedPlural from './src/components/plural'; |
@@ -22,6 +22,3 @@ /* | ||
}; | ||
FormattedPlural.defaultProps = { | ||
type: 'cardinal', | ||
}; | ||
FormattedPlural.displayName = 'FormattedPlural'; | ||
export default FormattedPlural; |
@@ -1,4 +0,4 @@ | ||
import { CreateIntlFn, IntlCache } from '@formatjs/intl'; | ||
import { IntlCache } from '@formatjs/intl'; | ||
import * as React from 'react'; | ||
import type { IntlConfig, IntlShape, ResolvedIntlConfig } from '../types'; | ||
import type { IntlConfig, IntlShape } from '../types'; | ||
interface State { | ||
@@ -20,11 +20,5 @@ /** | ||
} | ||
/** | ||
* Create intl object | ||
* @param config intl config | ||
* @param cache cache for formatter instances to prevent memory leak | ||
*/ | ||
export declare const createIntl: CreateIntlFn<React.ReactNode, IntlConfig, IntlShape>; | ||
export default class IntlProvider extends React.PureComponent<React.PropsWithChildren<IntlConfig>, State> { | ||
static displayName: string; | ||
static defaultProps: Pick<ResolvedIntlConfig, "timeZone" | "onError" | "fallbackOnEmptyString" | "formats" | "messages" | "defaultLocale" | "defaultFormats" | "textComponent">; | ||
static defaultProps: Pick<import("../types").ResolvedIntlConfig, "timeZone" | "onError" | "fallbackOnEmptyString" | "formats" | "messages" | "defaultLocale" | "defaultFormats" | "textComponent">; | ||
private cache; | ||
@@ -31,0 +25,0 @@ state: State; |
@@ -6,8 +6,8 @@ /* | ||
*/ | ||
import { __assign, __extends, __rest, __spreadArray } from "tslib"; | ||
import { createIntl as coreCreateIntl, formatMessage as coreFormatMessage, createIntlCache, } from '@formatjs/intl'; | ||
import { __extends } from "tslib"; | ||
import { createIntlCache } from '@formatjs/intl'; | ||
import * as React from 'react'; | ||
import { DEFAULT_INTL_CONFIG, assignUniqueKeysToParts, invariantIntlContext, shallowEqual, } from '../utils'; | ||
import { DEFAULT_INTL_CONFIG, invariantIntlContext, shallowEqual } from '../utils'; | ||
import { Provider } from './injectIntl'; | ||
import { isFormatXMLElementFn, } from 'intl-messageformat'; | ||
import { createIntl } from './createIntl'; | ||
function processIntlConfig(config) { | ||
@@ -29,55 +29,2 @@ return { | ||
} | ||
function assignUniqueKeysToFormatXMLElementFnArgument(values) { | ||
if (!values) { | ||
return values; | ||
} | ||
return Object.keys(values).reduce(function (acc, k) { | ||
var v = values[k]; | ||
acc[k] = isFormatXMLElementFn(v) | ||
? assignUniqueKeysToParts(v) | ||
: v; | ||
return acc; | ||
}, {}); | ||
} | ||
var formatMessage = function (config, formatters, descriptor, rawValues) { | ||
var rest = []; | ||
for (var _i = 4; _i < arguments.length; _i++) { | ||
rest[_i - 4] = arguments[_i]; | ||
} | ||
var values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues); | ||
var chunks = coreFormatMessage.apply(void 0, __spreadArray([config, | ||
formatters, | ||
descriptor, | ||
values], rest, false)); | ||
if (Array.isArray(chunks)) { | ||
return React.Children.toArray(chunks); | ||
} | ||
return chunks; | ||
}; | ||
/** | ||
* Create intl object | ||
* @param config intl config | ||
* @param cache cache for formatter instances to prevent memory leak | ||
*/ | ||
export var createIntl = function (_a, cache) { | ||
var rawDefaultRichTextElements = _a.defaultRichTextElements, config = __rest(_a, ["defaultRichTextElements"]); | ||
var defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(rawDefaultRichTextElements); | ||
var coreIntl = coreCreateIntl(__assign(__assign(__assign({}, DEFAULT_INTL_CONFIG), config), { defaultRichTextElements: defaultRichTextElements }), cache); | ||
var resolvedConfig = { | ||
locale: coreIntl.locale, | ||
timeZone: coreIntl.timeZone, | ||
fallbackOnEmptyString: coreIntl.fallbackOnEmptyString, | ||
formats: coreIntl.formats, | ||
defaultLocale: coreIntl.defaultLocale, | ||
defaultFormats: coreIntl.defaultFormats, | ||
messages: coreIntl.messages, | ||
onError: coreIntl.onError, | ||
defaultRichTextElements: defaultRichTextElements, | ||
}; | ||
return __assign(__assign({}, coreIntl), { formatMessage: formatMessage.bind(null, resolvedConfig, | ||
// @ts-expect-error fix this | ||
coreIntl.formatters), | ||
// @ts-expect-error fix this | ||
$t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters) }); | ||
}; | ||
var IntlProvider = /** @class */ (function (_super) { | ||
@@ -84,0 +31,0 @@ __extends(IntlProvider, _super); |
@@ -73,8 +73,8 @@ import { __assign, __rest } from "tslib"; | ||
var FormattedRelativeTime = function (_a) { | ||
var value = _a.value, unit = _a.unit, updateIntervalInSeconds = _a.updateIntervalInSeconds, otherProps = __rest(_a, ["value", "unit", "updateIntervalInSeconds"]); | ||
var _b = _a.value, value = _b === void 0 ? 0 : _b, _c = _a.unit, unit = _c === void 0 ? 'second' : _c, updateIntervalInSeconds = _a.updateIntervalInSeconds, otherProps = __rest(_a, ["value", "unit", "updateIntervalInSeconds"]); | ||
invariant(!updateIntervalInSeconds || | ||
!!(updateIntervalInSeconds && canIncrement(unit)), 'Cannot schedule update with unit longer than hour'); | ||
var _b = React.useState(), prevUnit = _b[0], setPrevUnit = _b[1]; | ||
var _c = React.useState(0), prevValue = _c[0], setPrevValue = _c[1]; | ||
var _d = React.useState(0), currentValueInSeconds = _d[0], setCurrentValueInSeconds = _d[1]; | ||
var _d = React.useState(), prevUnit = _d[0], setPrevUnit = _d[1]; | ||
var _e = React.useState(0), prevValue = _e[0], setPrevValue = _e[1]; | ||
var _f = React.useState(0), currentValueInSeconds = _f[0], setCurrentValueInSeconds = _f[1]; | ||
var updateTimer; | ||
@@ -126,6 +126,2 @@ if (unit !== prevUnit || value !== prevValue) { | ||
FormattedRelativeTime.displayName = 'FormattedRelativeTime'; | ||
FormattedRelativeTime.defaultProps = { | ||
value: 0, | ||
unit: 'second', | ||
}; | ||
export default FormattedRelativeTime; |
{ | ||
"name": "react-intl", | ||
"version": "6.5.5", | ||
"version": "6.6.0", | ||
"description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.", | ||
@@ -135,16 +135,16 @@ "keywords": [ | ||
"tslib": "^2.4.0", | ||
"@formatjs/ecma402-abstract": "1.18.0", | ||
"@formatjs/intl-displaynames": "6.6.4", | ||
"@formatjs/intl": "2.9.9", | ||
"@formatjs/icu-messageformat-parser": "2.7.3", | ||
"@formatjs/intl-listformat": "7.5.3", | ||
"intl-messageformat": "10.5.8" | ||
"@formatjs/ecma402-abstract": "1.18.1", | ||
"@formatjs/intl": "2.9.10", | ||
"@formatjs/icu-messageformat-parser": "2.7.4", | ||
"@formatjs/intl-displaynames": "6.6.5", | ||
"intl-messageformat": "10.5.9", | ||
"@formatjs/intl-listformat": "7.5.4" | ||
}, | ||
"devDependencies": { | ||
"@formatjs/intl-relativetimeformat": "11.2.10", | ||
"@formatjs/intl-numberformat": "8.9.0" | ||
"@formatjs/intl-numberformat": "8.9.1", | ||
"@formatjs/intl-relativetimeformat": "11.2.11" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.6.0 || 17 || 18", | ||
"typescript": "5" | ||
"typescript": "^4.7 || 5" | ||
}, | ||
@@ -151,0 +151,0 @@ "peerDependenciesMeta": { |
@@ -25,6 +25,3 @@ "use strict"; | ||
}; | ||
FormattedPlural.defaultProps = { | ||
type: 'cardinal', | ||
}; | ||
FormattedPlural.displayName = 'FormattedPlural'; | ||
exports.default = FormattedPlural; |
@@ -1,4 +0,4 @@ | ||
import { CreateIntlFn, IntlCache } from '@formatjs/intl'; | ||
import { IntlCache } from '@formatjs/intl'; | ||
import * as React from 'react'; | ||
import type { IntlConfig, IntlShape, ResolvedIntlConfig } from '../types'; | ||
import type { IntlConfig, IntlShape } from '../types'; | ||
interface State { | ||
@@ -20,11 +20,5 @@ /** | ||
} | ||
/** | ||
* Create intl object | ||
* @param config intl config | ||
* @param cache cache for formatter instances to prevent memory leak | ||
*/ | ||
export declare const createIntl: CreateIntlFn<React.ReactNode, IntlConfig, IntlShape>; | ||
export default class IntlProvider extends React.PureComponent<React.PropsWithChildren<IntlConfig>, State> { | ||
static displayName: string; | ||
static defaultProps: Pick<ResolvedIntlConfig, "timeZone" | "onError" | "fallbackOnEmptyString" | "formats" | "messages" | "defaultLocale" | "defaultFormats" | "textComponent">; | ||
static defaultProps: Pick<import("../types").ResolvedIntlConfig, "timeZone" | "onError" | "fallbackOnEmptyString" | "formats" | "messages" | "defaultLocale" | "defaultFormats" | "textComponent">; | ||
private cache; | ||
@@ -31,0 +25,0 @@ state: State; |
@@ -8,3 +8,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createIntl = void 0; | ||
var tslib_1 = require("tslib"); | ||
@@ -15,3 +14,3 @@ var intl_1 = require("@formatjs/intl"); | ||
var injectIntl_1 = require("./injectIntl"); | ||
var intl_messageformat_1 = require("intl-messageformat"); | ||
var createIntl_1 = require("./createIntl"); | ||
function processIntlConfig(config) { | ||
@@ -33,56 +32,2 @@ return { | ||
} | ||
function assignUniqueKeysToFormatXMLElementFnArgument(values) { | ||
if (!values) { | ||
return values; | ||
} | ||
return Object.keys(values).reduce(function (acc, k) { | ||
var v = values[k]; | ||
acc[k] = (0, intl_messageformat_1.isFormatXMLElementFn)(v) | ||
? (0, utils_1.assignUniqueKeysToParts)(v) | ||
: v; | ||
return acc; | ||
}, {}); | ||
} | ||
var formatMessage = function (config, formatters, descriptor, rawValues) { | ||
var rest = []; | ||
for (var _i = 4; _i < arguments.length; _i++) { | ||
rest[_i - 4] = arguments[_i]; | ||
} | ||
var values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues); | ||
var chunks = intl_1.formatMessage.apply(void 0, tslib_1.__spreadArray([config, | ||
formatters, | ||
descriptor, | ||
values], rest, false)); | ||
if (Array.isArray(chunks)) { | ||
return React.Children.toArray(chunks); | ||
} | ||
return chunks; | ||
}; | ||
/** | ||
* Create intl object | ||
* @param config intl config | ||
* @param cache cache for formatter instances to prevent memory leak | ||
*/ | ||
var createIntl = function (_a, cache) { | ||
var rawDefaultRichTextElements = _a.defaultRichTextElements, config = tslib_1.__rest(_a, ["defaultRichTextElements"]); | ||
var defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(rawDefaultRichTextElements); | ||
var coreIntl = (0, intl_1.createIntl)(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, utils_1.DEFAULT_INTL_CONFIG), config), { defaultRichTextElements: defaultRichTextElements }), cache); | ||
var resolvedConfig = { | ||
locale: coreIntl.locale, | ||
timeZone: coreIntl.timeZone, | ||
fallbackOnEmptyString: coreIntl.fallbackOnEmptyString, | ||
formats: coreIntl.formats, | ||
defaultLocale: coreIntl.defaultLocale, | ||
defaultFormats: coreIntl.defaultFormats, | ||
messages: coreIntl.messages, | ||
onError: coreIntl.onError, | ||
defaultRichTextElements: defaultRichTextElements, | ||
}; | ||
return tslib_1.__assign(tslib_1.__assign({}, coreIntl), { formatMessage: formatMessage.bind(null, resolvedConfig, | ||
// @ts-expect-error fix this | ||
coreIntl.formatters), | ||
// @ts-expect-error fix this | ||
$t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters) }); | ||
}; | ||
exports.createIntl = createIntl; | ||
var IntlProvider = /** @class */ (function (_super) { | ||
@@ -95,3 +40,3 @@ tslib_1.__extends(IntlProvider, _super); | ||
cache: _this.cache, | ||
intl: (0, exports.createIntl)(processIntlConfig(_this.props), _this.cache), | ||
intl: (0, createIntl_1.createIntl)(processIntlConfig(_this.props), _this.cache), | ||
prevConfig: processIntlConfig(_this.props), | ||
@@ -106,3 +51,3 @@ }; | ||
return { | ||
intl: (0, exports.createIntl)(config, cache), | ||
intl: (0, createIntl_1.createIntl)(config, cache), | ||
prevConfig: config, | ||
@@ -109,0 +54,0 @@ }; |
@@ -75,8 +75,8 @@ "use strict"; | ||
var FormattedRelativeTime = function (_a) { | ||
var value = _a.value, unit = _a.unit, updateIntervalInSeconds = _a.updateIntervalInSeconds, otherProps = tslib_1.__rest(_a, ["value", "unit", "updateIntervalInSeconds"]); | ||
var _b = _a.value, value = _b === void 0 ? 0 : _b, _c = _a.unit, unit = _c === void 0 ? 'second' : _c, updateIntervalInSeconds = _a.updateIntervalInSeconds, otherProps = tslib_1.__rest(_a, ["value", "unit", "updateIntervalInSeconds"]); | ||
(0, ecma402_abstract_1.invariant)(!updateIntervalInSeconds || | ||
!!(updateIntervalInSeconds && canIncrement(unit)), 'Cannot schedule update with unit longer than hour'); | ||
var _b = React.useState(), prevUnit = _b[0], setPrevUnit = _b[1]; | ||
var _c = React.useState(0), prevValue = _c[0], setPrevValue = _c[1]; | ||
var _d = React.useState(0), currentValueInSeconds = _d[0], setCurrentValueInSeconds = _d[1]; | ||
var _d = React.useState(), prevUnit = _d[0], setPrevUnit = _d[1]; | ||
var _e = React.useState(0), prevValue = _e[0], setPrevValue = _e[1]; | ||
var _f = React.useState(0), currentValueInSeconds = _f[0], setCurrentValueInSeconds = _f[1]; | ||
var updateTimer; | ||
@@ -128,6 +128,2 @@ if (unit !== prevUnit || value !== prevValue) { | ||
FormattedRelativeTime.displayName = 'FormattedRelativeTime'; | ||
FormattedRelativeTime.defaultProps = { | ||
value: 0, | ||
unit: 'second', | ||
}; | ||
exports.default = FormattedRelativeTime; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
241032
52
6343
7
1
21
+ Added@formatjs/ecma402-abstract@1.18.1(transitive)
+ Added@formatjs/icu-messageformat-parser@2.7.4(transitive)
+ Added@formatjs/icu-skeleton-parser@1.7.1(transitive)
+ Added@formatjs/intl@2.9.10(transitive)
+ Added@formatjs/intl-displaynames@6.6.5(transitive)
+ Added@formatjs/intl-listformat@7.5.4(transitive)
+ Added@formatjs/intl-localematcher@0.5.3(transitive)
+ Addedintl-messageformat@10.5.9(transitive)
- Removed@formatjs/ecma402-abstract@1.18.0(transitive)
- Removed@formatjs/icu-messageformat-parser@2.7.3(transitive)
- Removed@formatjs/icu-skeleton-parser@1.7.0(transitive)
- Removed@formatjs/intl@2.9.9(transitive)
- Removed@formatjs/intl-displaynames@6.6.4(transitive)
- Removed@formatjs/intl-listformat@7.5.3(transitive)
- Removed@formatjs/intl-localematcher@0.5.2(transitive)
- Removedintl-messageformat@10.5.8(transitive)
Updated@formatjs/intl@2.9.10
Updatedintl-messageformat@10.5.9