@heyhru/web-util-ua 0.1.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/index.d.ts +115 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +216 -0
- package/dist/index.mjs +177 -0
- package/package.json +32 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 浏览器类型枚举
|
|
3
|
+
*/
|
|
4
|
+
export declare enum BrowserType {
|
|
5
|
+
Chrome = "Chrome",
|
|
6
|
+
OurTool = "OurTool",
|
|
7
|
+
Other = "Other"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 操作系统类型
|
|
11
|
+
*/
|
|
12
|
+
export type OSType = "Windows" | "macOS" | "Linux" | "Android" | "iOS" | "Unknown";
|
|
13
|
+
/**
|
|
14
|
+
* 存储适配器接口(用于 getMockDeviceId)
|
|
15
|
+
*/
|
|
16
|
+
export interface StorageAdapter {
|
|
17
|
+
get(key: string): Promise<string | null>;
|
|
18
|
+
set(key: string, value: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 获取模拟设备 ID
|
|
22
|
+
* @param storageAdapter 可选的存储适配器,默认使用 localStorage
|
|
23
|
+
* @param storageKey 存储键名,默认为 "mock_device_id"
|
|
24
|
+
*/
|
|
25
|
+
export declare function getMockDeviceId(storageAdapter?: StorageAdapter, storageKey?: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* 获取浏览器语言设置(仅返回语言代码,如 "en"、"zh")
|
|
28
|
+
*/
|
|
29
|
+
export declare function getLocale(): string;
|
|
30
|
+
/**
|
|
31
|
+
* 获取完整的语言设置(�� "en-US"、"zh-CN")
|
|
32
|
+
*/
|
|
33
|
+
export declare function getFullLocale(): string;
|
|
34
|
+
/**
|
|
35
|
+
* 获取操作系统类型
|
|
36
|
+
*/
|
|
37
|
+
export declare function getOs(): OSType;
|
|
38
|
+
/**
|
|
39
|
+
* 获取浏览器类型
|
|
40
|
+
* @param customAppBridge 自定义的 App Bridge 对象名称,默认检查 window.pwaBridge
|
|
41
|
+
*/
|
|
42
|
+
export declare function getBrowserType(customAppBridge?: string): BrowserType;
|
|
43
|
+
/**
|
|
44
|
+
* 是否在 App 中(检测是否有 App Bridge)
|
|
45
|
+
* @param customAppBridge 自定义的 App Bridge 对象名称,默认检查 window.pwaBridge
|
|
46
|
+
*/
|
|
47
|
+
export declare function isApp(customAppBridge?: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* 是否为 Chrome 浏览器
|
|
50
|
+
*/
|
|
51
|
+
export declare function isChrome(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 是否为 PC 设备
|
|
54
|
+
*/
|
|
55
|
+
export declare function isPc(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* 是否为移动设备
|
|
58
|
+
*/
|
|
59
|
+
export declare function isMobile(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* 是否为 iOS 设备
|
|
62
|
+
*/
|
|
63
|
+
export declare function isIOS(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* 是否为 Android 设备
|
|
66
|
+
*/
|
|
67
|
+
export declare function isAndroid(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* 是否为 Safari 浏览器
|
|
70
|
+
*/
|
|
71
|
+
export declare function isSafari(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* 是否为 Firefox 浏览器
|
|
74
|
+
*/
|
|
75
|
+
export declare function isFirefox(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* 获取浏览器信息摘要
|
|
78
|
+
*/
|
|
79
|
+
export declare function getBrowserInfo(): {
|
|
80
|
+
os: OSType;
|
|
81
|
+
locale: string;
|
|
82
|
+
fullLocale: string;
|
|
83
|
+
browserType: BrowserType;
|
|
84
|
+
isMobile: boolean;
|
|
85
|
+
isPc: boolean;
|
|
86
|
+
isApp: boolean;
|
|
87
|
+
isChrome: boolean;
|
|
88
|
+
isSafari: boolean;
|
|
89
|
+
isFirefox: boolean;
|
|
90
|
+
isIOS: boolean;
|
|
91
|
+
isAndroid: boolean;
|
|
92
|
+
userAgent: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* 默认导出(兼容原 DeviceUtil 的使用方式)
|
|
96
|
+
*/
|
|
97
|
+
declare const _default: {
|
|
98
|
+
getMockDeviceId: typeof getMockDeviceId;
|
|
99
|
+
getLocale: typeof getLocale;
|
|
100
|
+
getFullLocale: typeof getFullLocale;
|
|
101
|
+
getOs: typeof getOs;
|
|
102
|
+
getBrowserType: typeof getBrowserType;
|
|
103
|
+
isApp: typeof isApp;
|
|
104
|
+
isChrome: typeof isChrome;
|
|
105
|
+
isSafari: typeof isSafari;
|
|
106
|
+
isFirefox: typeof isFirefox;
|
|
107
|
+
isPc: typeof isPc;
|
|
108
|
+
isMobile: typeof isMobile;
|
|
109
|
+
isIOS: typeof isIOS;
|
|
110
|
+
isAndroid: typeof isAndroid;
|
|
111
|
+
getBrowserInfo: typeof getBrowserInfo;
|
|
112
|
+
BrowserType: typeof BrowserType;
|
|
113
|
+
};
|
|
114
|
+
export default _default;
|
|
115
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,WAAW;IACrB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC;AAEnF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAsBD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,cAAc,GAAE,cAAsC,EACtD,UAAU,SAAmB,GAC5B,OAAO,CAAC,MAAM,CAAC,CASjB;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAQlC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAOtC;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,MAAM,CAkC9B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,WAAW,CAcpE;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAQvD;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAOlC;AAED;;GAEG;AACH,wBAAgB,IAAI,IAAI,OAAO,CAE9B;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAGlC;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAOlC;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAMnC;AAED;;GAEG;AACH,wBAAgB,cAAc;;;;;;;;;;;;;;EAgB7B;AAED;;GAEG;;;;;;;;;;;;;;;;;;AACH,wBAgBE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BrowserType: () => BrowserType,
|
|
24
|
+
default: () => index_default,
|
|
25
|
+
getBrowserInfo: () => getBrowserInfo,
|
|
26
|
+
getBrowserType: () => getBrowserType,
|
|
27
|
+
getFullLocale: () => getFullLocale,
|
|
28
|
+
getLocale: () => getLocale,
|
|
29
|
+
getMockDeviceId: () => getMockDeviceId,
|
|
30
|
+
getOs: () => getOs,
|
|
31
|
+
isAndroid: () => isAndroid,
|
|
32
|
+
isApp: () => isApp,
|
|
33
|
+
isChrome: () => isChrome,
|
|
34
|
+
isFirefox: () => isFirefox,
|
|
35
|
+
isIOS: () => isIOS,
|
|
36
|
+
isMobile: () => isMobile,
|
|
37
|
+
isPc: () => isPc,
|
|
38
|
+
isSafari: () => isSafari
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
var BrowserType = /* @__PURE__ */ ((BrowserType2) => {
|
|
42
|
+
BrowserType2["Chrome"] = "Chrome";
|
|
43
|
+
BrowserType2["OurTool"] = "OurTool";
|
|
44
|
+
BrowserType2["Other"] = "Other";
|
|
45
|
+
return BrowserType2;
|
|
46
|
+
})(BrowserType || {});
|
|
47
|
+
var LocalStorageAdapter = class {
|
|
48
|
+
async get(key) {
|
|
49
|
+
if (typeof window === "undefined" || !window.localStorage) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return window.localStorage.getItem(key);
|
|
53
|
+
}
|
|
54
|
+
async set(key, value) {
|
|
55
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
56
|
+
window.localStorage.setItem(key, value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var defaultStorageAdapter = new LocalStorageAdapter();
|
|
61
|
+
async function getMockDeviceId(storageAdapter = defaultStorageAdapter, storageKey = "mock_device_id") {
|
|
62
|
+
let mockId = await storageAdapter.get(storageKey);
|
|
63
|
+
if (mockId) {
|
|
64
|
+
return mockId;
|
|
65
|
+
}
|
|
66
|
+
mockId = `mock-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
67
|
+
await storageAdapter.set(storageKey, mockId);
|
|
68
|
+
return mockId;
|
|
69
|
+
}
|
|
70
|
+
function getLocale() {
|
|
71
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
72
|
+
return "en";
|
|
73
|
+
}
|
|
74
|
+
const locale = window.navigator.language || window.navigator.userLanguage;
|
|
75
|
+
return locale.split("-")[0];
|
|
76
|
+
}
|
|
77
|
+
function getFullLocale() {
|
|
78
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
79
|
+
return "en-US";
|
|
80
|
+
}
|
|
81
|
+
return window.navigator.language || window.navigator.userLanguage || "en-US";
|
|
82
|
+
}
|
|
83
|
+
function getOs() {
|
|
84
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
85
|
+
return "Unknown";
|
|
86
|
+
}
|
|
87
|
+
const userAgent = window.navigator.userAgent;
|
|
88
|
+
const platform = window.navigator.platform || window.navigator.userAgentData?.platform;
|
|
89
|
+
let os = "Unknown";
|
|
90
|
+
if (platform) {
|
|
91
|
+
if (/Windows/.test(platform)) {
|
|
92
|
+
os = "Windows";
|
|
93
|
+
} else if (/Mac/.test(platform)) {
|
|
94
|
+
os = "macOS";
|
|
95
|
+
} else if (/Linux arm/.test(platform) && /Android/.test(userAgent)) {
|
|
96
|
+
os = "Android";
|
|
97
|
+
} else if (/Linux/.test(platform)) {
|
|
98
|
+
os = "Linux";
|
|
99
|
+
} else if (/Android/.test(platform)) {
|
|
100
|
+
os = "Android";
|
|
101
|
+
} else if (/iPhone|iPad|iPod/.test(userAgent)) {
|
|
102
|
+
os = "iOS";
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
if (/Android/.test(userAgent)) {
|
|
106
|
+
os = "Android";
|
|
107
|
+
} else if (/iPhone|iPad|iPod/.test(userAgent)) {
|
|
108
|
+
os = "iOS";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return os;
|
|
112
|
+
}
|
|
113
|
+
function getBrowserType(customAppBridge) {
|
|
114
|
+
if (typeof window === "undefined") {
|
|
115
|
+
return "Other" /* Other */;
|
|
116
|
+
}
|
|
117
|
+
const bridgeName = customAppBridge || "pwaBridge";
|
|
118
|
+
if (window[bridgeName]) {
|
|
119
|
+
return "OurTool" /* OurTool */;
|
|
120
|
+
} else if (isChrome()) {
|
|
121
|
+
return "Chrome" /* Chrome */;
|
|
122
|
+
} else {
|
|
123
|
+
return "Other" /* Other */;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function isApp(customAppBridge) {
|
|
127
|
+
if (typeof window === "undefined") {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const bridgeName = customAppBridge || "pwaBridge";
|
|
131
|
+
return window[bridgeName] !== void 0 && window[bridgeName] !== null;
|
|
132
|
+
}
|
|
133
|
+
function isChrome() {
|
|
134
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return window.chrome && /Chrome/.test(window.navigator.userAgent);
|
|
138
|
+
}
|
|
139
|
+
function isPc() {
|
|
140
|
+
return !isMobile();
|
|
141
|
+
}
|
|
142
|
+
function isMobile() {
|
|
143
|
+
const os = getOs();
|
|
144
|
+
return os === "Android" || os === "iOS";
|
|
145
|
+
}
|
|
146
|
+
function isIOS() {
|
|
147
|
+
return getOs() === "iOS";
|
|
148
|
+
}
|
|
149
|
+
function isAndroid() {
|
|
150
|
+
return getOs() === "Android";
|
|
151
|
+
}
|
|
152
|
+
function isSafari() {
|
|
153
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
const userAgent = window.navigator.userAgent;
|
|
157
|
+
return /Safari/.test(userAgent) && !/Chrome/.test(userAgent);
|
|
158
|
+
}
|
|
159
|
+
function isFirefox() {
|
|
160
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return /Firefox/.test(window.navigator.userAgent);
|
|
164
|
+
}
|
|
165
|
+
function getBrowserInfo() {
|
|
166
|
+
return {
|
|
167
|
+
os: getOs(),
|
|
168
|
+
locale: getLocale(),
|
|
169
|
+
fullLocale: getFullLocale(),
|
|
170
|
+
browserType: getBrowserType(),
|
|
171
|
+
isMobile: isMobile(),
|
|
172
|
+
isPc: isPc(),
|
|
173
|
+
isApp: isApp(),
|
|
174
|
+
isChrome: isChrome(),
|
|
175
|
+
isSafari: isSafari(),
|
|
176
|
+
isFirefox: isFirefox(),
|
|
177
|
+
isIOS: isIOS(),
|
|
178
|
+
isAndroid: isAndroid(),
|
|
179
|
+
userAgent: typeof window !== "undefined" ? window.navigator?.userAgent : ""
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
var index_default = {
|
|
183
|
+
getMockDeviceId,
|
|
184
|
+
getLocale,
|
|
185
|
+
getFullLocale,
|
|
186
|
+
getOs,
|
|
187
|
+
getBrowserType,
|
|
188
|
+
isApp,
|
|
189
|
+
isChrome,
|
|
190
|
+
isSafari,
|
|
191
|
+
isFirefox,
|
|
192
|
+
isPc,
|
|
193
|
+
isMobile,
|
|
194
|
+
isIOS,
|
|
195
|
+
isAndroid,
|
|
196
|
+
getBrowserInfo,
|
|
197
|
+
BrowserType
|
|
198
|
+
};
|
|
199
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
200
|
+
0 && (module.exports = {
|
|
201
|
+
BrowserType,
|
|
202
|
+
getBrowserInfo,
|
|
203
|
+
getBrowserType,
|
|
204
|
+
getFullLocale,
|
|
205
|
+
getLocale,
|
|
206
|
+
getMockDeviceId,
|
|
207
|
+
getOs,
|
|
208
|
+
isAndroid,
|
|
209
|
+
isApp,
|
|
210
|
+
isChrome,
|
|
211
|
+
isFirefox,
|
|
212
|
+
isIOS,
|
|
213
|
+
isMobile,
|
|
214
|
+
isPc,
|
|
215
|
+
isSafari
|
|
216
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var BrowserType = /* @__PURE__ */ ((BrowserType2) => {
|
|
3
|
+
BrowserType2["Chrome"] = "Chrome";
|
|
4
|
+
BrowserType2["OurTool"] = "OurTool";
|
|
5
|
+
BrowserType2["Other"] = "Other";
|
|
6
|
+
return BrowserType2;
|
|
7
|
+
})(BrowserType || {});
|
|
8
|
+
var LocalStorageAdapter = class {
|
|
9
|
+
async get(key) {
|
|
10
|
+
if (typeof window === "undefined" || !window.localStorage) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return window.localStorage.getItem(key);
|
|
14
|
+
}
|
|
15
|
+
async set(key, value) {
|
|
16
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
17
|
+
window.localStorage.setItem(key, value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var defaultStorageAdapter = new LocalStorageAdapter();
|
|
22
|
+
async function getMockDeviceId(storageAdapter = defaultStorageAdapter, storageKey = "mock_device_id") {
|
|
23
|
+
let mockId = await storageAdapter.get(storageKey);
|
|
24
|
+
if (mockId) {
|
|
25
|
+
return mockId;
|
|
26
|
+
}
|
|
27
|
+
mockId = `mock-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
28
|
+
await storageAdapter.set(storageKey, mockId);
|
|
29
|
+
return mockId;
|
|
30
|
+
}
|
|
31
|
+
function getLocale() {
|
|
32
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
33
|
+
return "en";
|
|
34
|
+
}
|
|
35
|
+
const locale = window.navigator.language || window.navigator.userLanguage;
|
|
36
|
+
return locale.split("-")[0];
|
|
37
|
+
}
|
|
38
|
+
function getFullLocale() {
|
|
39
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
40
|
+
return "en-US";
|
|
41
|
+
}
|
|
42
|
+
return window.navigator.language || window.navigator.userLanguage || "en-US";
|
|
43
|
+
}
|
|
44
|
+
function getOs() {
|
|
45
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
46
|
+
return "Unknown";
|
|
47
|
+
}
|
|
48
|
+
const userAgent = window.navigator.userAgent;
|
|
49
|
+
const platform = window.navigator.platform || window.navigator.userAgentData?.platform;
|
|
50
|
+
let os = "Unknown";
|
|
51
|
+
if (platform) {
|
|
52
|
+
if (/Windows/.test(platform)) {
|
|
53
|
+
os = "Windows";
|
|
54
|
+
} else if (/Mac/.test(platform)) {
|
|
55
|
+
os = "macOS";
|
|
56
|
+
} else if (/Linux arm/.test(platform) && /Android/.test(userAgent)) {
|
|
57
|
+
os = "Android";
|
|
58
|
+
} else if (/Linux/.test(platform)) {
|
|
59
|
+
os = "Linux";
|
|
60
|
+
} else if (/Android/.test(platform)) {
|
|
61
|
+
os = "Android";
|
|
62
|
+
} else if (/iPhone|iPad|iPod/.test(userAgent)) {
|
|
63
|
+
os = "iOS";
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
if (/Android/.test(userAgent)) {
|
|
67
|
+
os = "Android";
|
|
68
|
+
} else if (/iPhone|iPad|iPod/.test(userAgent)) {
|
|
69
|
+
os = "iOS";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return os;
|
|
73
|
+
}
|
|
74
|
+
function getBrowserType(customAppBridge) {
|
|
75
|
+
if (typeof window === "undefined") {
|
|
76
|
+
return "Other" /* Other */;
|
|
77
|
+
}
|
|
78
|
+
const bridgeName = customAppBridge || "pwaBridge";
|
|
79
|
+
if (window[bridgeName]) {
|
|
80
|
+
return "OurTool" /* OurTool */;
|
|
81
|
+
} else if (isChrome()) {
|
|
82
|
+
return "Chrome" /* Chrome */;
|
|
83
|
+
} else {
|
|
84
|
+
return "Other" /* Other */;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function isApp(customAppBridge) {
|
|
88
|
+
if (typeof window === "undefined") {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const bridgeName = customAppBridge || "pwaBridge";
|
|
92
|
+
return window[bridgeName] !== void 0 && window[bridgeName] !== null;
|
|
93
|
+
}
|
|
94
|
+
function isChrome() {
|
|
95
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return window.chrome && /Chrome/.test(window.navigator.userAgent);
|
|
99
|
+
}
|
|
100
|
+
function isPc() {
|
|
101
|
+
return !isMobile();
|
|
102
|
+
}
|
|
103
|
+
function isMobile() {
|
|
104
|
+
const os = getOs();
|
|
105
|
+
return os === "Android" || os === "iOS";
|
|
106
|
+
}
|
|
107
|
+
function isIOS() {
|
|
108
|
+
return getOs() === "iOS";
|
|
109
|
+
}
|
|
110
|
+
function isAndroid() {
|
|
111
|
+
return getOs() === "Android";
|
|
112
|
+
}
|
|
113
|
+
function isSafari() {
|
|
114
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const userAgent = window.navigator.userAgent;
|
|
118
|
+
return /Safari/.test(userAgent) && !/Chrome/.test(userAgent);
|
|
119
|
+
}
|
|
120
|
+
function isFirefox() {
|
|
121
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return /Firefox/.test(window.navigator.userAgent);
|
|
125
|
+
}
|
|
126
|
+
function getBrowserInfo() {
|
|
127
|
+
return {
|
|
128
|
+
os: getOs(),
|
|
129
|
+
locale: getLocale(),
|
|
130
|
+
fullLocale: getFullLocale(),
|
|
131
|
+
browserType: getBrowserType(),
|
|
132
|
+
isMobile: isMobile(),
|
|
133
|
+
isPc: isPc(),
|
|
134
|
+
isApp: isApp(),
|
|
135
|
+
isChrome: isChrome(),
|
|
136
|
+
isSafari: isSafari(),
|
|
137
|
+
isFirefox: isFirefox(),
|
|
138
|
+
isIOS: isIOS(),
|
|
139
|
+
isAndroid: isAndroid(),
|
|
140
|
+
userAgent: typeof window !== "undefined" ? window.navigator?.userAgent : ""
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
var index_default = {
|
|
144
|
+
getMockDeviceId,
|
|
145
|
+
getLocale,
|
|
146
|
+
getFullLocale,
|
|
147
|
+
getOs,
|
|
148
|
+
getBrowserType,
|
|
149
|
+
isApp,
|
|
150
|
+
isChrome,
|
|
151
|
+
isSafari,
|
|
152
|
+
isFirefox,
|
|
153
|
+
isPc,
|
|
154
|
+
isMobile,
|
|
155
|
+
isIOS,
|
|
156
|
+
isAndroid,
|
|
157
|
+
getBrowserInfo,
|
|
158
|
+
BrowserType
|
|
159
|
+
};
|
|
160
|
+
export {
|
|
161
|
+
BrowserType,
|
|
162
|
+
index_default as default,
|
|
163
|
+
getBrowserInfo,
|
|
164
|
+
getBrowserType,
|
|
165
|
+
getFullLocale,
|
|
166
|
+
getLocale,
|
|
167
|
+
getMockDeviceId,
|
|
168
|
+
getOs,
|
|
169
|
+
isAndroid,
|
|
170
|
+
isApp,
|
|
171
|
+
isChrome,
|
|
172
|
+
isFirefox,
|
|
173
|
+
isIOS,
|
|
174
|
+
isMobile,
|
|
175
|
+
isPc,
|
|
176
|
+
isSafari
|
|
177
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@heyhru/web-util-ua",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.1.1",
|
|
7
|
+
"description": "User agent detection: device, browser, OS detection for web",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup && tsc --emitDeclarationOnly",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"lint1": "eslint src",
|
|
25
|
+
"clean": "rm -rf dist"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsup": "^8.5.1",
|
|
29
|
+
"typescript": "^6.0.2"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "bea932bfa6fd932a7a27a305d74b4b01c2e4ebe3"
|
|
32
|
+
}
|