react-intl 8.0.9 → 8.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils.js CHANGED
@@ -1,69 +1,71 @@
1
- import { __assign } from "tslib";
2
- import * as React from 'react';
3
- import { DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG } from '@formatjs/intl';
4
- export function invariant(condition, message, Err) {
5
- if (Err === void 0) { Err = Error; }
6
- if (!condition) {
7
- throw new Err(message);
8
- }
1
+ import "intl-messageformat";
2
+ import * as React from "react";
3
+ import "./types.js";
4
+ import { DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG } from "@formatjs/intl";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ export function invariant(condition, message, Err = Error) {
7
+ if (!condition) {
8
+ throw new Err(message);
9
+ }
9
10
  }
10
11
  export function invariantIntlContext(intl) {
11
- invariant(intl, '[React Intl] Could not find required `intl` object. ' +
12
- '<IntlProvider> needs to exist in the component ancestry.');
12
+ invariant(intl, "[React Intl] Could not find required `intl` object. " + "<IntlProvider> needs to exist in the component ancestry.");
13
13
  }
14
- export var DEFAULT_INTL_CONFIG = __assign(__assign({}, CORE_DEFAULT_INTL_CONFIG), { textComponent: React.Fragment });
14
+ export const DEFAULT_INTL_CONFIG = {
15
+ ...CORE_DEFAULT_INTL_CONFIG,
16
+ textComponent: React.Fragment
17
+ };
15
18
  /**
16
- * Builds an array of {@link React.ReactNode}s with index-based keys, similar to
17
- * {@link React.Children.toArray}. However, this function tells React that it
18
- * was intentional, so they won't produce a bunch of warnings about it.
19
- *
20
- * React doesn't recommend doing this because it makes reordering inefficient,
21
- * but we mostly need this for message chunks, which don't tend to reorder to
22
- * begin with.
23
- *
24
- */
25
- export var toKeyedReactNodeArray = function (children) {
26
- var childrenArray = React.Children.toArray(children);
27
- return childrenArray.map(function (child, index) {
28
- // For React elements, wrap in a keyed Fragment
29
- // This creates a new element with a key rather than trying to add one after creation
30
- if (React.isValidElement(child)) {
31
- return React.createElement(React.Fragment, { key: index }, child);
32
- }
33
- return child;
34
- });
19
+ * Builds an array of {@link React.ReactNode}s with index-based keys, similar to
20
+ * {@link React.Children.toArray}. However, this function tells React that it
21
+ * was intentional, so they won't produce a bunch of warnings about it.
22
+ *
23
+ * React doesn't recommend doing this because it makes reordering inefficient,
24
+ * but we mostly need this for message chunks, which don't tend to reorder to
25
+ * begin with.
26
+ *
27
+ */
28
+ export const toKeyedReactNodeArray = (children) => {
29
+ const childrenArray = React.Children.toArray(children);
30
+ return childrenArray.map((child, index) => {
31
+ // For React elements, wrap in a keyed Fragment
32
+ // This creates a new element with a key rather than trying to add one after creation
33
+ if (React.isValidElement(child)) {
34
+ return /* @__PURE__ */ _jsx(React.Fragment, { children: child }, index);
35
+ }
36
+ return child;
37
+ });
35
38
  };
36
39
  /**
37
- * Takes a `formatXMLElementFn`, and composes it in function, which passes
38
- * argument `parts` through, assigning unique key to each part, to prevent
39
- * "Each child in a list should have a unique "key"" React error.
40
- * @param formatXMLElementFn
41
- */
40
+ * Takes a `formatXMLElementFn`, and composes it in function, which passes
41
+ * argument `parts` through, assigning unique key to each part, to prevent
42
+ * "Each child in a list should have a unique "key"" React error.
43
+ * @param formatXMLElementFn
44
+ */
42
45
  export function assignUniqueKeysToParts(formatXMLElementFn) {
43
- return function (parts) {
44
- // eslint-disable-next-line prefer-rest-params
45
- return formatXMLElementFn(toKeyedReactNodeArray(parts));
46
- };
46
+ return function(parts) {
47
+ // eslint-disable-next-line prefer-rest-params
48
+ return formatXMLElementFn(toKeyedReactNodeArray(parts));
49
+ };
47
50
  }
48
51
  export function shallowEqual(objA, objB) {
49
- if (objA === objB) {
50
- return true;
51
- }
52
- if (!objA || !objB) {
53
- return false;
54
- }
55
- var aKeys = Object.keys(objA);
56
- var bKeys = Object.keys(objB);
57
- var len = aKeys.length;
58
- if (bKeys.length !== len) {
59
- return false;
60
- }
61
- for (var i = 0; i < len; i++) {
62
- var key = aKeys[i];
63
- if (objA[key] !== objB[key] ||
64
- !Object.prototype.hasOwnProperty.call(objB, key)) {
65
- return false;
66
- }
67
- }
68
- return true;
52
+ if (objA === objB) {
53
+ return true;
54
+ }
55
+ if (!objA || !objB) {
56
+ return false;
57
+ }
58
+ var aKeys = Object.keys(objA);
59
+ var bKeys = Object.keys(objB);
60
+ var len = aKeys.length;
61
+ if (bKeys.length !== len) {
62
+ return false;
63
+ }
64
+ for (var i = 0; i < len; i++) {
65
+ var key = aKeys[i];
66
+ if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
69
71
  }