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