@flighthq/useragent 0.5.1-next.920.da8f530 → 0.6.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 +2 -2
- package/dist/contract.d.ts +4 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +3 -2
- package/dist/contract.js.map +1 -1
- package/dist/deviceFormFactor.d.ts +35 -0
- package/dist/deviceFormFactor.d.ts.map +1 -0
- package/dist/deviceFormFactor.js +31 -0
- package/dist/deviceFormFactor.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/jsPattern.d.ts +65 -0
- package/dist/jsPattern.d.ts.map +1 -0
- package/dist/jsPattern.js +247 -0
- package/dist/jsPattern.js.map +1 -0
- package/dist/rustTestSupport.d.ts +12 -0
- package/dist/rustTestSupport.d.ts.map +1 -0
- package/dist/rustTestSupport.js +24 -0
- package/dist/rustTestSupport.js.map +1 -0
- package/dist/userAgent.d.ts +53 -3
- package/dist/userAgent.d.ts.map +1 -1
- package/dist/userAgent.js +162 -146
- package/dist/userAgent.js.map +1 -1
- package/dist/userAgentNative.d.ts +12 -0
- package/dist/userAgentNative.d.ts.map +1 -0
- package/dist/userAgentNative.js +46 -0
- package/dist/userAgentNative.js.map +1 -0
- package/dist/userAgentParse.d.ts +17 -1
- package/dist/userAgentParse.d.ts.map +1 -1
- package/dist/userAgentParse.js +195 -93
- package/dist/userAgentParse.js.map +1 -1
- package/dist/userAgentTruthy.d.ts +3 -0
- package/dist/userAgentTruthy.d.ts.map +1 -0
- package/dist/userAgentTruthy.js +64 -0
- package/dist/userAgentTruthy.js.map +1 -0
- package/package.json +5 -5
- package/src/jsPattern.test.ts +136 -0
- package/src/userAgent.test.ts +217 -370
- package/src/userAgentNative.test.ts +55 -0
- package/src/userAgentParse.test.ts +111 -132
package/dist/userAgent.js
CHANGED
|
@@ -1,192 +1,208 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// Generated from crates/flight-useragent/src/user_agent.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
import { captureAfter, charsOf, contains, containsAny, isAsciiDigit, isDigitOrDot, matchesAt, positions, } from './jsPattern.js';
|
|
4
|
+
import { detectEndiannessNative, parseUserAgentRuntimeNative } from './userAgentNative.js';
|
|
5
|
+
import { parseUserAgentOsVersion } from './userAgentParse.js';
|
|
6
|
+
/**
|
|
7
|
+
* Probes host CPU byte order with a local two-byte write-then-read (the source's
|
|
8
|
+
* `Uint16Array`/`Uint8Array` view of one buffer): `Big` when the high byte comes first, `Little`
|
|
9
|
+
* when the low byte does. The source's `Unknown` arm is for runtimes without ArrayBuffer, which
|
|
10
|
+
* cannot occur here.
|
|
11
|
+
*/
|
|
5
12
|
export function detectEndianness() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// ArrayBuffer unavailable — treat as unknown.
|
|
13
|
+
return detectEndiannessNative();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `i[3-6]86`
|
|
17
|
+
*/
|
|
18
|
+
function iX86(t) {
|
|
19
|
+
for (const at of positions(t, 'i')) {
|
|
20
|
+
if (at + 3 < t.length && t[at + 1] >= 0x0033 && t[at + 1] <= 0x0036 && matchesAt(t, at + 2, '86')) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
17
23
|
}
|
|
18
|
-
return
|
|
24
|
+
return false;
|
|
19
25
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// cleaner arch detection than the UA string. 'Windows', 'Linux', 'macOS', 'Chrome OS' map to 'x64'
|
|
28
|
-
// conservatively; Apple Silicon (M-series) is indistinguishable from x64 via this hint alone.
|
|
26
|
+
/**
|
|
27
|
+
* Parses the canonical CPU architecture token from a UA string: "x64", "arm64", "x86", "arm",
|
|
28
|
+
* "riscv64", "mips64", "mips", or "" when undetectable. A truthy `uadPlatform` (the UA-CH
|
|
29
|
+
* `navigator.userAgentData.platform` hint) is consulted first, case-folded as JS `toLowerCase`
|
|
30
|
+
* does; `undefined` and `Some("")` both skip it, as an empty string is falsy in TS. arm64/aarch64 is
|
|
31
|
+
* tested before arm.
|
|
32
|
+
*/
|
|
29
33
|
export function parseUserAgentArch(ua, uadPlatform) {
|
|
30
|
-
if (uadPlatform) {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
p
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
if (uadPlatform !== undefined) {
|
|
35
|
+
const platform = uadPlatform;
|
|
36
|
+
if (platform.length !== 0) {
|
|
37
|
+
const p = charsOf(platform);
|
|
38
|
+
if (contains(p, 'arm')) {
|
|
39
|
+
return 'arm64';
|
|
40
|
+
}
|
|
41
|
+
if (contains(p, 'x86') ||
|
|
42
|
+
contains(p, 'windows') ||
|
|
43
|
+
contains(p, 'linux') ||
|
|
44
|
+
contains(p, 'mac') ||
|
|
45
|
+
contains(p, 'chrome')) {
|
|
46
|
+
return 'x64';
|
|
47
|
+
}
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
const t = charsOf(ua);
|
|
51
|
+
const arch = containsAny(t, ['arm64', 'aarch64'])
|
|
52
|
+
? 'arm64'
|
|
53
|
+
: contains(t, 'arm')
|
|
54
|
+
? 'arm'
|
|
55
|
+
: containsAny(t, ['x86_64', 'win64', 'wow64', 'x64'])
|
|
56
|
+
? 'x64'
|
|
57
|
+
: iX86(t) || contains(t, 'x86')
|
|
58
|
+
? 'x86'
|
|
59
|
+
: contains(t, 'riscv64')
|
|
60
|
+
? 'riscv64'
|
|
61
|
+
: contains(t, 'mips64')
|
|
62
|
+
? 'mips64'
|
|
63
|
+
: contains(t, 'mips')
|
|
64
|
+
? 'mips'
|
|
65
|
+
: '';
|
|
66
|
+
return arch;
|
|
57
67
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Parses the browser engine from a UA string. iOS/iPadOS decide first (every browser there runs on
|
|
70
|
+
* the system WebKit); then Firefox (gecko); legacy EdgeHTML (`Edge/<digit>`) is `Unknown`, not
|
|
71
|
+
* blink; then Chrome/Chromium/Edg/OPR/Samsung (blink); then Safari/WebKit; else `Unknown`.
|
|
72
|
+
*/
|
|
61
73
|
export function parseUserAgentEngine(ua) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// keeps this from playing whack-a-mole with product tokens — `EdgiOS` contains `edg` and was being
|
|
65
|
-
// reported as blink (with an empty version, since no `Edg/` token follows), and any future
|
|
66
|
-
// `<Product>iOS` token would have failed the same way.
|
|
67
|
-
if (/iphone|ipad|ipod/i.test(ua))
|
|
74
|
+
const t = charsOf(ua);
|
|
75
|
+
if (containsAny(t, ['iphone', 'ipad', 'ipod'])) {
|
|
68
76
|
return 'webkit';
|
|
69
|
-
|
|
77
|
+
}
|
|
78
|
+
if (contains(t, 'firefox')) {
|
|
70
79
|
return 'gecko';
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// than a fourth engine value because PlatformEngine has no EdgeHTML member and adding one is a public
|
|
74
|
-
// type change every exhaustive consumer would have to handle. 'unknown' is the documented answer for
|
|
75
|
-
// an engine this SDK does not model, and it is the honest one: saying blink would have a caller apply
|
|
76
|
-
// Chromium workarounds to a browser that never ran Chromium. Distinguished from modern Edge by the
|
|
77
|
-
// trailing `e` — `Edg/` and `EdgiOS/` do not match.
|
|
78
|
-
if (/edge\/\d/i.test(ua))
|
|
80
|
+
}
|
|
81
|
+
if (positions(t, 'edge/').some((at) => at + 5 < t.length && isAsciiDigit(t[at + 5]))) {
|
|
79
82
|
return 'unknown';
|
|
80
|
-
|
|
83
|
+
}
|
|
84
|
+
if (containsAny(t, ['chrome', 'chromium', 'edg', 'opr', 'samsung'])) {
|
|
81
85
|
return 'blink';
|
|
82
|
-
|
|
86
|
+
}
|
|
87
|
+
if (containsAny(t, ['safari', 'webkit'])) {
|
|
83
88
|
return 'webkit';
|
|
89
|
+
}
|
|
84
90
|
return 'unknown';
|
|
85
91
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Extracts the raw browser/engine version token for `engine` ("" when absent or `Unknown`): gecko
|
|
94
|
+
* `Firefox/`; blink `Edg/`, then `OPR/`, then `Chrome/`; webkit `Version/`, then `AppleWebKit/`.
|
|
95
|
+
* Never parsed for semantics.
|
|
96
|
+
*/
|
|
90
97
|
export function parseUserAgentEngineVersion(ua, engine) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
const t = charsOf(ua);
|
|
99
|
+
if (engine === 'gecko') {
|
|
100
|
+
const firefox = captureAfter(t, 'firefox/', isDigitOrDot);
|
|
101
|
+
if (firefox !== undefined) {
|
|
102
|
+
const value = firefox;
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
107
|
+
if (engine === 'blink') {
|
|
108
|
+
const edge = captureAfter(t, 'edg/', isDigitOrDot);
|
|
109
|
+
if (edge !== undefined) {
|
|
110
|
+
const value = edge;
|
|
111
|
+
return value;
|
|
96
112
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
return edg[1];
|
|
102
|
-
const opr = /opr\/([\d.]+)/i.exec(ua);
|
|
103
|
-
if (opr)
|
|
104
|
-
return opr[1];
|
|
105
|
-
const chrome = /chrome\/([\d.]+)/i.exec(ua);
|
|
106
|
-
return chrome ? chrome[1] : '';
|
|
113
|
+
const opera = captureAfter(t, 'opr/', isDigitOrDot);
|
|
114
|
+
if (opera !== undefined) {
|
|
115
|
+
const value = opera;
|
|
116
|
+
return value;
|
|
107
117
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
return ver[1];
|
|
113
|
-
const wk = /applewebkit\/([\d.]+)/i.exec(ua);
|
|
114
|
-
return wk ? wk[1] : '';
|
|
118
|
+
const chrome = captureAfter(t, 'chrome/', isDigitOrDot);
|
|
119
|
+
if (chrome !== undefined) {
|
|
120
|
+
const value = chrome;
|
|
121
|
+
return value;
|
|
115
122
|
}
|
|
116
|
-
|
|
117
|
-
return '';
|
|
123
|
+
return '';
|
|
118
124
|
}
|
|
125
|
+
if (engine === 'webkit') {
|
|
126
|
+
const version = captureAfter(t, 'version/', isDigitOrDot);
|
|
127
|
+
if (version !== undefined) {
|
|
128
|
+
const value = version;
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
const webkit = captureAfter(t, 'applewebkit/', isDigitOrDot);
|
|
132
|
+
if (webkit !== undefined) {
|
|
133
|
+
const value = webkit;
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return '';
|
|
119
138
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
139
|
+
/**
|
|
140
|
+
* The platform kind derived from a name: iOS and Android are `Mobile`; everything else is `Web`.
|
|
141
|
+
*/
|
|
123
142
|
export function parseUserAgentKind(name) {
|
|
124
|
-
if (name === 'ios' || name === 'android')
|
|
143
|
+
if (name === 'ios' || name === 'android') {
|
|
125
144
|
return 'mobile';
|
|
145
|
+
}
|
|
126
146
|
return 'web';
|
|
127
147
|
}
|
|
128
|
-
|
|
129
|
-
|
|
148
|
+
/**
|
|
149
|
+
* The platform name from a UA string, in source precedence (android, iOS devices, `win`, `mac`,
|
|
150
|
+
* linux); `Web` when no known OS is detected.
|
|
151
|
+
*/
|
|
130
152
|
export function parseUserAgentName(ua) {
|
|
131
|
-
|
|
153
|
+
const t = charsOf(ua);
|
|
154
|
+
if (contains(t, 'android')) {
|
|
132
155
|
return 'android';
|
|
133
|
-
|
|
156
|
+
}
|
|
157
|
+
if (containsAny(t, ['iphone', 'ipad', 'ipod'])) {
|
|
134
158
|
return 'ios';
|
|
135
|
-
|
|
159
|
+
}
|
|
160
|
+
if (contains(t, 'win')) {
|
|
136
161
|
return 'windows';
|
|
137
|
-
|
|
162
|
+
}
|
|
163
|
+
if (contains(t, 'mac')) {
|
|
138
164
|
return 'macos';
|
|
139
|
-
|
|
165
|
+
}
|
|
166
|
+
if (contains(t, 'linux')) {
|
|
140
167
|
return 'linux';
|
|
168
|
+
}
|
|
141
169
|
return 'web';
|
|
142
170
|
}
|
|
143
|
-
|
|
144
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Pointer width in bits from a canonical arch token: 64 for "x64"/"arm64", 32 for "x86"/"arm", -1
|
|
173
|
+
* otherwise (TS `32 | 64 | -1`).
|
|
174
|
+
*/
|
|
145
175
|
export function parseUserAgentPointerWidth(arch) {
|
|
146
|
-
if (arch === 'x64' || arch === 'arm64')
|
|
176
|
+
if (arch === 'x64' || arch === 'arm64') {
|
|
147
177
|
return 64;
|
|
148
|
-
|
|
178
|
+
}
|
|
179
|
+
if (arch === 'x86' || arch === 'arm') {
|
|
149
180
|
return 32;
|
|
181
|
+
}
|
|
150
182
|
return -1;
|
|
151
183
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
184
|
+
/**
|
|
185
|
+
* The host shell from browser-global probes on an optional window-like record (TS
|
|
186
|
+
* `win?: Readonly<Record<unknown>>`; `undefined` is omitted/undefined). `Unknown` for no window;
|
|
187
|
+
* `Electron` when `process.versions.electron` is truthy; `Tauri` when `__TAURI__` is truthy;
|
|
188
|
+
* `Capacitor` when `Capacitor` is truthy; else `Web`. Truthiness and property access follow JS (see
|
|
189
|
+
* `isTruthy`): a nested object is a `Record<Unknown>` stored in the `Unknown`.
|
|
190
|
+
*/
|
|
155
191
|
export function parseUserAgentRuntime(win) {
|
|
156
|
-
|
|
157
|
-
return 'unknown';
|
|
158
|
-
// Electron: window.process?.versions?.electron is set in the renderer process.
|
|
159
|
-
const proc = win.process;
|
|
160
|
-
if (proc?.versions && proc.versions.electron)
|
|
161
|
-
return 'electron';
|
|
162
|
-
// Tauri: window.__TAURI__ is injected by the Tauri runtime.
|
|
163
|
-
if (win.__TAURI__)
|
|
164
|
-
return 'tauri';
|
|
165
|
-
// Capacitor: window.Capacitor is set by the Capacitor bridge.
|
|
166
|
-
if (win.Capacitor)
|
|
167
|
-
return 'capacitor';
|
|
168
|
-
return 'web';
|
|
192
|
+
return parseUserAgentRuntimeNative(win);
|
|
169
193
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
//
|
|
176
|
-
// The extraction itself lives in parseUserAgentOsVersion; this function is the PlatformName-vocabulary
|
|
177
|
-
// view of it. It used to carry its own copy of the same four patterns, and the copies had drifted:
|
|
178
|
-
// these required exactly one space (`/android ([\d.]+)/`) where the originals accept any whitespace
|
|
179
|
-
// (`/android\s+([\d.]+)/`), so this function returned '' for UAs the other parsed correctly. One
|
|
180
|
-
// implementation, two vocabularies — the drift cannot recur.
|
|
181
|
-
//
|
|
182
|
-
// FROZEN UA VALUES: see parseUserAgentOsVersion. Windows 11 is indistinguishable from Windows 10
|
|
183
|
-
// here, and macOS reads 10.15.7 on every version since Big Sur.
|
|
194
|
+
/**
|
|
195
|
+
* The raw dotted OS version for `name`: "" for `Linux` (no kernel version in a browser UA), for
|
|
196
|
+
* the `Web` fallback, and when `name` is not the platform the UA describes; otherwise
|
|
197
|
+
* `parseUserAgentOsVersion`.
|
|
198
|
+
*/
|
|
184
199
|
export function parseUserAgentVersion(ua, name) {
|
|
185
|
-
|
|
186
|
-
if (name === 'linux' || name === 'web')
|
|
200
|
+
if (name === 'linux' || name === 'web') {
|
|
187
201
|
return '';
|
|
188
|
-
|
|
202
|
+
}
|
|
203
|
+
if (parseUserAgentName(ua) !== name) {
|
|
189
204
|
return '';
|
|
205
|
+
}
|
|
190
206
|
return parseUserAgentOsVersion(ua);
|
|
191
207
|
}
|
|
192
208
|
//# sourceMappingURL=userAgent.js.map
|
package/dist/userAgent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userAgent.js","sourceRoot":"","sources":["../src/userAgent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"userAgent.js","sourceRoot":"","sources":["../src/userAgent.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AAEnE,OAAO,EACL,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,SAAS,GACV,MAAM,gBAAgB,CAAC;AASxB,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAO9D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,sBAAsB,EAAE,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,SAAS,IAAI,CAAC,CAAqB;IACjC,KAAK,MAAM,EAAE,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QACnC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,MAAM,IAAI,SAAS,CAAC,CAAC,EAAE,E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KAAK,OAAO,EAAE,CAAC;QACvC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAuC;IAC3E,OAAO,2BAA2B,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAU,EAAE,IAAkB;IAClE,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACvC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,kBAAkB,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,uBAAuB,CAAC,EAAE,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type PlatformEndianness = 'big' | 'little' | 'unknown';
|
|
2
|
+
type PlatformEngine = 'gecko' | 'blink' | 'webkit' | 'unknown';
|
|
3
|
+
type PlatformKind = 'desktop' | 'mobile' | 'web' | 'unknown';
|
|
4
|
+
type PlatformName = 'web' | 'windows' | 'macos' | 'linux' | 'ios' | 'android' | 'unknown';
|
|
5
|
+
type PlatformRuntime = 'web' | 'electron' | 'tauri' | 'capacitor' | 'native' | 'unknown';
|
|
6
|
+
type Unknown = unknown;
|
|
7
|
+
type UserAgentRuntimeWindow = Readonly<Record<string, Unknown>> | undefined;
|
|
8
|
+
declare function detectEndiannessNative(): PlatformEndianness;
|
|
9
|
+
declare function parseUserAgentRuntimeNative(win: UserAgentRuntimeWindow): PlatformRuntime;
|
|
10
|
+
export type { PlatformEndianness, PlatformEngine, PlatformKind, PlatformName, PlatformRuntime, Unknown };
|
|
11
|
+
export { detectEndiannessNative, parseUserAgentRuntimeNative };
|
|
12
|
+
//# sourceMappingURL=userAgentNative.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userAgentNative.d.ts","sourceRoot":"","sources":["../src/userAgentNative.ts"],"names":[],"mappings":"AAKA,KAAK,kBAAkB,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEvD,KAAK,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/D,KAAK,YAAY,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;AAE7D,KAAK,YAAY,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,CAAC;AAE1F,KAAK,eAAe,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzF,KAAK,OAAO,GAAG,OAAO,CAAC;AAEvB,KAAK,sBAAsB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;AAE5E,iBAAS,sBAAsB,IAAI,kBAAkB,CASpD;AAkBD,iBAAS,2BAA2B,CAAC,GAAG,EAAE,sBAAsB,GAAG,eAAe,CAejF;AAED,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC;AAEzG,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Generated from crates/flight-useragent/src/user_agent_native.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
import { isTruthy } from './userAgentTruthy.js';
|
|
4
|
+
function detectEndiannessNative() {
|
|
5
|
+
const bytes = new Uint8Array(new Uint16Array([0x0102]).buffer);
|
|
6
|
+
if (bytes[0] === 0x01) {
|
|
7
|
+
return 'big';
|
|
8
|
+
}
|
|
9
|
+
if (bytes[0] === 0x02) {
|
|
10
|
+
return 'little';
|
|
11
|
+
}
|
|
12
|
+
return 'unknown';
|
|
13
|
+
}
|
|
14
|
+
function getProperty(value, key) {
|
|
15
|
+
const __try0 = value;
|
|
16
|
+
if (__try0 === undefined) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const value_1 = __try0;
|
|
20
|
+
if (value_1 === undefined) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const record = value_1;
|
|
24
|
+
if (record === undefined) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return record[key];
|
|
28
|
+
}
|
|
29
|
+
function parseUserAgentRuntimeNative(win) {
|
|
30
|
+
if (win === undefined) {
|
|
31
|
+
return 'unknown';
|
|
32
|
+
}
|
|
33
|
+
const versions = getProperty(win['process'], 'versions');
|
|
34
|
+
if (isTruthy(versions) && isTruthy(getProperty(versions, 'electron'))) {
|
|
35
|
+
return 'electron';
|
|
36
|
+
}
|
|
37
|
+
if (isTruthy(win['__TAURI__'])) {
|
|
38
|
+
return 'tauri';
|
|
39
|
+
}
|
|
40
|
+
if (isTruthy(win['Capacitor'])) {
|
|
41
|
+
return 'capacitor';
|
|
42
|
+
}
|
|
43
|
+
return 'web';
|
|
44
|
+
}
|
|
45
|
+
export { detectEndiannessNative, parseUserAgentRuntimeNative };
|
|
46
|
+
//# sourceMappingURL=userAgentNative.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userAgentNative.js","sourceRoot":"","sources":["../src/userAgentNative.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,mEAAmE;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAgBhD,SAAS,sBAAsB;IAC7B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,W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E,CAAC;QAC/B,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAID,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,CAAC"}
|
package/dist/userAgentParse.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
import type { DeviceFormFactor } from '
|
|
1
|
+
import type { DeviceFormFactor } from './deviceFormFactor.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a device form factor from a UA string and a touch-point hint (`maxTouchPoints`:
|
|
4
|
+
* `navigator.maxTouchPoints`, or -1 when unavailable). Never returns ""; falls back to
|
|
5
|
+
* `DEVICE_FORM_FACTOR_UNKNOWN`. Branch order is the source's: car, TV, watch, tablet, phone, a
|
|
6
|
+
* touch-capable Macintosh UA (desktop-mode iPad), desktop tokens, then the zero-touch desktop hint.
|
|
7
|
+
*/
|
|
2
8
|
export declare function parseUserAgentFormFactor(ua: string, maxTouchPoints: number): DeviceFormFactor;
|
|
9
|
+
/**
|
|
10
|
+
* Parses an OS name from a UA string, or "" when unknown. Values: "Android", "iPadOS", "iOS",
|
|
11
|
+
* "ChromeOS", "Windows", "macOS", "FreeBSD", "OpenBSD", "NetBSD", "Linux".
|
|
12
|
+
*/
|
|
3
13
|
export declare function parseUserAgentOsName(ua: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Parses the raw dotted OS version from a UA string, or "" when not found: Android, then
|
|
16
|
+
* iOS/iPadOS (underscores to dots), Windows NT, macOS (underscores to dots), ChromeOS. The single
|
|
17
|
+
* OS-version extractor in this crate. Values are ceilings, not readings: Windows 11 reads "10.0"
|
|
18
|
+
* and macOS since Big Sur reads "10.15.7".
|
|
19
|
+
*/
|
|
4
20
|
export declare function parseUserAgentOsVersion(ua: string): string;
|
|
5
21
|
//# sourceMappingURL=userAgentParse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userAgentParse.d.ts","sourceRoot":"","sources":["../src/userAgentParse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"userAgentParse.d.ts","sourceRoot":"","sources":["../src/userAgentParse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAoH9D;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,gBAAgB,CAyC7F;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAwBvD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CA4B1D"}
|