os-detect 1.0.1 → 2.0.1

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/dist/vue.d.mts ADDED
@@ -0,0 +1,16 @@
1
+ import * as vue from 'vue';
2
+ import { OS } from './index.mjs';
3
+
4
+ /**
5
+ * Returns the current OS as a readonly ref with a string identifier.
6
+ * Detection is synchronous and cached.
7
+ */
8
+ declare function useOS(): Readonly<vue.Ref<OS, OS>>;
9
+ /**
10
+ * Asynchronously detects whether the current device runs Windows 11.
11
+ * Returns a readonly ref: null while detecting, then true or false.
12
+ * Requires navigator.userAgentData (Chrome 90+ / Edge 90+).
13
+ */
14
+ declare function useIsWindows11(): Readonly<vue.Ref<boolean | null, boolean | null>>;
15
+
16
+ export { useIsWindows11, useOS };
package/dist/vue.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import * as vue from 'vue';
2
+ import { OS } from './index.js';
3
+
4
+ /**
5
+ * Returns the current OS as a readonly ref with a string identifier.
6
+ * Detection is synchronous and cached.
7
+ */
8
+ declare function useOS(): Readonly<vue.Ref<OS, OS>>;
9
+ /**
10
+ * Asynchronously detects whether the current device runs Windows 11.
11
+ * Returns a readonly ref: null while detecting, then true or false.
12
+ * Requires navigator.userAgentData (Chrome 90+ / Edge 90+).
13
+ */
14
+ declare function useIsWindows11(): Readonly<vue.Ref<boolean | null, boolean | null>>;
15
+
16
+ export { useIsWindows11, useOS };
package/dist/vue.js ADDED
@@ -0,0 +1,200 @@
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/vue.ts
31
+ var vue_exports = {};
32
+ __export(vue_exports, {
33
+ useIsWindows11: () => useIsWindows11,
34
+ useOS: () => useOS
35
+ });
36
+ module.exports = __toCommonJS(vue_exports);
37
+ var import_vue = require("vue");
38
+
39
+ // src/index.ts
40
+ var cachedIsIOS;
41
+ var cachedIsMacOS;
42
+ var cachedIsAndroid;
43
+ var cachedIsWindows;
44
+ var cachedIsLinux;
45
+ var cachedIsChromeOS;
46
+ function getUADataPlatform() {
47
+ if (typeof navigator === "undefined") return null;
48
+ const uaData = navigator.userAgentData;
49
+ if (uaData && typeof uaData.platform === "string") {
50
+ return uaData.platform.toLowerCase();
51
+ }
52
+ return null;
53
+ }
54
+ function getNodePlatform() {
55
+ if (typeof navigator !== "undefined") return null;
56
+ if (typeof process === "undefined" || typeof process.platform !== "string") return null;
57
+ return process.platform;
58
+ }
59
+ function detectIsIOS() {
60
+ if (typeof cachedIsIOS === "boolean") return cachedIsIOS;
61
+ if (typeof navigator === "undefined" || typeof window === "undefined") {
62
+ return cachedIsIOS = false;
63
+ }
64
+ const platform = getUADataPlatform();
65
+ if (platform !== null) {
66
+ cachedIsIOS = platform === "ios";
67
+ return cachedIsIOS;
68
+ }
69
+ const isClassicIOSUA = /iPhone|iPod/.test(navigator.userAgent);
70
+ const isIPadUA = /iPad/.test(navigator.userAgent);
71
+ const isIPadOS = /Macintosh/.test(navigator.userAgent) && typeof navigator.maxTouchPoints === "number" && navigator.maxTouchPoints > 1;
72
+ cachedIsIOS = isClassicIOSUA || isIPadUA || isIPadOS;
73
+ return cachedIsIOS;
74
+ }
75
+ function detectIsMacOS() {
76
+ if (typeof cachedIsMacOS === "boolean") return cachedIsMacOS;
77
+ const nodePlatform = getNodePlatform();
78
+ if (nodePlatform !== null) {
79
+ return cachedIsMacOS = nodePlatform === "darwin";
80
+ }
81
+ if (typeof navigator === "undefined") return cachedIsMacOS = false;
82
+ const platform = getUADataPlatform();
83
+ if (platform !== null) {
84
+ cachedIsMacOS = platform === "macos";
85
+ return cachedIsMacOS;
86
+ }
87
+ const isMacUA = /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent);
88
+ cachedIsMacOS = isMacUA && !detectIsIOS();
89
+ return cachedIsMacOS;
90
+ }
91
+ function detectIsAndroid() {
92
+ if (typeof cachedIsAndroid === "boolean") return cachedIsAndroid;
93
+ const nodePlatform = getNodePlatform();
94
+ if (nodePlatform !== null) {
95
+ return cachedIsAndroid = nodePlatform === "android";
96
+ }
97
+ if (typeof navigator === "undefined") return cachedIsAndroid = false;
98
+ const platform = getUADataPlatform();
99
+ if (platform !== null) {
100
+ cachedIsAndroid = platform === "android";
101
+ return cachedIsAndroid;
102
+ }
103
+ cachedIsAndroid = /Android/.test(navigator.userAgent);
104
+ return cachedIsAndroid;
105
+ }
106
+ function detectIsWindows() {
107
+ if (typeof cachedIsWindows === "boolean") return cachedIsWindows;
108
+ const nodePlatform = getNodePlatform();
109
+ if (nodePlatform !== null) {
110
+ return cachedIsWindows = nodePlatform === "win32";
111
+ }
112
+ if (typeof navigator === "undefined") return cachedIsWindows = false;
113
+ const platform = getUADataPlatform();
114
+ if (platform !== null) {
115
+ cachedIsWindows = platform === "windows";
116
+ return cachedIsWindows;
117
+ }
118
+ cachedIsWindows = /Win32|Win64|Windows|WinCE/.test(navigator.userAgent);
119
+ return cachedIsWindows;
120
+ }
121
+ function detectIsChromeOS() {
122
+ if (typeof cachedIsChromeOS === "boolean") return cachedIsChromeOS;
123
+ if (typeof navigator === "undefined") return cachedIsChromeOS = false;
124
+ const platform = getUADataPlatform();
125
+ if (platform !== null) {
126
+ cachedIsChromeOS = platform === "chrome os" || platform === "chromeos";
127
+ return cachedIsChromeOS;
128
+ }
129
+ cachedIsChromeOS = /CrOS/.test(navigator.userAgent);
130
+ return cachedIsChromeOS;
131
+ }
132
+ function detectIsLinux() {
133
+ if (typeof cachedIsLinux === "boolean") return cachedIsLinux;
134
+ const nodePlatform = getNodePlatform();
135
+ if (nodePlatform !== null) {
136
+ return cachedIsLinux = nodePlatform === "linux";
137
+ }
138
+ if (typeof navigator === "undefined") return cachedIsLinux = false;
139
+ const platform = getUADataPlatform();
140
+ if (platform !== null) {
141
+ cachedIsLinux = platform === "linux";
142
+ return cachedIsLinux;
143
+ }
144
+ cachedIsLinux = /Linux/.test(navigator.userAgent) && !detectIsAndroid() && !detectIsChromeOS();
145
+ return cachedIsLinux;
146
+ }
147
+ async function detectIsWindows11() {
148
+ var _a, _b;
149
+ if (!detectIsWindows()) return false;
150
+ if (typeof navigator === "undefined" && typeof process !== "undefined") {
151
+ try {
152
+ const { release } = await import("os");
153
+ const buildNumber = parseInt((_a = release().split(".")[2]) != null ? _a : "0", 10);
154
+ return buildNumber >= 22e3;
155
+ } catch (e) {
156
+ return false;
157
+ }
158
+ }
159
+ try {
160
+ const nav = navigator;
161
+ if (!((_b = nav.userAgentData) == null ? void 0 : _b.getHighEntropyValues)) return false;
162
+ const { platformVersion } = await nav.userAgentData.getHighEntropyValues([
163
+ "platformVersion"
164
+ ]);
165
+ if (!platformVersion) return false;
166
+ const majorVersion = parseInt(platformVersion.split(".")[0], 10);
167
+ return majorVersion >= 13;
168
+ } catch (e) {
169
+ return false;
170
+ }
171
+ }
172
+ function getOS() {
173
+ if (detectIsIOS()) return "ios";
174
+ if (detectIsAndroid()) return "android";
175
+ if (detectIsChromeOS()) return "chromeos";
176
+ if (detectIsLinux()) return "linux";
177
+ if (detectIsMacOS()) return "macos";
178
+ if (detectIsWindows()) return "windows";
179
+ return "unknown";
180
+ }
181
+
182
+ // src/vue.ts
183
+ function useOS() {
184
+ const os = (0, import_vue.ref)(getOS());
185
+ return (0, import_vue.readonly)(os);
186
+ }
187
+ function useIsWindows11() {
188
+ const isWin11 = (0, import_vue.ref)(null);
189
+ (0, import_vue.onMounted)(() => {
190
+ detectIsWindows11().then((value) => {
191
+ isWin11.value = value;
192
+ });
193
+ });
194
+ return (0, import_vue.readonly)(isWin11);
195
+ }
196
+ // Annotate the CommonJS export names for ESM import in node:
197
+ 0 && (module.exports = {
198
+ useIsWindows11,
199
+ useOS
200
+ });
package/dist/vue.mjs ADDED
@@ -0,0 +1,164 @@
1
+ // src/vue.ts
2
+ import { ref, readonly, onMounted } from "vue";
3
+
4
+ // src/index.ts
5
+ var cachedIsIOS;
6
+ var cachedIsMacOS;
7
+ var cachedIsAndroid;
8
+ var cachedIsWindows;
9
+ var cachedIsLinux;
10
+ var cachedIsChromeOS;
11
+ function getUADataPlatform() {
12
+ if (typeof navigator === "undefined") return null;
13
+ const uaData = navigator.userAgentData;
14
+ if (uaData && typeof uaData.platform === "string") {
15
+ return uaData.platform.toLowerCase();
16
+ }
17
+ return null;
18
+ }
19
+ function getNodePlatform() {
20
+ if (typeof navigator !== "undefined") return null;
21
+ if (typeof process === "undefined" || typeof process.platform !== "string") return null;
22
+ return process.platform;
23
+ }
24
+ function detectIsIOS() {
25
+ if (typeof cachedIsIOS === "boolean") return cachedIsIOS;
26
+ if (typeof navigator === "undefined" || typeof window === "undefined") {
27
+ return cachedIsIOS = false;
28
+ }
29
+ const platform = getUADataPlatform();
30
+ if (platform !== null) {
31
+ cachedIsIOS = platform === "ios";
32
+ return cachedIsIOS;
33
+ }
34
+ const isClassicIOSUA = /iPhone|iPod/.test(navigator.userAgent);
35
+ const isIPadUA = /iPad/.test(navigator.userAgent);
36
+ const isIPadOS = /Macintosh/.test(navigator.userAgent) && typeof navigator.maxTouchPoints === "number" && navigator.maxTouchPoints > 1;
37
+ cachedIsIOS = isClassicIOSUA || isIPadUA || isIPadOS;
38
+ return cachedIsIOS;
39
+ }
40
+ function detectIsMacOS() {
41
+ if (typeof cachedIsMacOS === "boolean") return cachedIsMacOS;
42
+ const nodePlatform = getNodePlatform();
43
+ if (nodePlatform !== null) {
44
+ return cachedIsMacOS = nodePlatform === "darwin";
45
+ }
46
+ if (typeof navigator === "undefined") return cachedIsMacOS = false;
47
+ const platform = getUADataPlatform();
48
+ if (platform !== null) {
49
+ cachedIsMacOS = platform === "macos";
50
+ return cachedIsMacOS;
51
+ }
52
+ const isMacUA = /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent);
53
+ cachedIsMacOS = isMacUA && !detectIsIOS();
54
+ return cachedIsMacOS;
55
+ }
56
+ function detectIsAndroid() {
57
+ if (typeof cachedIsAndroid === "boolean") return cachedIsAndroid;
58
+ const nodePlatform = getNodePlatform();
59
+ if (nodePlatform !== null) {
60
+ return cachedIsAndroid = nodePlatform === "android";
61
+ }
62
+ if (typeof navigator === "undefined") return cachedIsAndroid = false;
63
+ const platform = getUADataPlatform();
64
+ if (platform !== null) {
65
+ cachedIsAndroid = platform === "android";
66
+ return cachedIsAndroid;
67
+ }
68
+ cachedIsAndroid = /Android/.test(navigator.userAgent);
69
+ return cachedIsAndroid;
70
+ }
71
+ function detectIsWindows() {
72
+ if (typeof cachedIsWindows === "boolean") return cachedIsWindows;
73
+ const nodePlatform = getNodePlatform();
74
+ if (nodePlatform !== null) {
75
+ return cachedIsWindows = nodePlatform === "win32";
76
+ }
77
+ if (typeof navigator === "undefined") return cachedIsWindows = false;
78
+ const platform = getUADataPlatform();
79
+ if (platform !== null) {
80
+ cachedIsWindows = platform === "windows";
81
+ return cachedIsWindows;
82
+ }
83
+ cachedIsWindows = /Win32|Win64|Windows|WinCE/.test(navigator.userAgent);
84
+ return cachedIsWindows;
85
+ }
86
+ function detectIsChromeOS() {
87
+ if (typeof cachedIsChromeOS === "boolean") return cachedIsChromeOS;
88
+ if (typeof navigator === "undefined") return cachedIsChromeOS = false;
89
+ const platform = getUADataPlatform();
90
+ if (platform !== null) {
91
+ cachedIsChromeOS = platform === "chrome os" || platform === "chromeos";
92
+ return cachedIsChromeOS;
93
+ }
94
+ cachedIsChromeOS = /CrOS/.test(navigator.userAgent);
95
+ return cachedIsChromeOS;
96
+ }
97
+ function detectIsLinux() {
98
+ if (typeof cachedIsLinux === "boolean") return cachedIsLinux;
99
+ const nodePlatform = getNodePlatform();
100
+ if (nodePlatform !== null) {
101
+ return cachedIsLinux = nodePlatform === "linux";
102
+ }
103
+ if (typeof navigator === "undefined") return cachedIsLinux = false;
104
+ const platform = getUADataPlatform();
105
+ if (platform !== null) {
106
+ cachedIsLinux = platform === "linux";
107
+ return cachedIsLinux;
108
+ }
109
+ cachedIsLinux = /Linux/.test(navigator.userAgent) && !detectIsAndroid() && !detectIsChromeOS();
110
+ return cachedIsLinux;
111
+ }
112
+ async function detectIsWindows11() {
113
+ var _a, _b;
114
+ if (!detectIsWindows()) return false;
115
+ if (typeof navigator === "undefined" && typeof process !== "undefined") {
116
+ try {
117
+ const { release } = await import("os");
118
+ const buildNumber = parseInt((_a = release().split(".")[2]) != null ? _a : "0", 10);
119
+ return buildNumber >= 22e3;
120
+ } catch (e) {
121
+ return false;
122
+ }
123
+ }
124
+ try {
125
+ const nav = navigator;
126
+ if (!((_b = nav.userAgentData) == null ? void 0 : _b.getHighEntropyValues)) return false;
127
+ const { platformVersion } = await nav.userAgentData.getHighEntropyValues([
128
+ "platformVersion"
129
+ ]);
130
+ if (!platformVersion) return false;
131
+ const majorVersion = parseInt(platformVersion.split(".")[0], 10);
132
+ return majorVersion >= 13;
133
+ } catch (e) {
134
+ return false;
135
+ }
136
+ }
137
+ function getOS() {
138
+ if (detectIsIOS()) return "ios";
139
+ if (detectIsAndroid()) return "android";
140
+ if (detectIsChromeOS()) return "chromeos";
141
+ if (detectIsLinux()) return "linux";
142
+ if (detectIsMacOS()) return "macos";
143
+ if (detectIsWindows()) return "windows";
144
+ return "unknown";
145
+ }
146
+
147
+ // src/vue.ts
148
+ function useOS() {
149
+ const os = ref(getOS());
150
+ return readonly(os);
151
+ }
152
+ function useIsWindows11() {
153
+ const isWin11 = ref(null);
154
+ onMounted(() => {
155
+ detectIsWindows11().then((value) => {
156
+ isWin11.value = value;
157
+ });
158
+ });
159
+ return readonly(isWin11);
160
+ }
161
+ export {
162
+ useIsWindows11,
163
+ useOS
164
+ };