react-is 16.3.0-alpha.3 → 16.3.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.
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
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
105
|
+
#### StrictMode
|
|
76
106
|
|
|
77
107
|
```js
|
|
78
108
|
import React from "react";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.3.
|
|
1
|
+
/** @license React v16.3.2
|
|
2
2
|
* react-is.development.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
@@ -32,6 +32,12 @@ 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
33
|
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol['for']('react.forward_ref') : 0xead0;
|
|
34
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
|
+
}
|
|
40
|
+
|
|
35
41
|
function typeOf(object) {
|
|
36
42
|
if (typeof object === 'object' && object !== null) {
|
|
37
43
|
var $$typeof = object.$$typeof;
|
|
@@ -108,6 +114,7 @@ exports.ForwardRef = ForwardRef;
|
|
|
108
114
|
exports.Fragment = Fragment;
|
|
109
115
|
exports.Portal = Portal;
|
|
110
116
|
exports.StrictMode = StrictMode;
|
|
117
|
+
exports.isValidElementType = isValidElementType;
|
|
111
118
|
exports.isAsyncMode = isAsyncMode;
|
|
112
119
|
exports.isContextConsumer = isContextConsumer;
|
|
113
120
|
exports.isContextProvider = isContextProvider;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.3.
|
|
1
|
+
/** @license React v16.3.2
|
|
2
2
|
* react-is.production.min.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
@@ -8,5 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
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.
|
|
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.
|
|
3
|
+
"version": "16.3.2",
|
|
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.3"
|
|
17
|
-
},
|
|
18
15
|
"files": [
|
|
19
16
|
"LICENSE",
|
|
20
17
|
"README.md",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.3.
|
|
1
|
+
/** @license React v16.3.2
|
|
2
2
|
* react-is.development.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
@@ -30,6 +30,12 @@ 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
31
|
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol['for']('react.forward_ref') : 0xead0;
|
|
32
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
|
+
}
|
|
38
|
+
|
|
33
39
|
function typeOf(object) {
|
|
34
40
|
if (typeof object === 'object' && object !== null) {
|
|
35
41
|
var $$typeof = object.$$typeof;
|
|
@@ -106,6 +112,7 @@ exports.ForwardRef = ForwardRef;
|
|
|
106
112
|
exports.Fragment = Fragment;
|
|
107
113
|
exports.Portal = Portal;
|
|
108
114
|
exports.StrictMode = StrictMode;
|
|
115
|
+
exports.isValidElementType = isValidElementType;
|
|
109
116
|
exports.isAsyncMode = isAsyncMode;
|
|
110
117
|
exports.isContextConsumer = isContextConsumer;
|
|
111
118
|
exports.isContextProvider = isContextProvider;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.3.
|
|
1
|
+
/** @license React v16.3.2
|
|
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
|
|
10
|
-
60103,n=d?Symbol["for"]("react.portal"):60106,
|
|
11
|
-
k};b.isContextProvider=function(a){return c(a)===
|
|
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})});
|