Skip to content

Commit 7153b07

Browse files
authored
Merge pull request #91 from duskload/feature/Add-Edge-Chromium
Feature/add edge chromium
2 parents e9b170e + ee0ae0d commit 7153b07

File tree

7 files changed

+86
-16
lines changed

7 files changed

+86
-16
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const styles = {
127127
| isSafari | bool | returns true if browser is `Safari` |
128128
| isOpera | bool | returns true if browser is `Opera` |
129129
| isIE | bool | returns true if browser is `Internet Explorer` |
130-
| isEdge | bool | returns true if browser is `Edge` |
130+
| isEdge | bool | returns true if browser is `Edge` or `Edge Chromium` |
131131
| isYandex | bool | returns true if browser is `Yandex` |
132132
| isChromium | bool | returns true if browser is `Chromium` |
133133
| isMobileSafari | bool | returns true if browser is `Mobile Safari` |
@@ -146,9 +146,12 @@ const styles = {
146146
| isIPhone13 | boolean | returns true/false if device is iPhone and running on iOS13 |
147147
| isIPad13 | boolean | returns true/false if device is iPad and running on iOS13 |
148148
| isIPod13 | boolean | returns true/false if device is iPod and running on iOS13 |
149-
| isElectron | boolean | returns true/false if running on Electron |
150-
| deviceDetect | function | return data object which includes all data about device (e.g version, engine, os etc.) |
151-
149+
| isElectron | boolean | returns true/false if running on `Electron` |
150+
| isEdgeChromium | boolean | returns true/false if browser is `Edge Chromium` |
151+
| isLegacyEdge | boolean | returns true if browser is `Edge` |
152+
| isWindows | boolean | returns true/false if os is `Windows` |
153+
| isMacOs | boolean | returns true/false if os is `Mac OS` |
154+
| deviceDetect | boolean | return data object which includes all data about device (e.g version, engine, os etc.) |
152155
### Views
153156

154157
Available views:
@@ -196,6 +199,17 @@ App = withOrientationChange(App)
196199
export { App }
197200
```
198201

202+
### Testing
203+
204+
```js
205+
import * as rdd from 'react-device-detect';
206+
207+
rdd.isMobile = true;
208+
209+
// use in tests
210+
211+
```
212+
199213
## License
200214

201215
MIT

index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ declare module "react-device-detect" {
5656
export import isIPhone13 = ReactDeviceDetect.isIPhone13;
5757
export import isIPod13 = ReactDeviceDetect.isIPod13;
5858
export import isElectron = ReactDeviceDetect.isElectron;
59+
export import isEdgeChromium = ReactDeviceDetect.isEdgeChromium;
60+
export import isLegacyEdge = ReactDeviceDetect.isLegacyEdge;
61+
export import isWindows = ReactDeviceDetect.isWindows;
62+
export import isMacOs = ReactDeviceDetect.isMacOs;
5963
export import withOrientationChange = ReactDeviceDetect.withOrientationChange;
6064
}
6165

@@ -184,4 +188,12 @@ declare namespace ReactDeviceDetect {
184188
export const isIPod13: boolean;
185189

186190
export const isElectron: boolean;
191+
192+
export const isEdgeChromium: boolean;
193+
194+
export const isLegacyEdge: boolean;
195+
196+
export const isWindows: boolean;
197+
198+
export const isMacOs: boolean;
187199
}

main.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var getNavigatorInstance = function getNavigatorInstance() {
3232
};
3333
var isIOS13Check = function isIOS13Check(type) {
3434
var nav = getNavigatorInstance();
35-
return nav && (nav.platform.indexOf(type) !== -1 || nav.platform === 'MacIntel' && nav.maxTouchPoints > 1 && !window.MSStream);
35+
return nav && nav.platform && (nav.platform.indexOf(type) !== -1 || nav.platform === 'MacIntel' && nav.maxTouchPoints > 1 && !window.MSStream);
3636
};
3737

3838
function _typeof(obj) {
@@ -203,12 +203,15 @@ var BROWSER_TYPES = {
203203
EDGE: "Edge",
204204
CHROMIUM: "Chromium",
205205
IE: 'IE',
206-
MOBILE_SAFARI: "Mobile Safari"
206+
MOBILE_SAFARI: "Mobile Safari",
207+
EDGE_CHROMIUM: "Edge Chromium"
207208
};
208209
var OS_TYPES = {
209210
IOS: 'iOS',
210211
ANDROID: "Android",
211-
WINDOWS_PHONE: "Windows Phone"
212+
WINDOWS_PHONE: "Windows Phone",
213+
WINDOWS: 'Windows',
214+
MAC_OS: 'Mac OS'
212215
};
213216
var initialData = {
214217
isMobile: false,
@@ -361,6 +364,14 @@ var isMobileAndTabletType = function isMobileAndTabletType() {
361364
}
362365
};
363366

367+
var isEdgeChromiumType = function isEdgeChromiumType() {
368+
if (os.name === OS_TYPES.WINDOWS && os.version === '10') {
369+
return typeof ua === 'string' && ua.indexOf('Edg/') !== -1;
370+
}
371+
372+
return false;
373+
};
374+
364375
var isSmartTVType = function isSmartTVType() {
365376
return device.type === DEVICE_TYPES.SMART_TV;
366377
};
@@ -381,6 +392,14 @@ var isAndroidType = function isAndroidType() {
381392
return os.name === OS_TYPES.ANDROID;
382393
};
383394

395+
var isWindowsType = function isWindowsType() {
396+
return os.name === OS_TYPES.WINDOWS;
397+
};
398+
399+
var isMacOsType = function isMacOsType() {
400+
return os.name === OS_TYPES.MAC_OS;
401+
};
402+
384403
var isWinPhoneType = function isWinPhoneType() {
385404
return os.name === OS_TYPES.WINDOWS_PHONE;
386405
};
@@ -519,14 +538,18 @@ var mobileModel = getMobileModel();
519538
var engineName = getEngineName();
520539
var engineVersion = getEngineVersion();
521540
var getUA = getUseragent();
522-
var isEdge = isEdgeType();
541+
var isEdge = isEdgeType() || isEdgeChromiumType();
523542
var isYandex = isYandexType();
524543
var deviceType = getDeviceType();
525544
var isIOS13 = getIOS13();
526545
var isIPad13 = getIPad13();
527546
var isIPhone13 = getIphone13();
528547
var isIPod13 = getIPod13();
529548
var isElectron = isElectronType();
549+
var isEdgeChromium = isEdgeChromiumType();
550+
var isLegacyEdge = isEdgeType();
551+
var isWindows = isWindowsType();
552+
var isMacOs = isMacOsType();
530553

531554
var AndroidView = function AndroidView(_ref) {
532555
var renderWithFragment = _ref.renderWithFragment,
@@ -756,6 +779,7 @@ exports.isChrome = isChrome;
756779
exports.isChromium = isChromium;
757780
exports.isConsole = isConsole;
758781
exports.isEdge = isEdge;
782+
exports.isEdgeChromium = isEdgeChromium;
759783
exports.isElectron = isElectron;
760784
exports.isFirefox = isFirefox;
761785
exports.isIE = isIE;
@@ -764,6 +788,8 @@ exports.isIOS13 = isIOS13;
764788
exports.isIPad13 = isIPad13;
765789
exports.isIPhone13 = isIPhone13;
766790
exports.isIPod13 = isIPod13;
791+
exports.isLegacyEdge = isLegacyEdge;
792+
exports.isMacOs = isMacOs;
767793
exports.isMobile = isMobile;
768794
exports.isMobileOnly = isMobileOnly;
769795
exports.isMobileSafari = isMobileSafari;
@@ -773,6 +799,7 @@ exports.isSmartTV = isSmartTV;
773799
exports.isTablet = isTablet;
774800
exports.isWearable = isWearable;
775801
exports.isWinPhone = isWinPhone;
802+
exports.isWindows = isWindows;
776803
exports.isYandex = isYandex;
777804
exports.mobileModel = mobileModel;
778805
exports.mobileVendor = mobileVendor;

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-device-detect",
3-
"version": "1.12.1",
3+
"version": "1.13.1",
44
"description": "Detect device type and render your component according to it",
55
"main": "main.js",
66
"typings": "./index.d.ts",

src/components/helpers/selectors.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ const isMobileAndTabletType = () => {
1414
}
1515
};
1616

17+
const isEdgeChromiumType = () => {
18+
if (os.name === OS_TYPES.WINDOWS && os.version === '10') {
19+
return typeof ua === 'string' && ua.indexOf('Edg/') !== -1;
20+
}
21+
22+
return false;
23+
};
24+
1725
const isSmartTVType = () => device.type === DEVICE_TYPES.SMART_TV;
1826
const isBrowserType = () => device.type === DEVICE_TYPES.BROWSER;
1927
const isWearableType = () => device.type === DEVICE_TYPES.WEARABLE;
2028
const isConsoleType = () => device.type === DEVICE_TYPES.CONSOLE;
2129
const isAndroidType = () => os.name === OS_TYPES.ANDROID;
30+
const isWindowsType = () => os.name === OS_TYPES.WINDOWS;
31+
const isMacOsType = () => os.name === OS_TYPES.MAC_OS;
2232
const isWinPhoneType = () => os.name === OS_TYPES.WINDOWS_PHONE;
2333
const isIOSType = () => os.name === OS_TYPES.IOS;
2434
const isChromeType = () => browser.name === BROWSER_TYPES.CHROME;
@@ -89,11 +99,15 @@ export const mobileModel = getMobileModel();
8999
export const engineName = getEngineName();
90100
export const engineVersion = getEngineVersion();
91101
export const getUA = getUseragent();
92-
export const isEdge = isEdgeType();
102+
export const isEdge = isEdgeType() || isEdgeChromiumType();
93103
export const isYandex = isYandexType();
94104
export const deviceType = getDeviceType();
95105
export const isIOS13 = getIOS13();
96106
export const isIPad13 = getIPad13();
97107
export const isIPhone13 = getIphone13();
98108
export const isIPod13 = getIPod13();
99109
export const isElectron = isElectronType();
110+
export const isEdgeChromium = isEdgeChromiumType();
111+
export const isLegacyEdge = isEdgeType();
112+
export const isWindows = isWindowsType();
113+
export const isMacOs = isMacOsType();

src/components/helpers/types.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ export const BROWSER_TYPES = {
1919
EDGE: "Edge",
2020
CHROMIUM: "Chromium",
2121
IE: 'IE',
22-
MOBILE_SAFARI: "Mobile Safari"
22+
MOBILE_SAFARI: "Mobile Safari",
23+
EDGE_CHROMIUM: "Edge Chromium"
2324
};
2425

2526
export const OS_TYPES = {
2627
IOS: 'iOS',
2728
ANDROID: "Android",
28-
WINDOWS_PHONE: "Windows Phone"
29+
WINDOWS_PHONE: "Windows Phone",
30+
WINDOWS: 'Windows',
31+
MAC_OS: 'Mac OS'
2932
};
3033

3134
const initialData = {

0 commit comments

Comments
 (0)