react-is 16.3.0-alpha.1 → 16.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `react-is`
2
2
 
3
- This package allows you to test arbitrary values and see if they're a particular React type, e.g. React Elements.
3
+ This package allows you to test arbitrary values and see if they're a particular React element type.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,7 +14,37 @@ npm install react-is --save
14
14
 
15
15
  ## Usage
16
16
 
17
- ### AsyncMode
17
+ ### Determining if a Component is Valid
18
+
19
+ ```js
20
+ import * as ReactIs from "react-is";
21
+
22
+ class ClassComponent extends React.Component {
23
+ render() {
24
+ return React.createElement("div");
25
+ }
26
+ }
27
+
28
+ const StatelessComponent = () => React.createElement("div");
29
+
30
+ const ForwardRefComponent = React.forwardRef((props, ref) =>
31
+ React.createElement(Component, { forwardedRef: ref, ...props })
32
+ );
33
+
34
+ const Context = React.createContext(false);
35
+
36
+ ReactIs.isValidElementType("div"); // true
37
+ ReactIs.isValidElementType(ClassComponent); // true
38
+ ReactIs.isValidElementType(StatelessComponent); // true
39
+ ReactIs.isValidElementType(ForwardRefComponent); // true
40
+ ReactIs.isValidElementType(Context.Provider); // true
41
+ ReactIs.isValidElementType(Context.Consumer); // true
42
+ ReactIs.isValidElementType(React.createFactory("div")); // true
43
+ ```
44
+
45
+ ### Determining an Element's Type
46
+
47
+ #### AsyncMode
18
48
 
19
49
  ```js
20
50
  import React from "react";
@@ -24,7 +54,7 @@ ReactIs.isAsyncMode(<React.unstable_AsyncMode />); // true
24
54
  ReactIs.typeOf(<React.unstable_AsyncMode />) === ReactIs.AsyncMode; // true
25
55
  ```
26
56
 
27
- ### Context
57
+ #### Context
28
58
 
29
59
  ```js
30
60
  import React from "react";
@@ -38,7 +68,7 @@ ReactIs.typeOf(<ThemeContext.Provider />) === ReactIs.ContextProvider; // true
38
68
  ReactIs.typeOf(<ThemeContext.Consumer />) === ReactIs.ContextConsumer; // true
39
69
  ```
40
70
 
41
- ### Element
71
+ #### Element
42
72
 
43
73
  ```js
44
74
  import React from "react";
@@ -48,7 +78,7 @@ ReactIs.isElement(<div />); // true
48
78
  ReactIs.typeOf(<div />) === ReactIs.Element; // true
49
79
  ```
50
80
 
51
- ### Fragment
81
+ #### Fragment
52
82
 
53
83
  ```js
54
84
  import React from "react";
@@ -58,7 +88,7 @@ ReactIs.isFragment(<></>); // true
58
88
  ReactIs.typeOf(<></>) === ReactIs.Fragment; // true
59
89
  ```
60
90
 
61
- ### Portal
91
+ #### Portal
62
92
 
63
93
  ```js
64
94
  import React from "react";
@@ -72,7 +102,7 @@ ReactIs.isPortal(portal); // true
72
102
  ReactIs.typeOf(portal) === ReactIs.Portal; // true
73
103
  ```
74
104
 
75
- ### StrictMode
105
+ #### StrictMode
76
106
 
77
107
  ```js
78
108
  import React from "react";
@@ -1,4 +1,4 @@
1
- /** @license React v16.3.0-alpha.1
1
+ /** @license React v16.3.0
2
2
  * react-is.development.js
3
3
  *
4
4
  * Copyright (c) 2013-present, Facebook, Inc.
@@ -30,6 +30,13 @@ var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol['for']('react.strict_mode') : 0x
30
30
  var REACT_PROVIDER_TYPE = hasSymbol ? Symbol['for']('react.provider') : 0xeacd;
31
31
  var REACT_CONTEXT_TYPE = hasSymbol ? Symbol['for']('react.context') : 0xeace;
32
32
  var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol['for']('react.async_mode') : 0xeacf;
33
+ var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol['for']('react.forward_ref') : 0xead0;
34
+
35
+ function isValidElementType(type) {
36
+ return typeof type === 'string' || typeof type === 'function' ||
37
+ // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
38
+ type === REACT_FRAGMENT_TYPE || type === REACT_ASYNC_MODE_TYPE || type === REACT_STRICT_MODE_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE);
39
+ }
33
40
 
34
41
  function typeOf(object) {
35
42
  if (typeof object === 'object' && object !== null) {
@@ -45,10 +52,11 @@ function typeOf(object) {
45
52
  case REACT_STRICT_MODE_TYPE:
46
53
  return type;
47
54
  default:
48
- var $$typeofType = type.$$typeof;
55
+ var $$typeofType = type && type.$$typeof;
49
56
 
50
57
  switch ($$typeofType) {
51
58
  case REACT_CONTEXT_TYPE:
59
+ case REACT_FORWARD_REF_TYPE:
52
60
  case REACT_PROVIDER_TYPE:
53
61
  return $$typeofType;
54
62
  default:
@@ -67,6 +75,7 @@ var AsyncMode = REACT_ASYNC_MODE_TYPE;
67
75
  var ContextConsumer = REACT_CONTEXT_TYPE;
68
76
  var ContextProvider = REACT_PROVIDER_TYPE;
69
77
  var Element = REACT_ELEMENT_TYPE;
78
+ var ForwardRef = REACT_FORWARD_REF_TYPE;
70
79
  var Fragment = REACT_FRAGMENT_TYPE;
71
80
  var Portal = REACT_PORTAL_TYPE;
72
81
  var StrictMode = REACT_STRICT_MODE_TYPE;
@@ -83,6 +92,9 @@ function isContextProvider(object) {
83
92
  function isElement(object) {
84
93
  return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
85
94
  }
95
+ function isForwardRef(object) {
96
+ return typeOf(object) === REACT_FORWARD_REF_TYPE;
97
+ }
86
98
  function isFragment(object) {
87
99
  return typeOf(object) === REACT_FRAGMENT_TYPE;
88
100
  }
@@ -98,13 +110,16 @@ exports.AsyncMode = AsyncMode;
98
110
  exports.ContextConsumer = ContextConsumer;
99
111
  exports.ContextProvider = ContextProvider;
100
112
  exports.Element = Element;
113
+ exports.ForwardRef = ForwardRef;
101
114
  exports.Fragment = Fragment;
102
115
  exports.Portal = Portal;
103
116
  exports.StrictMode = StrictMode;
117
+ exports.isValidElementType = isValidElementType;
104
118
  exports.isAsyncMode = isAsyncMode;
105
119
  exports.isContextConsumer = isContextConsumer;
106
120
  exports.isContextProvider = isContextProvider;
107
121
  exports.isElement = isElement;
122
+ exports.isForwardRef = isForwardRef;
108
123
  exports.isFragment = isFragment;
109
124
  exports.isPortal = isPortal;
110
125
  exports.isStrictMode = isStrictMode;
@@ -1,4 +1,4 @@
1
- /** @license React v16.3.0-alpha.1
1
+ /** @license React v16.3.0
2
2
  * react-is.production.min.js
3
3
  *
4
4
  * Copyright (c) 2013-present, Facebook, Inc.
@@ -7,6 +7,7 @@
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
9
 
10
- 'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var b="function"===typeof Symbol&&Symbol["for"],c=b?Symbol["for"]("react.element"):60103,d=b?Symbol["for"]("react.portal"):60106,e=b?Symbol["for"]("react.fragment"):60107,f=b?Symbol["for"]("react.strict_mode"):60108,g=b?Symbol["for"]("react.provider"):60109,h=b?Symbol["for"]("react.context"):60110,k=b?Symbol["for"]("react.async_mode"):60111;
11
- function l(a){if("object"===typeof a&&null!==a){var m=a.$$typeof;switch(m){case c:switch(a=a.type,a){case k:case e:case f:return a;default:switch(a=a.$$typeof,a){case h:case g:return a;default:return m}}case d:return m}}}exports.typeOf=l;exports.AsyncMode=k;exports.ContextConsumer=h;exports.ContextProvider=g;exports.Element=c;exports.Fragment=e;exports.Portal=d;exports.StrictMode=f;exports.isAsyncMode=function(a){return l(a)===k};exports.isContextConsumer=function(a){return l(a)===h};
12
- exports.isContextProvider=function(a){return l(a)===g};exports.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===c};exports.isFragment=function(a){return l(a)===e};exports.isPortal=function(a){return l(a)===d};exports.isStrictMode=function(a){return l(a)===f};
10
+ 'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var b="function"===typeof Symbol&&Symbol["for"],c=b?Symbol["for"]("react.element"):60103,d=b?Symbol["for"]("react.portal"):60106,e=b?Symbol["for"]("react.fragment"):60107,f=b?Symbol["for"]("react.strict_mode"):60108,g=b?Symbol["for"]("react.provider"):60109,h=b?Symbol["for"]("react.context"):60110,k=b?Symbol["for"]("react.async_mode"):60111,l=b?Symbol["for"]("react.forward_ref"):60112;
11
+ function m(a){if("object"===typeof a&&null!==a){var n=a.$$typeof;switch(n){case c:switch(a=a.type,a){case k:case e:case f:return a;default:switch(a=a&&a.$$typeof,a){case h:case l:case g:return a;default:return n}}case d:return n}}}exports.typeOf=m;exports.AsyncMode=k;exports.ContextConsumer=h;exports.ContextProvider=g;exports.Element=c;exports.ForwardRef=l;exports.Fragment=e;exports.Portal=d;exports.StrictMode=f;
12
+ exports.isValidElementType=function(a){return"string"===typeof a||"function"===typeof a||a===e||a===k||a===f||"object"===typeof a&&null!==a&&(a.$$typeof===g||a.$$typeof===h||a.$$typeof===l)};exports.isAsyncMode=function(a){return m(a)===k};exports.isContextConsumer=function(a){return m(a)===h};exports.isContextProvider=function(a){return m(a)===g};exports.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return m(a)===l};
13
+ exports.isFragment=function(a){return m(a)===e};exports.isPortal=function(a){return m(a)===d};exports.isStrictMode=function(a){return m(a)===f};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-is",
3
- "version": "16.3.0-alpha.1",
3
+ "version": "16.3.0",
4
4
  "description": "Brand checking of React Elements.",
5
5
  "main": "index.js",
6
6
  "repository": "facebook/react",
@@ -12,9 +12,6 @@
12
12
  "url": "https://github.com/facebook/react/issues"
13
13
  },
14
14
  "homepage": "https://reactjs.org/",
15
- "peerDependencies": {
16
- "react": "^16.0.0 || 16.3.0-alpha.1"
17
- },
18
15
  "files": [
19
16
  "LICENSE",
20
17
  "README.md",
@@ -1,4 +1,4 @@
1
- /** @license React v16.3.0-alpha.1
1
+ /** @license React v16.3.0
2
2
  * react-is.development.js
3
3
  *
4
4
  * Copyright (c) 2013-present, Facebook, Inc.
@@ -28,6 +28,13 @@ var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol['for']('react.strict_mode') : 0x
28
28
  var REACT_PROVIDER_TYPE = hasSymbol ? Symbol['for']('react.provider') : 0xeacd;
29
29
  var REACT_CONTEXT_TYPE = hasSymbol ? Symbol['for']('react.context') : 0xeace;
30
30
  var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol['for']('react.async_mode') : 0xeacf;
31
+ var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol['for']('react.forward_ref') : 0xead0;
32
+
33
+ function isValidElementType(type) {
34
+ return typeof type === 'string' || typeof type === 'function' ||
35
+ // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
36
+ type === REACT_FRAGMENT_TYPE || type === REACT_ASYNC_MODE_TYPE || type === REACT_STRICT_MODE_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE);
37
+ }
31
38
 
32
39
  function typeOf(object) {
33
40
  if (typeof object === 'object' && object !== null) {
@@ -43,10 +50,11 @@ function typeOf(object) {
43
50
  case REACT_STRICT_MODE_TYPE:
44
51
  return type;
45
52
  default:
46
- var $$typeofType = type.$$typeof;
53
+ var $$typeofType = type && type.$$typeof;
47
54
 
48
55
  switch ($$typeofType) {
49
56
  case REACT_CONTEXT_TYPE:
57
+ case REACT_FORWARD_REF_TYPE:
50
58
  case REACT_PROVIDER_TYPE:
51
59
  return $$typeofType;
52
60
  default:
@@ -65,6 +73,7 @@ var AsyncMode = REACT_ASYNC_MODE_TYPE;
65
73
  var ContextConsumer = REACT_CONTEXT_TYPE;
66
74
  var ContextProvider = REACT_PROVIDER_TYPE;
67
75
  var Element = REACT_ELEMENT_TYPE;
76
+ var ForwardRef = REACT_FORWARD_REF_TYPE;
68
77
  var Fragment = REACT_FRAGMENT_TYPE;
69
78
  var Portal = REACT_PORTAL_TYPE;
70
79
  var StrictMode = REACT_STRICT_MODE_TYPE;
@@ -81,6 +90,9 @@ function isContextProvider(object) {
81
90
  function isElement(object) {
82
91
  return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
83
92
  }
93
+ function isForwardRef(object) {
94
+ return typeOf(object) === REACT_FORWARD_REF_TYPE;
95
+ }
84
96
  function isFragment(object) {
85
97
  return typeOf(object) === REACT_FRAGMENT_TYPE;
86
98
  }
@@ -96,13 +108,16 @@ exports.AsyncMode = AsyncMode;
96
108
  exports.ContextConsumer = ContextConsumer;
97
109
  exports.ContextProvider = ContextProvider;
98
110
  exports.Element = Element;
111
+ exports.ForwardRef = ForwardRef;
99
112
  exports.Fragment = Fragment;
100
113
  exports.Portal = Portal;
101
114
  exports.StrictMode = StrictMode;
115
+ exports.isValidElementType = isValidElementType;
102
116
  exports.isAsyncMode = isAsyncMode;
103
117
  exports.isContextConsumer = isContextConsumer;
104
118
  exports.isContextProvider = isContextProvider;
105
119
  exports.isElement = isElement;
120
+ exports.isForwardRef = isForwardRef;
106
121
  exports.isFragment = isFragment;
107
122
  exports.isPortal = isPortal;
108
123
  exports.isStrictMode = isStrictMode;
@@ -1,4 +1,4 @@
1
- /** @license React v16.3.0-alpha.1
1
+ /** @license React v16.3.0
2
2
  * react-is.production.min.js
3
3
  *
4
4
  * Copyright (c) 2013-present, Facebook, Inc.
@@ -6,6 +6,7 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
- 'use strict';(function(b,c){"object"===typeof exports&&"undefined"!==typeof module?c(exports):"function"===typeof define&&define.amd?define(["exports"],c):c(b.ReactIs={})})(this,function(b){function c(a){if("object"===typeof a&&null!==a){var b=a.$$typeof;switch(b){case e:switch(a=a.type,a){case f:case g:case h:return a;default:switch(a=a.$$typeof,a){case k:case l:return a;default:return b}}case m:return b}}}var d="function"===typeof Symbol&&Symbol["for"],e=d?Symbol["for"]("react.element"):60103,m=
10
- d?Symbol["for"]("react.portal"):60106,g=d?Symbol["for"]("react.fragment"):60107,h=d?Symbol["for"]("react.strict_mode"):60108,l=d?Symbol["for"]("react.provider"):60109,k=d?Symbol["for"]("react.context"):60110,f=d?Symbol["for"]("react.async_mode"):60111;b.typeOf=c;b.AsyncMode=f;b.ContextConsumer=k;b.ContextProvider=l;b.Element=e;b.Fragment=g;b.Portal=m;b.StrictMode=h;b.isAsyncMode=function(a){return c(a)===f};b.isContextConsumer=function(a){return c(a)===k};b.isContextProvider=function(a){return c(a)===
11
- l};b.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===e};b.isFragment=function(a){return c(a)===g};b.isPortal=function(a){return c(a)===m};b.isStrictMode=function(a){return c(a)===h};Object.defineProperty(b,"__esModule",{value:!0})});
9
+ 'use strict';(function(b,c){"object"===typeof exports&&"undefined"!==typeof module?c(exports):"function"===typeof define&&define.amd?define(["exports"],c):c(b.ReactIs={})})(this,function(b){function c(a){if("object"===typeof a&&null!==a){var b=a.$$typeof;switch(b){case m:switch(a=a.type,a){case e:case f:case g:return a;default:switch(a=a&&a.$$typeof,a){case h:case k:case l:return a;default:return b}}case n:return b}}}var d="function"===typeof Symbol&&Symbol["for"],m=d?Symbol["for"]("react.element"):
10
+ 60103,n=d?Symbol["for"]("react.portal"):60106,f=d?Symbol["for"]("react.fragment"):60107,g=d?Symbol["for"]("react.strict_mode"):60108,l=d?Symbol["for"]("react.provider"):60109,h=d?Symbol["for"]("react.context"):60110,e=d?Symbol["for"]("react.async_mode"):60111,k=d?Symbol["for"]("react.forward_ref"):60112;b.typeOf=c;b.AsyncMode=e;b.ContextConsumer=h;b.ContextProvider=l;b.Element=m;b.ForwardRef=k;b.Fragment=f;b.Portal=n;b.StrictMode=g;b.isValidElementType=function(a){return"string"===typeof a||"function"===
11
+ typeof a||a===f||a===e||a===g||"object"===typeof a&&null!==a&&(a.$$typeof===l||a.$$typeof===h||a.$$typeof===k)};b.isAsyncMode=function(a){return c(a)===e};b.isContextConsumer=function(a){return c(a)===h};b.isContextProvider=function(a){return c(a)===l};b.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===m};b.isForwardRef=function(a){return c(a)===k};b.isFragment=function(a){return c(a)===f};b.isPortal=function(a){return c(a)===n};b.isStrictMode=function(a){return c(a)===g};Object.defineProperty(b,
12
+ "__esModule",{value:!0})});