os-detect 1.0.1 → 2.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/LICENSE +21 -0
- package/README.md +190 -19
- package/dist/index.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +229 -0
- package/dist/index.mjs +184 -0
- package/dist/index.umd.js +223 -0
- package/dist/react.d.mts +15 -0
- package/dist/react.d.ts +15 -0
- package/dist/react.js +198 -0
- package/dist/react.mjs +162 -0
- package/dist/react.umd.js +1653 -0
- package/dist/vue.d.mts +16 -0
- package/dist/vue.d.ts +16 -0
- package/dist/vue.js +200 -0
- package/dist/vue.mjs +164 -0
- package/dist/vue.umd.js +57212 -0
- package/package.json +93 -17
- package/index.js +0 -64
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Danil Lisin Vladimirovich (macrulez)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,38 +1,209 @@
|
|
|
1
1
|
# os-detect
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight utility for detecting the operating system and device type — in browsers, Node.js, and SSR. With React hooks and Vue composables. No dependencies.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```bash
|
|
8
8
|
npm install os-detect
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
```ts
|
|
14
|
+
import {
|
|
15
|
+
getOS,
|
|
16
|
+
detectIsIOS, detectIsMacOS, detectIsAndroid,
|
|
17
|
+
detectIsWindows, detectIsLinux, detectIsChromeOS,
|
|
18
|
+
detectIsWindows11,
|
|
19
|
+
isMobileDevice, isDesktopDevice,
|
|
20
|
+
} from 'os-detect';
|
|
21
|
+
|
|
22
|
+
// Get OS as a string
|
|
23
|
+
getOS(); // 'ios' | 'macos' | 'android' | 'windows' | 'linux' | 'chromeos' | 'unknown'
|
|
24
|
+
|
|
25
|
+
// Boolean detection
|
|
26
|
+
detectIsIOS(); // true on iPhone, iPod, iPad (including iPadOS 13+)
|
|
27
|
+
detectIsMacOS(); // true on macOS desktop (correctly excludes iPadOS 13+)
|
|
28
|
+
detectIsAndroid(); // true on Android phones and tablets
|
|
29
|
+
detectIsWindows(); // true on Windows desktop or laptop
|
|
30
|
+
detectIsLinux(); // true on Linux desktop (excludes Android and ChromeOS)
|
|
31
|
+
detectIsChromeOS(); // true on ChromeOS devices
|
|
32
|
+
|
|
33
|
+
// Async: Windows 11 check
|
|
34
|
+
const isWin11 = await detectIsWindows11(); // true | false
|
|
35
|
+
|
|
36
|
+
// Device category
|
|
37
|
+
isMobileDevice(); // true if iOS or Android
|
|
38
|
+
isDesktopDevice(); // true if macOS, Windows, Linux, or ChromeOS
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
CommonJS:
|
|
13
42
|
```js
|
|
14
|
-
const
|
|
43
|
+
const { getOS, detectIsIOS, isMobileDevice } = require('os-detect');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
UMD via `<script>` tag:
|
|
47
|
+
```html
|
|
48
|
+
<script src="https://unpkg.com/os-detect/dist/index.umd.js"></script>
|
|
49
|
+
<script>
|
|
50
|
+
console.log(OsDetect.getOS());
|
|
51
|
+
console.log(OsDetect.detectIsIOS());
|
|
52
|
+
console.log(OsDetect.isMobileDevice());
|
|
53
|
+
</script>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## React
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { useOS, useIsWindows11 } from 'os-detect/react';
|
|
62
|
+
|
|
63
|
+
function App() {
|
|
64
|
+
const os = useOS(); // 'windows' | 'macos' | 'ios' | ...
|
|
65
|
+
const isWin11 = useIsWindows11(); // null (loading) → true | false
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
<p>OS: {os}</p>
|
|
70
|
+
{isWin11 === null && <p>Detecting Windows version...</p>}
|
|
71
|
+
{isWin11 === true && <p>Windows 11</p>}
|
|
72
|
+
{isWin11 === false && os === 'windows' && <p>Windows 10 or older</p>}
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Requires React 17+.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Vue
|
|
83
|
+
|
|
84
|
+
```vue
|
|
85
|
+
<script setup lang="ts">
|
|
86
|
+
import { useOS, useIsWindows11 } from 'os-detect/vue';
|
|
87
|
+
|
|
88
|
+
const os = useOS(); // Readonly<Ref<OS>>
|
|
89
|
+
const isWin11 = useIsWindows11(); // Readonly<Ref<boolean | null>>
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<template>
|
|
93
|
+
<p>OS: {{ os }}</p>
|
|
94
|
+
<p v-if="isWin11 === null">Detecting Windows version...</p>
|
|
95
|
+
<p v-else-if="isWin11">Windows 11</p>
|
|
96
|
+
<p v-else-if="os === 'windows'">Windows 10 or older</p>
|
|
97
|
+
</template>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Requires Vue 3+.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Node.js & SSR
|
|
105
|
+
|
|
106
|
+
All functions work in Node.js via `process.platform`:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { getOS, detectIsWindows, detectIsWindows11 } from 'os-detect';
|
|
110
|
+
|
|
111
|
+
// Reads process.platform — no browser required
|
|
112
|
+
getOS(); // 'macos' | 'windows' | 'linux' | 'android' | 'unknown'
|
|
113
|
+
detectIsWindows(); // true on Windows
|
|
15
114
|
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
115
|
+
// Windows 11 via os.release() build number (>= 22000)
|
|
116
|
+
const isWin11 = await detectIsWindows11();
|
|
23
117
|
```
|
|
24
118
|
|
|
25
|
-
|
|
119
|
+
| `process.platform` | Detected as |
|
|
120
|
+
|---|---|
|
|
121
|
+
| `darwin` | macOS |
|
|
122
|
+
| `win32` | Windows (32-bit and 64-bit) |
|
|
123
|
+
| `linux` | Linux |
|
|
124
|
+
| `android` | Android |
|
|
26
125
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
126
|
+
Functions that require a browser environment (`detectIsIOS()`, `detectIsChromeOS()`) always return `false` in Node.js.
|
|
127
|
+
|
|
128
|
+
> **SSR hydration note**: In Next.js / Nuxt SSR, `getOS()` returns the **server's** OS, not the client's. To avoid hydration mismatches, wrap detection in `useEffect` (React) or `onMounted` (Vue) so it runs only on the client.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## API Reference
|
|
133
|
+
|
|
134
|
+
### OS String Detection
|
|
135
|
+
|
|
136
|
+
| Function | Returns |
|
|
137
|
+
|---|---|
|
|
138
|
+
| `getOS()` | `'ios'` \| `'macos'` \| `'android'` \| `'windows'` \| `'linux'` \| `'chromeos'` \| `'unknown'` |
|
|
139
|
+
|
|
140
|
+
### Boolean Detection
|
|
141
|
+
|
|
142
|
+
| Function | Returns `true` when | Node.js |
|
|
143
|
+
|---|---|---|
|
|
144
|
+
| `detectIsIOS()` | iPhone, iPod, or iPad (including iPadOS 13+) | always `false` |
|
|
145
|
+
| `detectIsMacOS()` | macOS desktop (excludes iPadOS 13+) | `process.platform === 'darwin'` |
|
|
146
|
+
| `detectIsAndroid()` | Android phones and tablets | `process.platform === 'android'` |
|
|
147
|
+
| `detectIsWindows()` | Windows desktop or laptop | `process.platform === 'win32'` |
|
|
148
|
+
| `detectIsLinux()` | Linux desktop (excludes Android and ChromeOS) | `process.platform === 'linux'` |
|
|
149
|
+
| `detectIsChromeOS()` | ChromeOS devices | always `false` |
|
|
150
|
+
| `detectIsWindows11()` | Windows 11 — **async**, `Promise<boolean>` | via `os.release()` |
|
|
151
|
+
|
|
152
|
+
### Device Category
|
|
153
|
+
|
|
154
|
+
| Function | Returns `true` when |
|
|
155
|
+
|---|---|
|
|
156
|
+
| `isMobileDevice()` | iOS or Android |
|
|
157
|
+
| `isDesktopDevice()` | macOS, Windows, Linux, or ChromeOS |
|
|
158
|
+
|
|
159
|
+
> `isMobileDevice()` and `isDesktopDevice()` are **not mutually exclusive** — a device with an unrecognized OS returns `false` for both.
|
|
160
|
+
|
|
161
|
+
### React Hooks
|
|
162
|
+
|
|
163
|
+
Import from `os-detect/react`:
|
|
164
|
+
|
|
165
|
+
| Hook | Returns |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `useOS()` | `OS` string — synchronous, cached |
|
|
168
|
+
| `useIsWindows11()` | `boolean \| null` — `null` while detecting |
|
|
169
|
+
|
|
170
|
+
### Vue Composables
|
|
171
|
+
|
|
172
|
+
Import from `os-detect/vue`:
|
|
173
|
+
|
|
174
|
+
| Composable | Returns |
|
|
175
|
+
|---|---|
|
|
176
|
+
| `useOS()` | `Readonly<Ref<OS>>` — synchronous, cached |
|
|
177
|
+
| `useIsWindows11()` | `Readonly<Ref<boolean \| null>>` — `null` while detecting |
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Detection Strategy
|
|
182
|
+
|
|
183
|
+
**Browser**: prefers `navigator.userAgentData` (Chrome 90+ / Edge 90+), falls back to `navigator.userAgent` for all other browsers.
|
|
184
|
+
|
|
185
|
+
**Node.js**: reads `process.platform` when `navigator` is absent.
|
|
186
|
+
|
|
187
|
+
Results are cached after the first call — subsequent calls have zero overhead.
|
|
188
|
+
|
|
189
|
+
`detectIsWindows11()` in the browser uses `userAgentData.getHighEntropyValues(['platformVersion'])` — Windows 11 reports `platformVersion >= 13.0.0`. In Node.js it uses `os.release()` — Windows 11 has build number `>= 22000`. Returns `false` if the API is unavailable or the call fails.
|
|
190
|
+
|
|
191
|
+
### iPadOS 13+ note
|
|
192
|
+
|
|
193
|
+
Since iPadOS 13, Safari sends `Macintosh` in the userAgent string. `detectIsIOS()` correctly identifies these devices using `navigator.maxTouchPoints > 1`, and `detectIsMacOS()` excludes them accordingly.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Migration from v1.x
|
|
198
|
+
|
|
199
|
+
`detectIsiOS()` was renamed to `detectIsIOS()`. The old name still works but logs a deprecation warning and will be removed in v3.0.
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
detectIsiOS() // deprecated — logs console.warn
|
|
203
|
+
detectIsIOS() // use this instead
|
|
204
|
+
```
|
|
34
205
|
|
|
35
|
-
|
|
206
|
+
---
|
|
36
207
|
|
|
37
208
|
## Author
|
|
38
209
|
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare function detectIsIOS(): boolean;
|
|
2
|
+
declare function detectIsMacOS(): boolean;
|
|
3
|
+
declare function detectIsAndroid(): boolean;
|
|
4
|
+
declare function detectIsWindows(): boolean;
|
|
5
|
+
declare function detectIsChromeOS(): boolean;
|
|
6
|
+
declare function detectIsLinux(): boolean;
|
|
7
|
+
declare function detectIsWindows11(): Promise<boolean>;
|
|
8
|
+
type OS = 'ios' | 'macos' | 'android' | 'windows' | 'linux' | 'chromeos' | 'unknown';
|
|
9
|
+
declare function getOS(): OS;
|
|
10
|
+
declare function isMobileDevice(): boolean;
|
|
11
|
+
declare function isDesktopDevice(): boolean;
|
|
12
|
+
/** @deprecated Use detectIsIOS() instead. Will be removed in v3.0. */
|
|
13
|
+
declare function detectIsiOS(): boolean;
|
|
14
|
+
declare const osDetect: {
|
|
15
|
+
detectIsIOS: typeof detectIsIOS;
|
|
16
|
+
detectIsMacOS: typeof detectIsMacOS;
|
|
17
|
+
detectIsAndroid: typeof detectIsAndroid;
|
|
18
|
+
detectIsWindows: typeof detectIsWindows;
|
|
19
|
+
detectIsLinux: typeof detectIsLinux;
|
|
20
|
+
detectIsChromeOS: typeof detectIsChromeOS;
|
|
21
|
+
detectIsWindows11: typeof detectIsWindows11;
|
|
22
|
+
getOS: typeof getOS;
|
|
23
|
+
isMobileDevice: typeof isMobileDevice;
|
|
24
|
+
isDesktopDevice: typeof isDesktopDevice;
|
|
25
|
+
detectIsiOS: typeof detectIsiOS;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { type OS, osDetect as default, detectIsAndroid, detectIsChromeOS, detectIsIOS, detectIsLinux, detectIsMacOS, detectIsWindows, detectIsWindows11, detectIsiOS, getOS, isDesktopDevice, isMobileDevice };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare function detectIsIOS(): boolean;
|
|
2
|
+
declare function detectIsMacOS(): boolean;
|
|
3
|
+
declare function detectIsAndroid(): boolean;
|
|
4
|
+
declare function detectIsWindows(): boolean;
|
|
5
|
+
declare function detectIsChromeOS(): boolean;
|
|
6
|
+
declare function detectIsLinux(): boolean;
|
|
7
|
+
declare function detectIsWindows11(): Promise<boolean>;
|
|
8
|
+
type OS = 'ios' | 'macos' | 'android' | 'windows' | 'linux' | 'chromeos' | 'unknown';
|
|
9
|
+
declare function getOS(): OS;
|
|
10
|
+
declare function isMobileDevice(): boolean;
|
|
11
|
+
declare function isDesktopDevice(): boolean;
|
|
12
|
+
/** @deprecated Use detectIsIOS() instead. Will be removed in v3.0. */
|
|
13
|
+
declare function detectIsiOS(): boolean;
|
|
14
|
+
declare const osDetect: {
|
|
15
|
+
detectIsIOS: typeof detectIsIOS;
|
|
16
|
+
detectIsMacOS: typeof detectIsMacOS;
|
|
17
|
+
detectIsAndroid: typeof detectIsAndroid;
|
|
18
|
+
detectIsWindows: typeof detectIsWindows;
|
|
19
|
+
detectIsLinux: typeof detectIsLinux;
|
|
20
|
+
detectIsChromeOS: typeof detectIsChromeOS;
|
|
21
|
+
detectIsWindows11: typeof detectIsWindows11;
|
|
22
|
+
getOS: typeof getOS;
|
|
23
|
+
isMobileDevice: typeof isMobileDevice;
|
|
24
|
+
isDesktopDevice: typeof isDesktopDevice;
|
|
25
|
+
detectIsiOS: typeof detectIsiOS;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { type OS, osDetect as default, detectIsAndroid, detectIsChromeOS, detectIsIOS, detectIsLinux, detectIsMacOS, detectIsWindows, detectIsWindows11, detectIsiOS, getOS, isDesktopDevice, isMobileDevice };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => index_default,
|
|
34
|
+
detectIsAndroid: () => detectIsAndroid,
|
|
35
|
+
detectIsChromeOS: () => detectIsChromeOS,
|
|
36
|
+
detectIsIOS: () => detectIsIOS,
|
|
37
|
+
detectIsLinux: () => detectIsLinux,
|
|
38
|
+
detectIsMacOS: () => detectIsMacOS,
|
|
39
|
+
detectIsWindows: () => detectIsWindows,
|
|
40
|
+
detectIsWindows11: () => detectIsWindows11,
|
|
41
|
+
detectIsiOS: () => detectIsiOS,
|
|
42
|
+
getOS: () => getOS,
|
|
43
|
+
isDesktopDevice: () => isDesktopDevice,
|
|
44
|
+
isMobileDevice: () => isMobileDevice
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
var cachedIsIOS;
|
|
48
|
+
var cachedIsMacOS;
|
|
49
|
+
var cachedIsAndroid;
|
|
50
|
+
var cachedIsWindows;
|
|
51
|
+
var cachedIsLinux;
|
|
52
|
+
var cachedIsChromeOS;
|
|
53
|
+
function getUADataPlatform() {
|
|
54
|
+
if (typeof navigator === "undefined") return null;
|
|
55
|
+
const uaData = navigator.userAgentData;
|
|
56
|
+
if (uaData && typeof uaData.platform === "string") {
|
|
57
|
+
return uaData.platform.toLowerCase();
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function getNodePlatform() {
|
|
62
|
+
if (typeof navigator !== "undefined") return null;
|
|
63
|
+
if (typeof process === "undefined" || typeof process.platform !== "string") return null;
|
|
64
|
+
return process.platform;
|
|
65
|
+
}
|
|
66
|
+
function detectIsIOS() {
|
|
67
|
+
if (typeof cachedIsIOS === "boolean") return cachedIsIOS;
|
|
68
|
+
if (typeof navigator === "undefined" || typeof window === "undefined") {
|
|
69
|
+
return cachedIsIOS = false;
|
|
70
|
+
}
|
|
71
|
+
const platform = getUADataPlatform();
|
|
72
|
+
if (platform !== null) {
|
|
73
|
+
cachedIsIOS = platform === "ios";
|
|
74
|
+
return cachedIsIOS;
|
|
75
|
+
}
|
|
76
|
+
const isClassicIOSUA = /iPhone|iPod/.test(navigator.userAgent);
|
|
77
|
+
const isIPadUA = /iPad/.test(navigator.userAgent);
|
|
78
|
+
const isIPadOS = /Macintosh/.test(navigator.userAgent) && typeof navigator.maxTouchPoints === "number" && navigator.maxTouchPoints > 1;
|
|
79
|
+
cachedIsIOS = isClassicIOSUA || isIPadUA || isIPadOS;
|
|
80
|
+
return cachedIsIOS;
|
|
81
|
+
}
|
|
82
|
+
function detectIsMacOS() {
|
|
83
|
+
if (typeof cachedIsMacOS === "boolean") return cachedIsMacOS;
|
|
84
|
+
const nodePlatform = getNodePlatform();
|
|
85
|
+
if (nodePlatform !== null) {
|
|
86
|
+
return cachedIsMacOS = nodePlatform === "darwin";
|
|
87
|
+
}
|
|
88
|
+
if (typeof navigator === "undefined") return cachedIsMacOS = false;
|
|
89
|
+
const platform = getUADataPlatform();
|
|
90
|
+
if (platform !== null) {
|
|
91
|
+
cachedIsMacOS = platform === "macos";
|
|
92
|
+
return cachedIsMacOS;
|
|
93
|
+
}
|
|
94
|
+
const isMacUA = /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent);
|
|
95
|
+
cachedIsMacOS = isMacUA && !detectIsIOS();
|
|
96
|
+
return cachedIsMacOS;
|
|
97
|
+
}
|
|
98
|
+
function detectIsAndroid() {
|
|
99
|
+
if (typeof cachedIsAndroid === "boolean") return cachedIsAndroid;
|
|
100
|
+
const nodePlatform = getNodePlatform();
|
|
101
|
+
if (nodePlatform !== null) {
|
|
102
|
+
return cachedIsAndroid = nodePlatform === "android";
|
|
103
|
+
}
|
|
104
|
+
if (typeof navigator === "undefined") return cachedIsAndroid = false;
|
|
105
|
+
const platform = getUADataPlatform();
|
|
106
|
+
if (platform !== null) {
|
|
107
|
+
cachedIsAndroid = platform === "android";
|
|
108
|
+
return cachedIsAndroid;
|
|
109
|
+
}
|
|
110
|
+
cachedIsAndroid = /Android/.test(navigator.userAgent);
|
|
111
|
+
return cachedIsAndroid;
|
|
112
|
+
}
|
|
113
|
+
function detectIsWindows() {
|
|
114
|
+
if (typeof cachedIsWindows === "boolean") return cachedIsWindows;
|
|
115
|
+
const nodePlatform = getNodePlatform();
|
|
116
|
+
if (nodePlatform !== null) {
|
|
117
|
+
return cachedIsWindows = nodePlatform === "win32";
|
|
118
|
+
}
|
|
119
|
+
if (typeof navigator === "undefined") return cachedIsWindows = false;
|
|
120
|
+
const platform = getUADataPlatform();
|
|
121
|
+
if (platform !== null) {
|
|
122
|
+
cachedIsWindows = platform === "windows";
|
|
123
|
+
return cachedIsWindows;
|
|
124
|
+
}
|
|
125
|
+
cachedIsWindows = /Win32|Win64|Windows|WinCE/.test(navigator.userAgent);
|
|
126
|
+
return cachedIsWindows;
|
|
127
|
+
}
|
|
128
|
+
function detectIsChromeOS() {
|
|
129
|
+
if (typeof cachedIsChromeOS === "boolean") return cachedIsChromeOS;
|
|
130
|
+
if (typeof navigator === "undefined") return cachedIsChromeOS = false;
|
|
131
|
+
const platform = getUADataPlatform();
|
|
132
|
+
if (platform !== null) {
|
|
133
|
+
cachedIsChromeOS = platform === "chrome os" || platform === "chromeos";
|
|
134
|
+
return cachedIsChromeOS;
|
|
135
|
+
}
|
|
136
|
+
cachedIsChromeOS = /CrOS/.test(navigator.userAgent);
|
|
137
|
+
return cachedIsChromeOS;
|
|
138
|
+
}
|
|
139
|
+
function detectIsLinux() {
|
|
140
|
+
if (typeof cachedIsLinux === "boolean") return cachedIsLinux;
|
|
141
|
+
const nodePlatform = getNodePlatform();
|
|
142
|
+
if (nodePlatform !== null) {
|
|
143
|
+
return cachedIsLinux = nodePlatform === "linux";
|
|
144
|
+
}
|
|
145
|
+
if (typeof navigator === "undefined") return cachedIsLinux = false;
|
|
146
|
+
const platform = getUADataPlatform();
|
|
147
|
+
if (platform !== null) {
|
|
148
|
+
cachedIsLinux = platform === "linux";
|
|
149
|
+
return cachedIsLinux;
|
|
150
|
+
}
|
|
151
|
+
cachedIsLinux = /Linux/.test(navigator.userAgent) && !detectIsAndroid() && !detectIsChromeOS();
|
|
152
|
+
return cachedIsLinux;
|
|
153
|
+
}
|
|
154
|
+
async function detectIsWindows11() {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
if (!detectIsWindows()) return false;
|
|
157
|
+
if (typeof navigator === "undefined" && typeof process !== "undefined") {
|
|
158
|
+
try {
|
|
159
|
+
const { release } = await import("os");
|
|
160
|
+
const buildNumber = parseInt((_a = release().split(".")[2]) != null ? _a : "0", 10);
|
|
161
|
+
return buildNumber >= 22e3;
|
|
162
|
+
} catch (e) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const nav = navigator;
|
|
168
|
+
if (!((_b = nav.userAgentData) == null ? void 0 : _b.getHighEntropyValues)) return false;
|
|
169
|
+
const { platformVersion } = await nav.userAgentData.getHighEntropyValues([
|
|
170
|
+
"platformVersion"
|
|
171
|
+
]);
|
|
172
|
+
if (!platformVersion) return false;
|
|
173
|
+
const majorVersion = parseInt(platformVersion.split(".")[0], 10);
|
|
174
|
+
return majorVersion >= 13;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function getOS() {
|
|
180
|
+
if (detectIsIOS()) return "ios";
|
|
181
|
+
if (detectIsAndroid()) return "android";
|
|
182
|
+
if (detectIsChromeOS()) return "chromeos";
|
|
183
|
+
if (detectIsLinux()) return "linux";
|
|
184
|
+
if (detectIsMacOS()) return "macos";
|
|
185
|
+
if (detectIsWindows()) return "windows";
|
|
186
|
+
return "unknown";
|
|
187
|
+
}
|
|
188
|
+
function isMobileDevice() {
|
|
189
|
+
return detectIsIOS() || detectIsAndroid();
|
|
190
|
+
}
|
|
191
|
+
function isDesktopDevice() {
|
|
192
|
+
return detectIsMacOS() || detectIsWindows() || detectIsLinux() || detectIsChromeOS();
|
|
193
|
+
}
|
|
194
|
+
function detectIsiOS() {
|
|
195
|
+
if (typeof console !== "undefined") {
|
|
196
|
+
console.warn(
|
|
197
|
+
"[os-detect] detectIsiOS() is deprecated. Use detectIsIOS() instead. Will be removed in v3.0."
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
return detectIsIOS();
|
|
201
|
+
}
|
|
202
|
+
var osDetect = {
|
|
203
|
+
detectIsIOS,
|
|
204
|
+
detectIsMacOS,
|
|
205
|
+
detectIsAndroid,
|
|
206
|
+
detectIsWindows,
|
|
207
|
+
detectIsLinux,
|
|
208
|
+
detectIsChromeOS,
|
|
209
|
+
detectIsWindows11,
|
|
210
|
+
getOS,
|
|
211
|
+
isMobileDevice,
|
|
212
|
+
isDesktopDevice,
|
|
213
|
+
detectIsiOS
|
|
214
|
+
};
|
|
215
|
+
var index_default = osDetect;
|
|
216
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
+
0 && (module.exports = {
|
|
218
|
+
detectIsAndroid,
|
|
219
|
+
detectIsChromeOS,
|
|
220
|
+
detectIsIOS,
|
|
221
|
+
detectIsLinux,
|
|
222
|
+
detectIsMacOS,
|
|
223
|
+
detectIsWindows,
|
|
224
|
+
detectIsWindows11,
|
|
225
|
+
detectIsiOS,
|
|
226
|
+
getOS,
|
|
227
|
+
isDesktopDevice,
|
|
228
|
+
isMobileDevice
|
|
229
|
+
});
|