@ouroboros/browser 0.5.3 → 0.5.4
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 +1 -1
- package/devices.d.ts +12 -0
- package/devices.js +25 -1
- package/package.json +1 -1
- package/src/devices.ts +30 -1
- package/ouroboros-browser-0.5.3.tgz +0 -0
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ import { cookies } from '@ouroboros/browser';
|
|
|
46
46
|
Import Devices into your code
|
|
47
47
|
|
|
48
48
|
```javascript
|
|
49
|
-
import devices, { hasPointer } from '@ouroboros/browser/devices';
|
|
49
|
+
import devices, { hasPointer, isMobile } from '@ouroboros/browser/devices';
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
or
|
package/devices.d.ts
CHANGED
|
@@ -17,7 +17,19 @@
|
|
|
17
17
|
* @returns bool
|
|
18
18
|
*/
|
|
19
19
|
export declare function hasPointer(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Is Mobile
|
|
22
|
+
*
|
|
23
|
+
* Returns true only if the device appears to be a mobile device, but does not
|
|
24
|
+
* gaurantee anything.
|
|
25
|
+
*
|
|
26
|
+
* @name isMobile
|
|
27
|
+
* @access public
|
|
28
|
+
* @returns bool
|
|
29
|
+
*/
|
|
30
|
+
export declare function isMobile(): boolean;
|
|
20
31
|
declare const devices: {
|
|
21
32
|
hasPointer: typeof hasPointer;
|
|
33
|
+
isMobile: typeof isMobile;
|
|
22
34
|
};
|
|
23
35
|
export default devices;
|
package/devices.js
CHANGED
|
@@ -19,6 +19,30 @@
|
|
|
19
19
|
export function hasPointer() {
|
|
20
20
|
return window.matchMedia("(any-hover: hover)").matches;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Is Mobile
|
|
24
|
+
*
|
|
25
|
+
* Returns true only if the device appears to be a mobile device, but does not
|
|
26
|
+
* gaurantee anything.
|
|
27
|
+
*
|
|
28
|
+
* @name isMobile
|
|
29
|
+
* @access public
|
|
30
|
+
* @returns bool
|
|
31
|
+
*/
|
|
32
|
+
export function isMobile() {
|
|
33
|
+
// Mobile regex
|
|
34
|
+
const reMobile = /iPhone|Android.*Mobile|Mobile.*Android|KaiOS/i;
|
|
35
|
+
// If any of the following fail, we are probably on desktop
|
|
36
|
+
if (!reMobile.test(navigator.userAgent)
|
|
37
|
+
|| !('ontouchstart' in window)
|
|
38
|
+
|| !('orientation' in window)
|
|
39
|
+
|| window.innerWidth >= 768) {
|
|
40
|
+
// Not a mobile device
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Probably a mobile device
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
22
46
|
// Default export
|
|
23
|
-
const devices = { hasPointer };
|
|
47
|
+
const devices = { hasPointer, isMobile };
|
|
24
48
|
export default devices;
|
package/package.json
CHANGED
package/src/devices.ts
CHANGED
|
@@ -21,6 +21,35 @@ export function hasPointer(): boolean {
|
|
|
21
21
|
return window.matchMedia("(any-hover: hover)").matches
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Is Mobile
|
|
26
|
+
*
|
|
27
|
+
* Returns true only if the device appears to be a mobile device, but does not
|
|
28
|
+
* gaurantee anything.
|
|
29
|
+
*
|
|
30
|
+
* @name isMobile
|
|
31
|
+
* @access public
|
|
32
|
+
* @returns bool
|
|
33
|
+
*/
|
|
34
|
+
export function isMobile(): boolean {
|
|
35
|
+
|
|
36
|
+
// Mobile regex
|
|
37
|
+
const reMobile = /iPhone|Android.*Mobile|Mobile.*Android|KaiOS/i;
|
|
38
|
+
|
|
39
|
+
// If any of the following fail, we are probably on desktop
|
|
40
|
+
if(!reMobile.test(navigator.userAgent)
|
|
41
|
+
|| !('ontouchstart' in window)
|
|
42
|
+
|| !('orientation' in window)
|
|
43
|
+
|| window.innerWidth >= 768) {
|
|
44
|
+
|
|
45
|
+
// Not a mobile device
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Probably a mobile device
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
24
53
|
// Default export
|
|
25
|
-
const devices = { hasPointer }
|
|
54
|
+
const devices = { hasPointer, isMobile }
|
|
26
55
|
export default devices;
|
|
Binary file
|