os-detect 1.0.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 +47 -0
- package/index.js +64 -0
- package/package.json +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# os-detect
|
|
2
|
+
|
|
3
|
+
Simple OS and device type detection for browsers (no dependencies).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install os-detect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const osDetect = require('os-detect');
|
|
15
|
+
|
|
16
|
+
console.log(osDetect.detectIsiOS()); // true/false
|
|
17
|
+
console.log(osDetect.detectIsMacOS()); // true/false
|
|
18
|
+
console.log(osDetect.detectIsAndroid()); // true/false
|
|
19
|
+
console.log(osDetect.detectIsWindows()); // true/false
|
|
20
|
+
console.log(osDetect.detectIsLinux()); // true/false
|
|
21
|
+
console.log(osDetect.isMobileDevice()); // true/false
|
|
22
|
+
console.log(osDetect.isDesktopDevice()); // true/false
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
- `detectIsiOS()`
|
|
28
|
+
- `detectIsMacOS()`
|
|
29
|
+
- `detectIsAndroid()`
|
|
30
|
+
- `detectIsWindows()`
|
|
31
|
+
- `detectIsLinux()`
|
|
32
|
+
- `isMobileDevice()`
|
|
33
|
+
- `isDesktopDevice()`
|
|
34
|
+
|
|
35
|
+
All functions return a boolean.
|
|
36
|
+
|
|
37
|
+
## Author
|
|
38
|
+
|
|
39
|
+
Danil Lisin Vladimirovich aka Macrulez
|
|
40
|
+
|
|
41
|
+
GitHub: [macrulezru](https://github.com/macrulezru)
|
|
42
|
+
|
|
43
|
+
Website: [macrulez.ru](https://macrulez.ru/)
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
let cachedIsiOS;
|
|
2
|
+
let cachedIsMacOS;
|
|
3
|
+
let cachedIsAndroid;
|
|
4
|
+
let cachedIsWindows;
|
|
5
|
+
let cachedIsLinux;
|
|
6
|
+
|
|
7
|
+
function detectIsiOS() {
|
|
8
|
+
if (typeof cachedIsiOS === 'boolean') return cachedIsiOS;
|
|
9
|
+
if (typeof navigator === 'undefined' || typeof window === 'undefined') return false;
|
|
10
|
+
const isIOSUA =
|
|
11
|
+
/iPad|iPhone|iPod/.test(navigator.userAgent) &&
|
|
12
|
+
typeof window.MSStream === 'undefined';
|
|
13
|
+
const hasMultiTouch =
|
|
14
|
+
'ontouchstart' in window ||
|
|
15
|
+
(typeof navigator.maxTouchPoints === 'number' && navigator.maxTouchPoints > 1);
|
|
16
|
+
cachedIsiOS = Boolean(isIOSUA && hasMultiTouch);
|
|
17
|
+
return cachedIsiOS;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function detectIsMacOS() {
|
|
21
|
+
if (typeof cachedIsMacOS === 'boolean') return cachedIsMacOS;
|
|
22
|
+
if (typeof navigator === 'undefined') return false;
|
|
23
|
+
cachedIsMacOS = /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent);
|
|
24
|
+
return cachedIsMacOS;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function detectIsAndroid() {
|
|
28
|
+
if (typeof cachedIsAndroid === 'boolean') return cachedIsAndroid;
|
|
29
|
+
if (typeof navigator === 'undefined') return false;
|
|
30
|
+
cachedIsAndroid = /Android/.test(navigator.userAgent);
|
|
31
|
+
return cachedIsAndroid;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function detectIsWindows() {
|
|
35
|
+
if (typeof cachedIsWindows === 'boolean') return cachedIsWindows;
|
|
36
|
+
if (typeof navigator === 'undefined') return false;
|
|
37
|
+
cachedIsWindows = /Win32|Win64|Windows|WinCE/.test(navigator.userAgent);
|
|
38
|
+
return cachedIsWindows;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function detectIsLinux() {
|
|
42
|
+
if (typeof cachedIsLinux === 'boolean') return cachedIsLinux;
|
|
43
|
+
if (typeof navigator === 'undefined') return false;
|
|
44
|
+
cachedIsLinux = /Linux/.test(navigator.userAgent) && !detectIsAndroid();
|
|
45
|
+
return cachedIsLinux;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isMobileDevice() {
|
|
49
|
+
return detectIsiOS() || detectIsAndroid();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isDesktopDevice() {
|
|
53
|
+
return detectIsMacOS() || detectIsWindows() || detectIsLinux();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = {
|
|
57
|
+
detectIsiOS,
|
|
58
|
+
detectIsMacOS,
|
|
59
|
+
detectIsAndroid,
|
|
60
|
+
detectIsWindows,
|
|
61
|
+
detectIsLinux,
|
|
62
|
+
isMobileDevice,
|
|
63
|
+
isDesktopDevice
|
|
64
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "os-detect",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Simple OS and device type detection for browsers (no dependencies)",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": ["os", "detect", "browser", "platform", "device", "mobile", "desktop"],
|
|
7
|
+
"author": "",
|
|
8
|
+
"license": "MIT"
|
|
9
|
+
}
|