@naturalcycles/js-lib 15.85.0 → 15.86.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/dist/ua/ua.d.ts +113 -0
- package/dist/ua/ua.js +1297 -0
- package/package.json +3 -2
- package/src/ua/ua.ts +1473 -0
package/dist/ua/ua.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/// <reference lib="dom" preserve="true" />
|
|
2
|
+
export type UADeviceType = 'console' | 'mobile' | 'tablet' | 'smarttv' | 'wearable' | 'embedded';
|
|
3
|
+
export interface UABrowser {
|
|
4
|
+
/**
|
|
5
|
+
* E.g Chrome, Edge, Firefox, Safari, Mobile Safari, Opera, IE, UCBrowser, WeChat, ...
|
|
6
|
+
*/
|
|
7
|
+
name: string | undefined;
|
|
8
|
+
version: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Major version, e.g. '20' for version '20.0.1090.0'.
|
|
11
|
+
*/
|
|
12
|
+
major: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface UACpu {
|
|
15
|
+
/**
|
|
16
|
+
* E.g 68k, amd64, arm, arm64, armhf, avr, ia32, ia64, irix, irix64, mips, mips64,
|
|
17
|
+
* pa-risc, ppc, sparc, sparc64.
|
|
18
|
+
*/
|
|
19
|
+
architecture: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
export interface UADevice {
|
|
22
|
+
/**
|
|
23
|
+
* E.g Apple, Samsung, Huawei, Xiaomi, Google, Sony, LG, Microsoft, Amazon, ...
|
|
24
|
+
*/
|
|
25
|
+
vendor: string | undefined;
|
|
26
|
+
model: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Undefined means "desktop-like" (no specific device type detected).
|
|
29
|
+
*/
|
|
30
|
+
type: UADeviceType | undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface UAEngine {
|
|
33
|
+
/**
|
|
34
|
+
* E.g Blink, Gecko, WebKit, EdgeHTML, Presto, Trident, ...
|
|
35
|
+
*/
|
|
36
|
+
name: string | undefined;
|
|
37
|
+
version: string | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface UAOS {
|
|
40
|
+
/**
|
|
41
|
+
* E.g Windows, iOS, Mac OS, Android, Linux, Chromium OS, ...
|
|
42
|
+
*/
|
|
43
|
+
name: string | undefined;
|
|
44
|
+
version: string | undefined;
|
|
45
|
+
}
|
|
46
|
+
export interface UAResult {
|
|
47
|
+
ua: string;
|
|
48
|
+
browser: UABrowser;
|
|
49
|
+
engine: UAEngine;
|
|
50
|
+
os: UAOS;
|
|
51
|
+
device: UADevice;
|
|
52
|
+
cpu: UACpu;
|
|
53
|
+
}
|
|
54
|
+
export type UAMapperFn = (match: string) => string | undefined;
|
|
55
|
+
export type UAStrMap = Record<string, string | string[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Describes how a regex capture group is assigned to a result property:
|
|
58
|
+
* - `prop` - assign the raw match
|
|
59
|
+
* - `[prop, value]` - assign a fixed value (ignore the match)
|
|
60
|
+
* - `[prop, fn]` - assign `fn(match)`
|
|
61
|
+
* - `[prop, regex, replacement]` - assign `match.replace(regex, replacement)`
|
|
62
|
+
* - `[prop, fn, map]` - assign `fn(match, map)` (string-map lookup)
|
|
63
|
+
* - `[prop, regex, replacement, fn]` - assign `fn(match.replace(regex, replacement))`
|
|
64
|
+
*/
|
|
65
|
+
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];
|
|
66
|
+
/**
|
|
67
|
+
* Alternating sequence of regex-list and action-list:
|
|
68
|
+
* `[RegExp[], UAAction[], RegExp[], UAAction[], ...]`.
|
|
69
|
+
* The regexes are tried in order; the first match wins and its capture groups
|
|
70
|
+
* are assigned via the following action-list.
|
|
71
|
+
*/
|
|
72
|
+
export type UARegexMapEntry = RegExp[] | UAAction[];
|
|
73
|
+
/**
|
|
74
|
+
* Custom regexes to extend the built-in ones.
|
|
75
|
+
* Extension regexes are tried before the built-in regexes of the same category.
|
|
76
|
+
*/
|
|
77
|
+
export interface UAParserExtensions {
|
|
78
|
+
browser?: UARegexMapEntry[];
|
|
79
|
+
cpu?: UARegexMapEntry[];
|
|
80
|
+
device?: UARegexMapEntry[];
|
|
81
|
+
engine?: UARegexMapEntry[];
|
|
82
|
+
os?: UARegexMapEntry[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Parses the given User-Agent string into browser, engine, os, device and cpu information.
|
|
86
|
+
*
|
|
87
|
+
* When `ua` is not provided and running in a browser - `navigator.userAgent` is used
|
|
88
|
+
* (with client-hints-based refinements, e.g. Brave and iPadOS detection).
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseUserAgent(userAgent?: string, extensions?: UAParserExtensions): UAResult;
|
|
91
|
+
/**
|
|
92
|
+
* User-Agent parser.
|
|
93
|
+
*
|
|
94
|
+
* Compared to `parseUserAgent()`, the class allows parsing only the needed parts
|
|
95
|
+
* (e.g `getBrowser()` alone is much cheaper than `getResult()`),
|
|
96
|
+
* and reusing the compiled extensions across multiple `setUA()` calls.
|
|
97
|
+
*/
|
|
98
|
+
export declare class UAParser {
|
|
99
|
+
constructor(ua?: string, extensions?: UAParserExtensions);
|
|
100
|
+
constructor(extensions: UAParserExtensions);
|
|
101
|
+
private ua;
|
|
102
|
+
private readonly nav;
|
|
103
|
+
private readonly rgxMap;
|
|
104
|
+
private readonly isSelfNav;
|
|
105
|
+
getBrowser(): UABrowser;
|
|
106
|
+
getCPU(): UACpu;
|
|
107
|
+
getDevice(): UADevice;
|
|
108
|
+
getEngine(): UAEngine;
|
|
109
|
+
getOS(): UAOS;
|
|
110
|
+
getResult(): UAResult;
|
|
111
|
+
getUA(): string;
|
|
112
|
+
setUA(ua: string | undefined): this;
|
|
113
|
+
}
|