react-intl 10.1.1 → 10.1.2

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.
@@ -1,9 +0,0 @@
1
- import * as React from "react";
2
- import "../types.js";
3
- import { invariantIntlContext } from "../utils.js";
4
- import { Context } from "./context.js";
5
- export default function useIntl() {
6
- const intl = React.useContext(Context);
7
- invariantIntlContext(intl);
8
- return intl;
9
- }
package/src/types.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { type ResolvedIntlConfig as CoreResolvedIntlConfig, type Formatters, type IntlFormatters, type MessageDescriptor } from "@formatjs/intl";
2
- import { type FormatXMLElementFn, type Options as IntlMessageFormatOptions, type PrimitiveType } from "intl-messageformat";
3
- import * as React from "react";
4
- import type { DEFAULT_INTL_CONFIG } from "./utils.js";
5
- export type IntlConfig = Omit<ResolvedIntlConfig, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
6
- export interface ResolvedIntlConfig extends CoreResolvedIntlConfig<React.ReactNode> {
7
- textComponent?: React.ComponentType | keyof React.JSX.IntrinsicElements;
8
- wrapRichTextChunksInFragment?: boolean;
9
- }
10
- export interface IntlShape extends ResolvedIntlConfig, IntlFormatters<React.ReactNode> {
11
- formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
12
- formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, React.ReactNode | PrimitiveType | FormatXMLElementFn<string, React.ReactNode>>, opts?: IntlMessageFormatOptions): Array<React.ReactNode>;
13
- formatters: Formatters;
14
- }
package/src/types.js DELETED
@@ -1,8 +0,0 @@
1
- /*
2
- * Copyright 2015, Yahoo Inc.
3
- * Copyrights licensed under the New BSD License.
4
- * See the accompanying LICENSE file for terms.
5
- */
6
- import "@formatjs/intl";
7
- import "intl-messageformat";
8
- import * as React from "react";
package/src/utils.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { type FormatXMLElementFn } from "intl-messageformat";
2
- import * as React from "react";
3
- import { type ResolvedIntlConfig } from "./types.js";
4
- export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
5
- export declare function invariantIntlContext(intl?: any): asserts intl;
6
- export type DefaultIntlConfig = Pick<ResolvedIntlConfig, "fallbackOnEmptyString" | "formats" | "messages" | "timeZone" | "textComponent" | "defaultLocale" | "defaultFormats" | "onError">;
7
- export declare const DEFAULT_INTL_CONFIG: DefaultIntlConfig;
8
- /**
9
- * Builds an array of {@link React.ReactNode}s with index-based keys, similar to
10
- * {@link React.Children.toArray}. However, this function tells React that it
11
- * was intentional, so they won't produce a bunch of warnings about it.
12
- *
13
- * React doesn't recommend doing this because it makes reordering inefficient,
14
- * but we mostly need this for message chunks, which don't tend to reorder to
15
- * begin with.
16
- *
17
- */
18
- export declare const toKeyedReactNodeArray: typeof React.Children.toArray;
19
- /**
20
- * Takes a `formatXMLElementFn`, and composes it in function, which passes
21
- * argument `parts` through, assigning unique key to each part, to prevent
22
- * "Each child in a list should have a unique "key"" React error.
23
- * @param formatXMLElementFn
24
- */
25
- export declare function assignUniqueKeysToParts(formatXMLElementFn: FormatXMLElementFn<React.ReactNode>): FormatXMLElementFn<React.ReactNode>;
26
- export declare function shallowEqual<T extends Record<string, unknown> = Record<string, unknown>>(objA?: T, objB?: T): boolean;
package/src/utils.js DELETED
@@ -1,71 +0,0 @@
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
- }
10
- }
11
- export function invariantIntlContext(intl) {
12
- invariant(intl, "[React Intl] Could not find required `intl` object. " + "<IntlProvider> needs to exist in the component ancestry.");
13
- }
14
- export const DEFAULT_INTL_CONFIG = {
15
- ...CORE_DEFAULT_INTL_CONFIG,
16
- textComponent: React.Fragment
17
- };
18
- /**
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
- });
38
- };
39
- /**
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
- */
45
- export function assignUniqueKeysToParts(formatXMLElementFn) {
46
- return function(parts) {
47
- // eslint-disable-next-line prefer-rest-params
48
- return formatXMLElementFn(toKeyedReactNodeArray(parts));
49
- };
50
- }
51
- export function shallowEqual(objA, objB) {
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;
71
- }