react-intl 5.4.1 → 5.4.5

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
@@ -9,10 +9,28 @@ All rights reserved.
9
9
  This source code is licensed under the BSD-style license found in the LICENSE
10
10
  file in the root directory of React's source tree.
11
11
  */
12
+ var __assign = (this && this.__assign) || function () {
13
+ __assign = Object.assign || function(t) {
14
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
15
+ s = arguments[i];
16
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
17
+ t[p] = s[p];
18
+ }
19
+ return t;
20
+ };
21
+ return __assign.apply(this, arguments);
22
+ };
23
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
24
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
25
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
26
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
27
+ r[k] = a[j];
28
+ return r;
29
+ };
12
30
  Object.defineProperty(exports, "__esModule", { value: true });
13
31
  var React = require("react");
14
32
  var intl_messageformat_1 = require("intl-messageformat");
15
- var intl_format_cache_1 = require("intl-format-cache");
33
+ var memoize = require("fast-memoize");
16
34
  var intl_utils_1 = require("@formatjs/intl-utils");
17
35
  var error_1 = require("./error");
18
36
  function filterProps(props, whitelist, defaults) {
@@ -59,6 +77,26 @@ function createIntlCache() {
59
77
  };
60
78
  }
61
79
  exports.createIntlCache = createIntlCache;
80
+ function createFastMemoizeCache(store) {
81
+ return {
82
+ create: function () {
83
+ return {
84
+ has: function (key) {
85
+ return key in store;
86
+ },
87
+ get: function (key) {
88
+ return store[key];
89
+ },
90
+ set: function (key, value) {
91
+ store[key] = value;
92
+ },
93
+ };
94
+ },
95
+ };
96
+ }
97
+ // @ts-ignore this is to deal with rollup's default import shenanigans
98
+ var _memoizeIntl = memoize.default || memoize;
99
+ var memoizeIntl = _memoizeIntl;
62
100
  /**
63
101
  * Create intl formatters and populate cache
64
102
  * @param cache explicit cache to prevent leaking memory
@@ -68,14 +106,83 @@ function createFormatters(cache) {
68
106
  var RelativeTimeFormat = Intl.RelativeTimeFormat;
69
107
  var ListFormat = Intl.ListFormat;
70
108
  var DisplayNames = Intl.DisplayNames;
109
+ var getDateTimeFormat = memoizeIntl(function () {
110
+ var _a;
111
+ var args = [];
112
+ for (var _i = 0; _i < arguments.length; _i++) {
113
+ args[_i] = arguments[_i];
114
+ }
115
+ return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArrays([void 0], args)))();
116
+ }, {
117
+ cache: createFastMemoizeCache(cache.dateTime),
118
+ strategy: memoizeIntl.strategies.variadic,
119
+ });
120
+ var getNumberFormat = memoizeIntl(function () {
121
+ var _a;
122
+ var args = [];
123
+ for (var _i = 0; _i < arguments.length; _i++) {
124
+ args[_i] = arguments[_i];
125
+ }
126
+ return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArrays([void 0], args)))();
127
+ }, {
128
+ cache: createFastMemoizeCache(cache.number),
129
+ strategy: memoizeIntl.strategies.variadic,
130
+ });
131
+ var getPluralRules = memoizeIntl(function () {
132
+ var _a;
133
+ var args = [];
134
+ for (var _i = 0; _i < arguments.length; _i++) {
135
+ args[_i] = arguments[_i];
136
+ }
137
+ return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArrays([void 0], args)))();
138
+ }, {
139
+ cache: createFastMemoizeCache(cache.pluralRules),
140
+ strategy: memoizeIntl.strategies.variadic,
141
+ });
71
142
  return {
72
- getDateTimeFormat: intl_format_cache_1.default(Intl.DateTimeFormat, cache.dateTime),
73
- getNumberFormat: intl_format_cache_1.default(Intl.NumberFormat, cache.number),
74
- getMessageFormat: intl_format_cache_1.default(intl_messageformat_1.default, cache.message),
75
- getRelativeTimeFormat: intl_format_cache_1.default(RelativeTimeFormat, cache.relativeTime),
76
- getPluralRules: intl_format_cache_1.default(Intl.PluralRules, cache.pluralRules),
77
- getListFormat: intl_format_cache_1.default(ListFormat, cache.list),
78
- getDisplayNames: intl_format_cache_1.default(DisplayNames, cache.displayNames),
143
+ getDateTimeFormat: getDateTimeFormat,
144
+ getNumberFormat: getNumberFormat,
145
+ getMessageFormat: memoizeIntl(function (message, locales, overrideFormats, opts) {
146
+ return new intl_messageformat_1.IntlMessageFormat(message, locales, overrideFormats, __assign({ formatters: {
147
+ getNumberFormat: getNumberFormat,
148
+ getDateTimeFormat: getDateTimeFormat,
149
+ getPluralRules: getPluralRules,
150
+ } }, (opts || {})));
151
+ }, {
152
+ cache: createFastMemoizeCache(cache.message),
153
+ strategy: memoizeIntl.strategies.variadic,
154
+ }),
155
+ getRelativeTimeFormat: memoizeIntl(function () {
156
+ var args = [];
157
+ for (var _i = 0; _i < arguments.length; _i++) {
158
+ args[_i] = arguments[_i];
159
+ }
160
+ return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, __spreadArrays([void 0], args)))();
161
+ }, {
162
+ cache: createFastMemoizeCache(cache.relativeTime),
163
+ strategy: memoizeIntl.strategies.variadic,
164
+ }),
165
+ getPluralRules: getPluralRules,
166
+ getListFormat: memoizeIntl(function () {
167
+ var args = [];
168
+ for (var _i = 0; _i < arguments.length; _i++) {
169
+ args[_i] = arguments[_i];
170
+ }
171
+ return new (ListFormat.bind.apply(ListFormat, __spreadArrays([void 0], args)))();
172
+ }, {
173
+ cache: createFastMemoizeCache(cache.list),
174
+ strategy: memoizeIntl.strategies.variadic,
175
+ }),
176
+ getDisplayNames: memoizeIntl(function () {
177
+ var args = [];
178
+ for (var _i = 0; _i < arguments.length; _i++) {
179
+ args[_i] = arguments[_i];
180
+ }
181
+ return new (DisplayNames.bind.apply(DisplayNames, __spreadArrays([void 0], args)))();
182
+ }, {
183
+ cache: createFastMemoizeCache(cache.displayNames),
184
+ strategy: memoizeIntl.strategies.variadic,
185
+ }),
79
186
  };
80
187
  }
81
188
  exports.createFormatters = createFormatters;