react-intl 2.2.3 → 2.3.0

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/lib/index.es.js CHANGED
@@ -7,7 +7,8 @@
7
7
  import allLocaleData from '../locale-data/index.js';
8
8
  import IntlMessageFormat from 'intl-messageformat';
9
9
  import IntlRelativeFormat from 'intl-relativeformat';
10
- import React, { Children, Component, PropTypes, createElement, isValidElement } from 'react';
10
+ import PropTypes from 'prop-types';
11
+ import React, { Children, Component, createElement, isValidElement } from 'react';
11
12
  import invariant from 'invariant';
12
13
  import memoizeIntlConstructor from 'intl-format-cache';
13
14
 
@@ -1137,20 +1138,24 @@ var FormattedRelative = function (_Component) {
1137
1138
  value: function scheduleNextUpdate(props, state) {
1138
1139
  var _this2 = this;
1139
1140
 
1140
- var updateInterval = props.updateInterval;
1141
+ // Cancel and pending update because we're scheduling a new update.
1142
+ clearTimeout(this._timer);
1143
+
1144
+ var value = props.value,
1145
+ units = props.units,
1146
+ updateInterval = props.updateInterval;
1141
1147
 
1142
- // If the `updateInterval` is falsy, including `0`, then auto updates
1143
- // have been turned off, so we bail and skip scheduling an update.
1148
+ var time = new Date(value).getTime();
1144
1149
 
1145
- if (!updateInterval) {
1150
+ // If the `updateInterval` is falsy, including `0` or we don't have a
1151
+ // valid date, then auto updates have been turned off, so we bail and
1152
+ // skip scheduling an update.
1153
+ if (!updateInterval || !isFinite(time)) {
1146
1154
  return;
1147
1155
  }
1148
1156
 
1149
- var time = new Date(props.value).getTime();
1150
1157
  var delta = time - state.now;
1151
- var units = props.units || selectUnits(delta);
1152
-
1153
- var unitDelay = getUnitDelay(units);
1158
+ var unitDelay = getUnitDelay(units || selectUnits(delta));
1154
1159
  var unitRemainder = Math.abs(delta % unitDelay);
1155
1160
 
1156
1161
  // We want the largest possible timer delay which will still display
@@ -1159,8 +1164,6 @@ var FormattedRelative = function (_Component) {
1159
1164
  // "1 minute ago" to "2 minutes ago" when the delta is 120,000ms.
1160
1165
  var delay = delta < 0 ? Math.max(updateInterval, unitDelay - unitRemainder) : Math.max(updateInterval, unitRemainder);
1161
1166
 
1162
- clearTimeout(this._timer);
1163
-
1164
1167
  this._timer = setTimeout(function () {
1165
1168
  _this2.setState({ now: _this2.context.intl.now() });
1166
1169
  }, delay);
@@ -1446,42 +1449,40 @@ var FormattedMessage = function (_Component) {
1446
1449
 
1447
1450
  var hasValues = values && Object.keys(values).length > 0;
1448
1451
  if (hasValues) {
1449
- (function () {
1450
- // Creates a token with a random UID that should not be guessable or
1451
- // conflict with other parts of the `message` string.
1452
- var uid = Math.floor(Math.random() * 0x10000000000).toString(16);
1453
-
1454
- var generateToken = function () {
1455
- var counter = 0;
1456
- return function () {
1457
- return 'ELEMENT-' + uid + '-' + (counter += 1);
1458
- };
1459
- }();
1460
-
1461
- // Splitting with a delimiter to support IE8. When using a regex
1462
- // with a capture group IE8 does not include the capture group in
1463
- // the resulting array.
1464
- tokenDelimiter = '@__' + uid + '__@';
1465
- tokenizedValues = {};
1466
- elements = {};
1467
-
1468
- // Iterates over the `props` to keep track of any React Element
1469
- // values so they can be represented by the `token` as a placeholder
1470
- // when the `message` is formatted. This allows the formatted
1471
- // message to then be broken-up into parts with references to the
1472
- // React Elements inserted back in.
1473
- Object.keys(values).forEach(function (name) {
1474
- var value = values[name];
1475
-
1476
- if (isValidElement(value)) {
1477
- var token = generateToken();
1478
- tokenizedValues[name] = tokenDelimiter + token + tokenDelimiter;
1479
- elements[token] = value;
1480
- } else {
1481
- tokenizedValues[name] = value;
1482
- }
1483
- });
1484
- })();
1452
+ // Creates a token with a random UID that should not be guessable or
1453
+ // conflict with other parts of the `message` string.
1454
+ var uid = Math.floor(Math.random() * 0x10000000000).toString(16);
1455
+
1456
+ var generateToken = function () {
1457
+ var counter = 0;
1458
+ return function () {
1459
+ return 'ELEMENT-' + uid + '-' + (counter += 1);
1460
+ };
1461
+ }();
1462
+
1463
+ // Splitting with a delimiter to support IE8. When using a regex
1464
+ // with a capture group IE8 does not include the capture group in
1465
+ // the resulting array.
1466
+ tokenDelimiter = '@__' + uid + '__@';
1467
+ tokenizedValues = {};
1468
+ elements = {};
1469
+
1470
+ // Iterates over the `props` to keep track of any React Element
1471
+ // values so they can be represented by the `token` as a placeholder
1472
+ // when the `message` is formatted. This allows the formatted
1473
+ // message to then be broken-up into parts with references to the
1474
+ // React Elements inserted back in.
1475
+ Object.keys(values).forEach(function (name) {
1476
+ var value = values[name];
1477
+
1478
+ if (isValidElement(value)) {
1479
+ var token = generateToken();
1480
+ tokenizedValues[name] = tokenDelimiter + token + tokenDelimiter;
1481
+ elements[token] = value;
1482
+ } else {
1483
+ tokenizedValues[name] = value;
1484
+ }
1485
+ });
1485
1486
  }
1486
1487
 
1487
1488
  var descriptor = { id: id, description: description, defaultMessage: defaultMessage };
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
13
13
  var allLocaleData = _interopDefault(require('../locale-data/index.js'));
14
14
  var IntlMessageFormat = _interopDefault(require('intl-messageformat'));
15
15
  var IntlRelativeFormat = _interopDefault(require('intl-relativeformat'));
16
+ var PropTypes = _interopDefault(require('prop-types'));
16
17
  var React = require('react');
17
18
  var React__default = _interopDefault(React);
18
19
  var invariant = _interopDefault(require('invariant'));
@@ -219,14 +220,14 @@ var toConsumableArray = function (arr) {
219
220
  * See the accompanying LICENSE file for terms.
220
221
  */
221
222
 
222
- var bool = React.PropTypes.bool;
223
- var number = React.PropTypes.number;
224
- var string = React.PropTypes.string;
225
- var func = React.PropTypes.func;
226
- var object = React.PropTypes.object;
227
- var oneOf = React.PropTypes.oneOf;
228
- var shape = React.PropTypes.shape;
229
- var any = React.PropTypes.any;
223
+ var bool = PropTypes.bool;
224
+ var number = PropTypes.number;
225
+ var string = PropTypes.string;
226
+ var func = PropTypes.func;
227
+ var object = PropTypes.object;
228
+ var oneOf = PropTypes.oneOf;
229
+ var shape = PropTypes.shape;
230
+ var any = PropTypes.any;
230
231
 
231
232
  var localeMatcher = oneOf(['best fit', 'lookup']);
232
233
  var narrowShortLong = oneOf(['narrow', 'short', 'long']);
@@ -928,8 +929,8 @@ IntlProvider.childContextTypes = {
928
929
  intl: intlShape.isRequired
929
930
  };
930
931
  process.env.NODE_ENV !== "production" ? IntlProvider.propTypes = _extends({}, intlConfigPropTypes, {
931
- children: React.PropTypes.element.isRequired,
932
- initialNow: React.PropTypes.any
932
+ children: PropTypes.element.isRequired,
933
+ initialNow: PropTypes.any
933
934
  }) : void 0;
934
935
 
935
936
  /*
@@ -991,9 +992,9 @@ FormattedDate.contextTypes = {
991
992
  intl: intlShape
992
993
  };
993
994
  process.env.NODE_ENV !== "production" ? FormattedDate.propTypes = _extends({}, dateTimeFormatPropTypes, {
994
- value: React.PropTypes.any.isRequired,
995
- format: React.PropTypes.string,
996
- children: React.PropTypes.func
995
+ value: PropTypes.any.isRequired,
996
+ format: PropTypes.string,
997
+ children: PropTypes.func
997
998
  }) : void 0;
998
999
 
999
1000
  /*
@@ -1055,9 +1056,9 @@ FormattedTime.contextTypes = {
1055
1056
  intl: intlShape
1056
1057
  };
1057
1058
  process.env.NODE_ENV !== "production" ? FormattedTime.propTypes = _extends({}, dateTimeFormatPropTypes, {
1058
- value: React.PropTypes.any.isRequired,
1059
- format: React.PropTypes.string,
1060
- children: React.PropTypes.func
1059
+ value: PropTypes.any.isRequired,
1060
+ format: PropTypes.string,
1061
+ children: PropTypes.func
1061
1062
  }) : void 0;
1062
1063
 
1063
1064
  /*
@@ -1144,20 +1145,24 @@ var FormattedRelative = function (_Component) {
1144
1145
  value: function scheduleNextUpdate(props, state) {
1145
1146
  var _this2 = this;
1146
1147
 
1147
- var updateInterval = props.updateInterval;
1148
+ // Cancel and pending update because we're scheduling a new update.
1149
+ clearTimeout(this._timer);
1150
+
1151
+ var value = props.value,
1152
+ units = props.units,
1153
+ updateInterval = props.updateInterval;
1148
1154
 
1149
- // If the `updateInterval` is falsy, including `0`, then auto updates
1150
- // have been turned off, so we bail and skip scheduling an update.
1155
+ var time = new Date(value).getTime();
1151
1156
 
1152
- if (!updateInterval) {
1157
+ // If the `updateInterval` is falsy, including `0` or we don't have a
1158
+ // valid date, then auto updates have been turned off, so we bail and
1159
+ // skip scheduling an update.
1160
+ if (!updateInterval || !isFinite(time)) {
1153
1161
  return;
1154
1162
  }
1155
1163
 
1156
- var time = new Date(props.value).getTime();
1157
1164
  var delta = time - state.now;
1158
- var units = props.units || selectUnits(delta);
1159
-
1160
- var unitDelay = getUnitDelay(units);
1165
+ var unitDelay = getUnitDelay(units || selectUnits(delta));
1161
1166
  var unitRemainder = Math.abs(delta % unitDelay);
1162
1167
 
1163
1168
  // We want the largest possible timer delay which will still display
@@ -1166,8 +1171,6 @@ var FormattedRelative = function (_Component) {
1166
1171
  // "1 minute ago" to "2 minutes ago" when the delta is 120,000ms.
1167
1172
  var delay = delta < 0 ? Math.max(updateInterval, unitDelay - unitRemainder) : Math.max(updateInterval, unitRemainder);
1168
1173
 
1169
- clearTimeout(this._timer);
1170
-
1171
1174
  this._timer = setTimeout(function () {
1172
1175
  _this2.setState({ now: _this2.context.intl.now() });
1173
1176
  }, delay);
@@ -1242,11 +1245,11 @@ FormattedRelative.defaultProps = {
1242
1245
  updateInterval: 1000 * 10
1243
1246
  };
1244
1247
  process.env.NODE_ENV !== "production" ? FormattedRelative.propTypes = _extends({}, relativeFormatPropTypes, {
1245
- value: React.PropTypes.any.isRequired,
1246
- format: React.PropTypes.string,
1247
- updateInterval: React.PropTypes.number,
1248
- initialNow: React.PropTypes.any,
1249
- children: React.PropTypes.func
1248
+ value: PropTypes.any.isRequired,
1249
+ format: PropTypes.string,
1250
+ updateInterval: PropTypes.number,
1251
+ initialNow: PropTypes.any,
1252
+ children: PropTypes.func
1250
1253
  }) : void 0;
1251
1254
 
1252
1255
  /*
@@ -1308,9 +1311,9 @@ FormattedNumber.contextTypes = {
1308
1311
  intl: intlShape
1309
1312
  };
1310
1313
  process.env.NODE_ENV !== "production" ? FormattedNumber.propTypes = _extends({}, numberFormatPropTypes, {
1311
- value: React.PropTypes.any.isRequired,
1312
- format: React.PropTypes.string,
1313
- children: React.PropTypes.func
1314
+ value: PropTypes.any.isRequired,
1315
+ format: PropTypes.string,
1316
+ children: PropTypes.func
1314
1317
  }) : void 0;
1315
1318
 
1316
1319
  /*
@@ -1377,16 +1380,16 @@ FormattedPlural.defaultProps = {
1377
1380
  style: 'cardinal'
1378
1381
  };
1379
1382
  process.env.NODE_ENV !== "production" ? FormattedPlural.propTypes = _extends({}, pluralFormatPropTypes, {
1380
- value: React.PropTypes.any.isRequired,
1383
+ value: PropTypes.any.isRequired,
1381
1384
 
1382
- other: React.PropTypes.node.isRequired,
1383
- zero: React.PropTypes.node,
1384
- one: React.PropTypes.node,
1385
- two: React.PropTypes.node,
1386
- few: React.PropTypes.node,
1387
- many: React.PropTypes.node,
1385
+ other: PropTypes.node.isRequired,
1386
+ zero: PropTypes.node,
1387
+ one: PropTypes.node,
1388
+ two: PropTypes.node,
1389
+ few: PropTypes.node,
1390
+ many: PropTypes.node,
1388
1391
 
1389
- children: React.PropTypes.func
1392
+ children: PropTypes.func
1390
1393
  }) : void 0;
1391
1394
 
1392
1395
  /*
@@ -1453,42 +1456,40 @@ var FormattedMessage = function (_Component) {
1453
1456
 
1454
1457
  var hasValues = values && Object.keys(values).length > 0;
1455
1458
  if (hasValues) {
1456
- (function () {
1457
- // Creates a token with a random UID that should not be guessable or
1458
- // conflict with other parts of the `message` string.
1459
- var uid = Math.floor(Math.random() * 0x10000000000).toString(16);
1460
-
1461
- var generateToken = function () {
1462
- var counter = 0;
1463
- return function () {
1464
- return 'ELEMENT-' + uid + '-' + (counter += 1);
1465
- };
1466
- }();
1467
-
1468
- // Splitting with a delimiter to support IE8. When using a regex
1469
- // with a capture group IE8 does not include the capture group in
1470
- // the resulting array.
1471
- tokenDelimiter = '@__' + uid + '__@';
1472
- tokenizedValues = {};
1473
- elements = {};
1474
-
1475
- // Iterates over the `props` to keep track of any React Element
1476
- // values so they can be represented by the `token` as a placeholder
1477
- // when the `message` is formatted. This allows the formatted
1478
- // message to then be broken-up into parts with references to the
1479
- // React Elements inserted back in.
1480
- Object.keys(values).forEach(function (name) {
1481
- var value = values[name];
1482
-
1483
- if (React.isValidElement(value)) {
1484
- var token = generateToken();
1485
- tokenizedValues[name] = tokenDelimiter + token + tokenDelimiter;
1486
- elements[token] = value;
1487
- } else {
1488
- tokenizedValues[name] = value;
1489
- }
1490
- });
1491
- })();
1459
+ // Creates a token with a random UID that should not be guessable or
1460
+ // conflict with other parts of the `message` string.
1461
+ var uid = Math.floor(Math.random() * 0x10000000000).toString(16);
1462
+
1463
+ var generateToken = function () {
1464
+ var counter = 0;
1465
+ return function () {
1466
+ return 'ELEMENT-' + uid + '-' + (counter += 1);
1467
+ };
1468
+ }();
1469
+
1470
+ // Splitting with a delimiter to support IE8. When using a regex
1471
+ // with a capture group IE8 does not include the capture group in
1472
+ // the resulting array.
1473
+ tokenDelimiter = '@__' + uid + '__@';
1474
+ tokenizedValues = {};
1475
+ elements = {};
1476
+
1477
+ // Iterates over the `props` to keep track of any React Element
1478
+ // values so they can be represented by the `token` as a placeholder
1479
+ // when the `message` is formatted. This allows the formatted
1480
+ // message to then be broken-up into parts with references to the
1481
+ // React Elements inserted back in.
1482
+ Object.keys(values).forEach(function (name) {
1483
+ var value = values[name];
1484
+
1485
+ if (React.isValidElement(value)) {
1486
+ var token = generateToken();
1487
+ tokenizedValues[name] = tokenDelimiter + token + tokenDelimiter;
1488
+ elements[token] = value;
1489
+ } else {
1490
+ tokenizedValues[name] = value;
1491
+ }
1492
+ });
1492
1493
  }
1493
1494
 
1494
1495
  var descriptor = { id: id, description: description, defaultMessage: defaultMessage };
@@ -1531,9 +1532,9 @@ FormattedMessage.defaultProps = {
1531
1532
  values: {}
1532
1533
  };
1533
1534
  process.env.NODE_ENV !== "production" ? FormattedMessage.propTypes = _extends({}, messageDescriptorPropTypes, {
1534
- values: React.PropTypes.object,
1535
- tagName: React.PropTypes.string,
1536
- children: React.PropTypes.func
1535
+ values: PropTypes.object,
1536
+ tagName: PropTypes.string,
1537
+ children: PropTypes.func
1537
1538
  }) : void 0;
1538
1539
 
1539
1540
  /*
@@ -1624,9 +1625,9 @@ FormattedHTMLMessage.defaultProps = {
1624
1625
  values: {}
1625
1626
  };
1626
1627
  process.env.NODE_ENV !== "production" ? FormattedHTMLMessage.propTypes = _extends({}, messageDescriptorPropTypes, {
1627
- values: React.PropTypes.object,
1628
- tagName: React.PropTypes.string,
1629
- children: React.PropTypes.func
1628
+ values: PropTypes.object,
1629
+ tagName: PropTypes.string,
1630
+ children: PropTypes.func
1630
1631
  }) : void 0;
1631
1632
 
1632
1633
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intl",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.",
5
5
  "keywords": [
6
6
  "intl",
@@ -70,25 +70,27 @@
70
70
  "invariant": "^2.1.1"
71
71
  },
72
72
  "peerDependencies": {
73
- "react": "^0.14.0 || ^15.0.0-0"
73
+ "react": "^0.14.9 || ^15.0.0",
74
+ "prop-types": "^15.5.4"
74
75
  },
75
76
  "devDependencies": {
76
77
  "babel-cli": "^6.2.0",
77
78
  "babel-eslint": "^7.1.1",
78
- "babel-jest": "^18.0.0",
79
+ "babel-jest": "^19.0.0",
79
80
  "babel-plugin-external-helpers": "^6.18.0",
80
81
  "babel-plugin-react-intl": "^2.0.0",
82
+ "babel-plugin-transform-async-to-generator": "^6.16.0",
81
83
  "babel-plugin-transform-class-properties": "^6.11.5",
82
84
  "babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
83
85
  "babel-plugin-transform-es3-member-expression-literals": "^6.3.13",
84
86
  "babel-plugin-transform-es3-property-literals": "^6.3.13",
85
87
  "babel-plugin-transform-object-rest-spread": "^6.1.18",
86
- "babel-plugin-transform-react-remove-prop-types": "^0.2.10",
88
+ "babel-plugin-transform-react-remove-prop-types": "^0.3.2",
87
89
  "babel-preset-es2015": "^6.1.18",
88
90
  "babel-preset-react": "^6.1.18",
89
91
  "babelify": "^7.2.0",
90
92
  "benchmark": "^2.1.0",
91
- "browserify": "^13.0.0",
93
+ "browserify": "^14.0.0",
92
94
  "browserify-shim": "^3.8.11",
93
95
  "cross-env": "^3.1.3",
94
96
  "eslint": "^3.10.2",
@@ -100,11 +102,12 @@
100
102
  "glob": "^7.0.0",
101
103
  "intl": "^1.2.1",
102
104
  "intl-messageformat-parser": "^1.2.0",
103
- "jest": "^18.0.0",
105
+ "jest": "^19.0.0",
104
106
  "mkdirp": "^0.5.1",
105
- "react": "^15.0.0",
106
- "react-addons-test-utils": "^15.0.0",
107
- "react-dom": "^15.0.0",
107
+ "prop-types": "^15.5.4",
108
+ "react": "^15.5.4",
109
+ "react-dom": "^15.5.4",
110
+ "react-test-renderer": "^15.5.4",
108
111
  "rimraf": "^2.4.2",
109
112
  "rollup": "^0.41.4",
110
113
  "rollup-plugin-babel": "^2.3.9",
@@ -118,7 +121,7 @@
118
121
  "watchify": "^3.7.0"
119
122
  },
120
123
  "scripts": {
121
- "clean": "rimraf src/en.js coverage/ dist/ lib/ locale-data/",
124
+ "clean": "rimraf src/en.js coverage/ dist/ lib/ locale-data/ test/renderer.js",
122
125
  "build:data": "babel-node scripts/build-data",
123
126
  "build:lib": "rollup -c rollup.config.lib.js",
124
127
  "build:dist:dev": "cross-env NODE_ENV=development rollup -c rollup.config.dist.js",
@@ -127,7 +130,7 @@
127
130
  "build": "npm run build:data && npm run build:lib && npm run build:dist",
128
131
  "react:clean": "rimraf node_modules/{react,react-dom,react-addons-test-utils}",
129
132
  "react:14": "npm run react:clean && npm i react@^0.14 react-dom@^0.14 react-addons-test-utils@^0.14",
130
- "react:15": "npm run react:clean && npm i react@^15 react-dom@^15 react-addons-test-utils@^15",
133
+ "react:15": "npm run react:clean && npm i react@^15 react-dom@^15",
131
134
  "lint": "eslint .",
132
135
  "lint:fix": "eslint . --fix",
133
136
  "test": "jest --coverage --verbose",