react-intl 2.2.0 → 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/src/types.js DELETED
@@ -1,88 +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
-
7
- import {PropTypes} from 'react';
8
-
9
- const {bool, number, string, func, object, oneOf, shape, node} = PropTypes;
10
- const localeMatcher = oneOf(['best fit', 'lookup']);
11
- const narrowShortLong = oneOf(['narrow', 'short', 'long']);
12
- const numeric2digit = oneOf(['numeric', '2-digit']);
13
- const funcReq = func.isRequired;
14
-
15
- export const intlConfigPropTypes = {
16
- locale : string,
17
- formats : object,
18
- messages : object,
19
- textComponent: node,
20
-
21
- defaultLocale : string,
22
- defaultFormats: object,
23
- };
24
-
25
- export const intlFormatPropTypes = {
26
- formatDate : funcReq,
27
- formatTime : funcReq,
28
- formatRelative : funcReq,
29
- formatNumber : funcReq,
30
- formatPlural : funcReq,
31
- formatMessage : funcReq,
32
- formatHTMLMessage: funcReq,
33
- };
34
-
35
- export const intlShape = shape({
36
- ...intlConfigPropTypes,
37
- ...intlFormatPropTypes,
38
- formatters: object,
39
- now: funcReq,
40
- });
41
-
42
- export const messageDescriptorPropTypes = {
43
- id : string.isRequired,
44
- description : string,
45
- defaultMessage: string,
46
- };
47
-
48
- export const dateTimeFormatPropTypes = {
49
- localeMatcher,
50
- formatMatcher: oneOf(['basic', 'best fit']),
51
-
52
- timeZone: string,
53
- hour12 : bool,
54
-
55
- weekday : narrowShortLong,
56
- era : narrowShortLong,
57
- year : numeric2digit,
58
- month : oneOf(['numeric', '2-digit', 'narrow', 'short', 'long']),
59
- day : numeric2digit,
60
- hour : numeric2digit,
61
- minute : numeric2digit,
62
- second : numeric2digit,
63
- timeZoneName: oneOf(['short', 'long']),
64
- };
65
-
66
- export const numberFormatPropTypes = {
67
- localeMatcher,
68
-
69
- style : oneOf(['decimal', 'currency', 'percent']),
70
- currency : string,
71
- currencyDisplay: oneOf(['symbol', 'code', 'name']),
72
- useGrouping : bool,
73
-
74
- minimumIntegerDigits : number,
75
- minimumFractionDigits : number,
76
- maximumFractionDigits : number,
77
- minimumSignificantDigits: number,
78
- maximumSignificantDigits: number,
79
- };
80
-
81
- export const relativeFormatPropTypes = {
82
- style: oneOf(['best fit', 'numeric']),
83
- units: oneOf(['second', 'minute', 'hour', 'day', 'month', 'year']),
84
- };
85
-
86
- export const pluralFormatPropTypes = {
87
- style: oneOf(['cardinal', 'ordinal']),
88
- };
package/src/utils.js DELETED
@@ -1,93 +0,0 @@
1
- /*
2
- HTML escaping and shallow-equals implementations are the same as React's
3
- (on purpose.) Therefore, it has the following Copyright and Licensing:
4
-
5
- Copyright 2013-2014, Facebook, Inc.
6
- All rights reserved.
7
-
8
- This source code is licensed under the BSD-style license found in the LICENSE
9
- file in the root directory of React's source tree.
10
- */
11
-
12
- import invariant from 'invariant';
13
- import {intlConfigPropTypes} from './types';
14
-
15
- const intlConfigPropNames = Object.keys(intlConfigPropTypes);
16
-
17
- const ESCAPED_CHARS = {
18
- '&' : '&',
19
- '>' : '>',
20
- '<' : '&lt;',
21
- '"' : '&quot;',
22
- '\'': '&#x27;',
23
- };
24
-
25
- const UNSAFE_CHARS_REGEX = /[&><"']/g;
26
-
27
- export function escape(str) {
28
- return ('' + str).replace(UNSAFE_CHARS_REGEX, (match) => ESCAPED_CHARS[match]);
29
- }
30
-
31
- export function filterProps(props, whitelist, defaults = {}) {
32
- return whitelist.reduce((filtered, name) => {
33
- if (props.hasOwnProperty(name)) {
34
- filtered[name] = props[name];
35
- } else if (defaults.hasOwnProperty(name)) {
36
- filtered[name] = defaults[name];
37
- }
38
-
39
- return filtered;
40
- }, {});
41
- }
42
-
43
- export function invariantIntlContext({intl} = {}) {
44
- invariant(intl,
45
- '[React Intl] Could not find required `intl` object. ' +
46
- '<IntlProvider> needs to exist in the component ancestry.'
47
- );
48
- }
49
-
50
- export function shallowEquals(objA, objB) {
51
- if (objA === objB) {
52
- return true;
53
- }
54
-
55
- if (typeof objA !== 'object' || objA === null ||
56
- typeof objB !== 'object' || objB === null) {
57
- return false;
58
- }
59
-
60
- let keysA = Object.keys(objA);
61
- let keysB = Object.keys(objB);
62
-
63
- if (keysA.length !== keysB.length) {
64
- return false;
65
- }
66
-
67
- // Test for A's keys different from B.
68
- let bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
69
- for (let i = 0; i < keysA.length; i++) {
70
- if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
71
- return false;
72
- }
73
- }
74
-
75
- return true;
76
- }
77
-
78
- export function shouldIntlComponentUpdate(
79
- {props, state, context = {}},
80
- nextProps, nextState, nextContext = {}
81
- ) {
82
- const {intl = {}} = context;
83
- const {intl: nextIntl = {}} = nextContext;
84
-
85
- return (
86
- !shallowEquals(nextProps, props) ||
87
- !shallowEquals(nextState, state) ||
88
- !(nextIntl === intl || shallowEquals(
89
- filterProps(nextIntl, intlConfigPropNames),
90
- filterProps(intl, intlConfigPropNames)
91
- ))
92
- );
93
- }