@naturalcycles/js-lib 15.85.0 → 15.86.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.
@@ -0,0 +1,183 @@
1
+ /// <reference lib="dom" preserve="true" />
2
+ export type UADeviceType = 'console' | 'mobile' | 'tablet' | 'smarttv' | 'wearable' | 'embedded';
3
+ /**
4
+ * Popular OS names as produced by the parser, for convenient comparisons
5
+ * (`os.name === UAOSName.iOS`) without magic strings.
6
+ *
7
+ * Not exhaustive - the parser emits many more names; compare against a string for the rest.
8
+ */
9
+ export declare enum UAOSName {
10
+ iOS = "iOS",
11
+ Android = "Android",
12
+ MacOS = "Mac OS",
13
+ Windows = "Windows",
14
+ Linux = "Linux",
15
+ ChromiumOS = "Chromium OS",
16
+ WatchOS = "watchOS"
17
+ }
18
+ /**
19
+ * Popular browser names as produced by the parser, for convenient comparisons
20
+ * (`browser.name === UABrowserName.Safari`) without magic strings.
21
+ *
22
+ * Not exhaustive - the parser emits many more names; compare against a string for the rest.
23
+ */
24
+ export declare enum UABrowserName {
25
+ Chrome = "Chrome",
26
+ ChromeWebView = "Chrome WebView",
27
+ ChromeHeadless = "Chrome Headless",
28
+ Safari = "Safari",
29
+ MobileSafari = "Mobile Safari",
30
+ Firefox = "Firefox",
31
+ Edge = "Edge",
32
+ Opera = "Opera",
33
+ SamsungInternet = "Samsung Internet",
34
+ Facebook = "Facebook",
35
+ Instagram = "Instagram",
36
+ /**
37
+ * Bare WebKit UA without a Safari token, typically an iOS in-app webview (e.g. WKWebView).
38
+ */
39
+ WebKit = "WebKit"
40
+ }
41
+ export interface UABrowser {
42
+ /**
43
+ * E.g Chrome, Edge, Firefox, Safari, Mobile Safari, Opera, IE, UCBrowser, WeChat, ...
44
+ * Popular values are available as `UABrowserName`.
45
+ */
46
+ name: string | undefined;
47
+ version: string | undefined;
48
+ /**
49
+ * Major version, e.g. '20' for version '20.0.1090.0'.
50
+ */
51
+ major: string | undefined;
52
+ }
53
+ export interface UACpu {
54
+ /**
55
+ * E.g 68k, amd64, arm, arm64, armhf, avr, ia32, ia64, irix, irix64, mips, mips64,
56
+ * pa-risc, ppc, sparc, sparc64.
57
+ */
58
+ architecture: string | undefined;
59
+ }
60
+ export interface UADevice {
61
+ /**
62
+ * E.g Apple, Samsung, Huawei, Xiaomi, Google, Sony, LG, Microsoft, Amazon, ...
63
+ */
64
+ vendor: string | undefined;
65
+ model: string | undefined;
66
+ /**
67
+ * Undefined means "desktop-like" (no specific device type detected).
68
+ */
69
+ type: UADeviceType | undefined;
70
+ }
71
+ export interface UAEngine {
72
+ /**
73
+ * E.g Blink, Gecko, WebKit, EdgeHTML, Presto, Trident, ...
74
+ */
75
+ name: string | undefined;
76
+ version: string | undefined;
77
+ }
78
+ export interface UAOS {
79
+ /**
80
+ * E.g Windows, iOS, Mac OS, Android, Linux, Chromium OS, ...
81
+ * Popular values are available as `UAOSName`.
82
+ */
83
+ name: string | undefined;
84
+ version: string | undefined;
85
+ }
86
+ export interface UAResult {
87
+ ua: string;
88
+ browser: UABrowser;
89
+ engine: UAEngine;
90
+ os: UAOS;
91
+ device: UADevice;
92
+ cpu: UACpu;
93
+ }
94
+ export type UAMapperFn = (match: string) => string | undefined;
95
+ export type UAStrMap = Record<string, string | string[]>;
96
+ /**
97
+ * Describes how a regex capture group is assigned to a result property:
98
+ * - `prop` - assign the raw match
99
+ * - `[prop, value]` - assign a fixed value (ignore the match)
100
+ * - `[prop, fn]` - assign `fn(match)`
101
+ * - `[prop, regex, replacement]` - assign `match.replace(regex, replacement)`
102
+ * - `[prop, fn, map]` - assign `fn(match, map)` (string-map lookup)
103
+ * - `[prop, regex, replacement, fn]` - assign `fn(match.replace(regex, replacement))`
104
+ */
105
+ export type UAAction = string | readonly [string, string] | readonly [string, UAMapperFn] | readonly [string, RegExp, string] | readonly [string, (str: string, map: UAStrMap) => string | undefined, UAStrMap] | readonly [string, RegExp, string, UAMapperFn];
106
+ /**
107
+ * Alternating sequence of regex-list and action-list:
108
+ * `[RegExp[], UAAction[], RegExp[], UAAction[], ...]`.
109
+ * The regexes are tried in order; the first match wins and its capture groups
110
+ * are assigned via the following action-list.
111
+ */
112
+ export type UARegexMapEntry = RegExp[] | UAAction[];
113
+ /**
114
+ * Custom regexes to extend the built-in ones.
115
+ * Extension regexes are tried before the built-in regexes of the same category.
116
+ */
117
+ export interface UAParserExtensions {
118
+ browser?: UARegexMapEntry[];
119
+ cpu?: UARegexMapEntry[];
120
+ device?: UARegexMapEntry[];
121
+ engine?: UARegexMapEntry[];
122
+ os?: UARegexMapEntry[];
123
+ }
124
+ /**
125
+ * Parses the given User-Agent string into browser, engine, os, device and cpu information.
126
+ *
127
+ * When `ua` is not provided and running in a browser - `navigator.userAgent` is used
128
+ * (with client-hints-based refinements, e.g. Brave and iPadOS detection).
129
+ */
130
+ export declare function parseUserAgent(userAgent?: string, extensions?: UAParserExtensions): UAResult;
131
+ export declare function uaParser(userAgent?: string, extensions?: UAParserExtensions): UAParser;
132
+ /**
133
+ * User-Agent parser.
134
+ *
135
+ * Compared to `parseUserAgent()`, the class allows parsing only the needed parts
136
+ * (e.g `getBrowser()` alone is much cheaper than `getResult()`),
137
+ * and reusing the compiled extensions across multiple `setUA()` calls.
138
+ */
139
+ export declare class UAParser {
140
+ constructor(ua?: string, extensions?: UAParserExtensions);
141
+ private ua;
142
+ private readonly nav;
143
+ private readonly rgxMap;
144
+ private readonly isSelfNav;
145
+ private cachedBrowser?;
146
+ private cachedOs?;
147
+ private cachedDevice?;
148
+ getBrowser(): UABrowser;
149
+ getCPU(): UACpu;
150
+ getDevice(): UADevice;
151
+ getEngine(): UAEngine;
152
+ getOS(): UAOS;
153
+ getResult(): UAResult;
154
+ getUA(): string;
155
+ setUA(ua: string | undefined): this;
156
+ /**
157
+ * True if the OS is iOS.
158
+ * Note: desktop-mode iPads send a Mac-like UA and are not detected as iOS
159
+ * (except when parsing the browser's own UA, where client-hints refinements apply).
160
+ */
161
+ isIos(): boolean;
162
+ isAndroid(): boolean;
163
+ isMacOs(): boolean;
164
+ isWindows(): boolean;
165
+ /**
166
+ * True for 'Chrome', 'Chrome WebView' and 'Chrome Headless' (not for Chromium).
167
+ */
168
+ isChrome(): boolean;
169
+ /**
170
+ * True for 'Safari' and 'Mobile Safari' (not for bare-WebKit iOS in-app webviews).
171
+ */
172
+ isSafari(): boolean;
173
+ isFirefox(): boolean;
174
+ isEdge(): boolean;
175
+ /**
176
+ * True if the device type is 'mobile' (phones; tablets are 'tablet' - see isTablet).
177
+ */
178
+ isMobile(): boolean;
179
+ isTablet(): boolean;
180
+ private browser;
181
+ private os;
182
+ private device;
183
+ }