@wtasnorg/node-lib 0.0.7 → 0.0.8
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/changelog.txt +14 -0
- package/dev_checklist.txt +56 -0
- package/docs/README.md +8 -35
- package/docs/docs.json +448 -205
- package/docs/functions/createFindDirectories.md +2 -2
- package/docs/functions/hello.md +2 -2
- package/docs/functions/parseUserAgent.md +42 -0
- package/docs/functions/pojo.md +2 -2
- package/docs/interfaces/FileSystemDependencies.md +9 -9
- package/docs/interfaces/FindDirectoriesOptions.md +8 -8
- package/docs/interfaces/UserAgentInfo.md +61 -0
- package/eslint.config.js +7 -2
- package/gen-docs/001_commands.txt +44 -0
- package/gen-docs/001_coverage.txt +43 -0
- package/gen-docs/001_env.txt +33 -0
- package/gen-docs/001_lint.txt +40 -0
- package/gen-docs/001_state.txt +58 -0
- package/gen-docs/002_api.txt +34 -0
- package/gen-docs/002_deps.txt +46 -0
- package/gen-docs/002_errors.txt +34 -0
- package/gen-docs/002_naming.txt +36 -0
- package/gen-docs/002_notes.txt +20 -0
- package/gen-docs/002_purity.txt +36 -0
- package/gen-docs/002_scope.txt +28 -0
- package/gen-docs/002_srp.txt +34 -0
- package/gen-sec/001_commands.txt +65 -0
- package/gen-sec/001_env.txt +28 -0
- package/gen-sec/001_findings.txt +63 -0
- package/gen-sec/001_inventory.txt +41 -0
- package/gen-sec/001_owasp.txt +78 -0
- package/gen-sec/001_scope.txt +44 -0
- package/package.json +3 -2
- package/{README.md → readme.txt} +2 -1
- package/src/find.d.ts +4 -4
- package/src/find.js +12 -6
- package/src/find.ts +10 -10
- package/src/index.d.ts +4 -2
- package/src/index.js +2 -1
- package/src/index.ts +5 -1
- package/src/pojo.js +1 -1
- package/src/pojo.test.js +1 -3
- package/src/pojo.test.ts +2 -1
- package/src/pojo.ts +1 -1
- package/src/user-agent.d.ts +48 -0
- package/src/user-agent.js +189 -0
- package/src/user-agent.test.d.ts +2 -0
- package/src/user-agent.test.js +54 -0
- package/src/user-agent.test.ts +60 -0
- package/src/user-agent.ts +199 -0
- package/DEV_CHECKLIST.md +0 -15
- package/docs/_media/LICENSE +0 -21
- package/docs/globals.md +0 -16
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Information extracted from a user-agent string.
|
|
3
|
+
*/
|
|
4
|
+
export interface UserAgentInfo {
|
|
5
|
+
/**
|
|
6
|
+
* Browser name (e.g., Chrome, Firefox, Safari, Edge, Opera, Other).
|
|
7
|
+
*/
|
|
8
|
+
browser: string;
|
|
9
|
+
/**
|
|
10
|
+
* Browser version (e.g., 120.0.0.0).
|
|
11
|
+
*/
|
|
12
|
+
version: string;
|
|
13
|
+
/**
|
|
14
|
+
* Operating system (e.g., Windows, macOS, Linux, iOS, Android, Other).
|
|
15
|
+
*/
|
|
16
|
+
os: string;
|
|
17
|
+
/**
|
|
18
|
+
* Device type (e.g., Mobile, Tablet, Desktop, Other).
|
|
19
|
+
*/
|
|
20
|
+
device: string;
|
|
21
|
+
/**
|
|
22
|
+
* Rendering engine (e.g., Blink, WebKit, Gecko, Presto, Other).
|
|
23
|
+
*/
|
|
24
|
+
engine: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parses a user-agent string into a UserAgentInfo object.
|
|
28
|
+
*
|
|
29
|
+
* @param ua - The user-agent string to parse.
|
|
30
|
+
* @returns An object containing the extracted information.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Success Example (Chrome on Windows)
|
|
35
|
+
* const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
36
|
+
* const info = parseUserAgent(ua);
|
|
37
|
+
* // { browser: "Chrome", version: "120.0.0.0", os: "Windows", device: "Desktop", engine: "Blink" }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Error/Fallback Example (Empty string)
|
|
43
|
+
* const info = parseUserAgent("");
|
|
44
|
+
* // { browser: "Other", version: "0", os: "Other", device: "Desktop", engine: "Other" }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseUserAgent(ua: string): UserAgentInfo;
|
|
48
|
+
//# sourceMappingURL=user-agent.d.ts.map
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a user-agent string into a UserAgentInfo object.
|
|
3
|
+
*
|
|
4
|
+
* @param ua - The user-agent string to parse.
|
|
5
|
+
* @returns An object containing the extracted information.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Success Example (Chrome on Windows)
|
|
10
|
+
* const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
11
|
+
* const info = parseUserAgent(ua);
|
|
12
|
+
* // { browser: "Chrome", version: "120.0.0.0", os: "Windows", device: "Desktop", engine: "Blink" }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Error/Fallback Example (Empty string)
|
|
18
|
+
* const info = parseUserAgent("");
|
|
19
|
+
* // { browser: "Other", version: "0", os: "Other", device: "Desktop", engine: "Other" }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function parseUserAgent(ua) {
|
|
23
|
+
if (!ua) {
|
|
24
|
+
return {
|
|
25
|
+
browser: "Other",
|
|
26
|
+
version: "0",
|
|
27
|
+
os: "Other",
|
|
28
|
+
device: "Desktop",
|
|
29
|
+
engine: "Other",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const browserInfo = detectBrowser(ua);
|
|
33
|
+
return {
|
|
34
|
+
browser: browserInfo.name,
|
|
35
|
+
version: browserInfo.version,
|
|
36
|
+
os: detectOS(ua),
|
|
37
|
+
device: detectDeviceType(ua),
|
|
38
|
+
engine: detectEngine(ua),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Detects the browser name and version from a user-agent string.
|
|
43
|
+
*
|
|
44
|
+
* @param ua - The user-agent string.
|
|
45
|
+
* @returns An object with name and version.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Success Example
|
|
50
|
+
* detectBrowser("Mozilla/5.0 ... Firefox/121.0");
|
|
51
|
+
* // { name: "Firefox", version: "121.0" }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Error/Fallback Example
|
|
57
|
+
* detectBrowser("UnknownBot/1.0");
|
|
58
|
+
* // { name: "Other", version: "0" }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function detectBrowser(ua) {
|
|
62
|
+
let name = "Other";
|
|
63
|
+
let version = "0";
|
|
64
|
+
if (ua.includes("Edg/")) {
|
|
65
|
+
name = "Edge";
|
|
66
|
+
version = ua.split("Edg/")[1]?.split(" ")[0] || "0";
|
|
67
|
+
}
|
|
68
|
+
else if (ua.includes("Chrome/") && !ua.includes("Chromium/")) {
|
|
69
|
+
name = "Chrome";
|
|
70
|
+
version = ua.split("Chrome/")[1]?.split(" ")[0] || "0";
|
|
71
|
+
}
|
|
72
|
+
else if (ua.includes("Safari/") && !ua.includes("Chrome/")) {
|
|
73
|
+
name = "Safari";
|
|
74
|
+
version = ua.split("Version/")[1]?.split(" ")[0] || ua.split("Safari/")[1]?.split(" ")[0] || "0";
|
|
75
|
+
}
|
|
76
|
+
else if (ua.includes("Firefox/")) {
|
|
77
|
+
name = "Firefox";
|
|
78
|
+
version = ua.split("Firefox/")[1]?.split(" ")[0] || "0";
|
|
79
|
+
}
|
|
80
|
+
else if (ua.includes("OPR/") || ua.includes("Opera/")) {
|
|
81
|
+
name = "Opera";
|
|
82
|
+
version = (ua.split("OPR/")[1] || ua.split("Opera/")[1])?.split(" ")[0] || "0";
|
|
83
|
+
}
|
|
84
|
+
return { name, version };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Detects the operating system from a user-agent string.
|
|
88
|
+
*
|
|
89
|
+
* @param ua - The user-agent string.
|
|
90
|
+
* @returns The operating system name.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Success Example
|
|
95
|
+
* detectOS("Mozilla/5.0 (iPhone; ...)");
|
|
96
|
+
* // "iOS"
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* // Error/Fallback Example
|
|
102
|
+
* detectOS("Custom OS");
|
|
103
|
+
* // "Other"
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
function detectOS(ua) {
|
|
107
|
+
if (ua.includes("iPhone") || ua.includes("iPad") || ua.includes("iPod")) {
|
|
108
|
+
return "iOS";
|
|
109
|
+
}
|
|
110
|
+
if (ua.includes("Windows")) {
|
|
111
|
+
return "Windows";
|
|
112
|
+
}
|
|
113
|
+
if (ua.includes("Mac OS X")) {
|
|
114
|
+
return "macOS";
|
|
115
|
+
}
|
|
116
|
+
if (ua.includes("Android")) {
|
|
117
|
+
return "Android";
|
|
118
|
+
}
|
|
119
|
+
if (ua.includes("Linux")) {
|
|
120
|
+
return "Linux";
|
|
121
|
+
}
|
|
122
|
+
return "Other";
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Detects the device type (Desktop, Mobile, Tablet) from a user-agent string.
|
|
126
|
+
*
|
|
127
|
+
* @param ua - The user-agent string.
|
|
128
|
+
* @returns The device type.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* // Success Example
|
|
133
|
+
* detectDeviceType("Mozilla/5.0 (iPad; ...)");
|
|
134
|
+
* // "Tablet"
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Error/Fallback Example
|
|
140
|
+
* detectDeviceType("Generic Browser");
|
|
141
|
+
* // "Desktop"
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
function detectDeviceType(ua) {
|
|
145
|
+
if (ua.includes("iPad") || (ua.includes("Android") && !ua.includes("Mobile"))) {
|
|
146
|
+
return "Tablet";
|
|
147
|
+
}
|
|
148
|
+
if (ua.includes("Mobi")) {
|
|
149
|
+
return "Mobile";
|
|
150
|
+
}
|
|
151
|
+
return "Desktop";
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Detects the rendering engine from a user-agent string.
|
|
155
|
+
*
|
|
156
|
+
* @param ua - The user-agent string.
|
|
157
|
+
* @returns The engine name.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* // Success Example
|
|
162
|
+
* detectEngine("Mozilla/5.0 ... AppleWebKit/537.36 ...");
|
|
163
|
+
* // "Blink"
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // Error/Fallback Example
|
|
169
|
+
* detectEngine("Unknown Engine");
|
|
170
|
+
* // "Other"
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
function detectEngine(ua) {
|
|
174
|
+
// Blink check must come first: Chrome/Chromium browsers use AppleWebKit but are Blink-based
|
|
175
|
+
if (ua.includes("Chrome/") && ua.includes("AppleWebKit/")) {
|
|
176
|
+
return "Blink";
|
|
177
|
+
}
|
|
178
|
+
if (ua.includes("AppleWebKit")) {
|
|
179
|
+
return "WebKit";
|
|
180
|
+
}
|
|
181
|
+
if (ua.includes("Gecko/")) {
|
|
182
|
+
return "Gecko";
|
|
183
|
+
}
|
|
184
|
+
if (ua.includes("Presto/")) {
|
|
185
|
+
return "Presto";
|
|
186
|
+
}
|
|
187
|
+
return "Other";
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=user-agent.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { parseUserAgent } from "./user-agent.js";
|
|
4
|
+
test("parseUserAgent - Chrome on Windows", () => {
|
|
5
|
+
const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
6
|
+
const info = parseUserAgent(ua);
|
|
7
|
+
assert.strictEqual(info.browser, "Chrome");
|
|
8
|
+
assert.strictEqual(info.os, "Windows");
|
|
9
|
+
assert.strictEqual(info.device, "Desktop");
|
|
10
|
+
assert.strictEqual(info.version, "120.0.0.0");
|
|
11
|
+
});
|
|
12
|
+
test("parseUserAgent - Firefox on macOS", () => {
|
|
13
|
+
const ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14.2; rv:121.0) Gecko/20100101 Firefox/121.0";
|
|
14
|
+
const info = parseUserAgent(ua);
|
|
15
|
+
assert.strictEqual(info.browser, "Firefox");
|
|
16
|
+
assert.strictEqual(info.os, "macOS");
|
|
17
|
+
assert.strictEqual(info.version, "121.0");
|
|
18
|
+
assert.strictEqual(info.engine, "Gecko");
|
|
19
|
+
});
|
|
20
|
+
test("parseUserAgent - Safari on iPhone", () => {
|
|
21
|
+
const ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1";
|
|
22
|
+
const info = parseUserAgent(ua);
|
|
23
|
+
assert.strictEqual(info.browser, "Safari");
|
|
24
|
+
assert.strictEqual(info.os, "iOS");
|
|
25
|
+
assert.strictEqual(info.device, "Mobile");
|
|
26
|
+
assert.strictEqual(info.version, "17.2");
|
|
27
|
+
});
|
|
28
|
+
test("parseUserAgent - Edge on Windows", () => {
|
|
29
|
+
const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0";
|
|
30
|
+
const info = parseUserAgent(ua);
|
|
31
|
+
assert.strictEqual(info.browser, "Edge");
|
|
32
|
+
assert.strictEqual(info.os, "Windows");
|
|
33
|
+
assert.strictEqual(info.version, "120.0.0.0");
|
|
34
|
+
});
|
|
35
|
+
test("parseUserAgent - Chrome on Android (Mobile)", () => {
|
|
36
|
+
const ua = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
|
|
37
|
+
const info = parseUserAgent(ua);
|
|
38
|
+
assert.strictEqual(info.browser, "Chrome");
|
|
39
|
+
assert.strictEqual(info.os, "Android");
|
|
40
|
+
assert.strictEqual(info.device, "Mobile");
|
|
41
|
+
});
|
|
42
|
+
test("parseUserAgent - Android Tablet", () => {
|
|
43
|
+
const ua = "Mozilla/5.0 (Linux; Android 10; SM-T510) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
44
|
+
const info = parseUserAgent(ua);
|
|
45
|
+
assert.strictEqual(info.browser, "Chrome");
|
|
46
|
+
assert.strictEqual(info.os, "Android");
|
|
47
|
+
assert.strictEqual(info.device, "Tablet");
|
|
48
|
+
});
|
|
49
|
+
test("parseUserAgent - Empty/Null UA", () => {
|
|
50
|
+
const info = parseUserAgent("");
|
|
51
|
+
assert.strictEqual(info.browser, "Other");
|
|
52
|
+
assert.strictEqual(info.device, "Desktop");
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=user-agent.test.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { parseUserAgent } from "./user-agent.js";
|
|
4
|
+
|
|
5
|
+
test("parseUserAgent - Chrome on Windows", () => {
|
|
6
|
+
const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
7
|
+
const info = parseUserAgent(ua);
|
|
8
|
+
assert.strictEqual(info.browser, "Chrome");
|
|
9
|
+
assert.strictEqual(info.os, "Windows");
|
|
10
|
+
assert.strictEqual(info.device, "Desktop");
|
|
11
|
+
assert.strictEqual(info.version, "120.0.0.0");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("parseUserAgent - Firefox on macOS", () => {
|
|
15
|
+
const ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14.2; rv:121.0) Gecko/20100101 Firefox/121.0";
|
|
16
|
+
const info = parseUserAgent(ua);
|
|
17
|
+
assert.strictEqual(info.browser, "Firefox");
|
|
18
|
+
assert.strictEqual(info.os, "macOS");
|
|
19
|
+
assert.strictEqual(info.version, "121.0");
|
|
20
|
+
assert.strictEqual(info.engine, "Gecko");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("parseUserAgent - Safari on iPhone", () => {
|
|
24
|
+
const ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1";
|
|
25
|
+
const info = parseUserAgent(ua);
|
|
26
|
+
assert.strictEqual(info.browser, "Safari");
|
|
27
|
+
assert.strictEqual(info.os, "iOS");
|
|
28
|
+
assert.strictEqual(info.device, "Mobile");
|
|
29
|
+
assert.strictEqual(info.version, "17.2");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("parseUserAgent - Edge on Windows", () => {
|
|
33
|
+
const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0";
|
|
34
|
+
const info = parseUserAgent(ua);
|
|
35
|
+
assert.strictEqual(info.browser, "Edge");
|
|
36
|
+
assert.strictEqual(info.os, "Windows");
|
|
37
|
+
assert.strictEqual(info.version, "120.0.0.0");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("parseUserAgent - Chrome on Android (Mobile)", () => {
|
|
41
|
+
const ua = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
|
|
42
|
+
const info = parseUserAgent(ua);
|
|
43
|
+
assert.strictEqual(info.browser, "Chrome");
|
|
44
|
+
assert.strictEqual(info.os, "Android");
|
|
45
|
+
assert.strictEqual(info.device, "Mobile");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("parseUserAgent - Android Tablet", () => {
|
|
49
|
+
const ua = "Mozilla/5.0 (Linux; Android 10; SM-T510) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
50
|
+
const info = parseUserAgent(ua);
|
|
51
|
+
assert.strictEqual(info.browser, "Chrome");
|
|
52
|
+
assert.strictEqual(info.os, "Android");
|
|
53
|
+
assert.strictEqual(info.device, "Tablet");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("parseUserAgent - Empty/Null UA", () => {
|
|
57
|
+
const info = parseUserAgent("");
|
|
58
|
+
assert.strictEqual(info.browser, "Other");
|
|
59
|
+
assert.strictEqual(info.device, "Desktop");
|
|
60
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Information extracted from a user-agent string.
|
|
3
|
+
*/
|
|
4
|
+
export interface UserAgentInfo {
|
|
5
|
+
/**
|
|
6
|
+
* Browser name (e.g., Chrome, Firefox, Safari, Edge, Opera, Other).
|
|
7
|
+
*/
|
|
8
|
+
browser: string;
|
|
9
|
+
/**
|
|
10
|
+
* Browser version (e.g., 120.0.0.0).
|
|
11
|
+
*/
|
|
12
|
+
version: string;
|
|
13
|
+
/**
|
|
14
|
+
* Operating system (e.g., Windows, macOS, Linux, iOS, Android, Other).
|
|
15
|
+
*/
|
|
16
|
+
os: string;
|
|
17
|
+
/**
|
|
18
|
+
* Device type (e.g., Mobile, Tablet, Desktop, Other).
|
|
19
|
+
*/
|
|
20
|
+
device: string;
|
|
21
|
+
/**
|
|
22
|
+
* Rendering engine (e.g., Blink, WebKit, Gecko, Presto, Other).
|
|
23
|
+
*/
|
|
24
|
+
engine: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parses a user-agent string into a UserAgentInfo object.
|
|
29
|
+
*
|
|
30
|
+
* @param ua - The user-agent string to parse.
|
|
31
|
+
* @returns An object containing the extracted information.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Success Example (Chrome on Windows)
|
|
36
|
+
* const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
37
|
+
* const info = parseUserAgent(ua);
|
|
38
|
+
* // { browser: "Chrome", version: "120.0.0.0", os: "Windows", device: "Desktop", engine: "Blink" }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // Error/Fallback Example (Empty string)
|
|
44
|
+
* const info = parseUserAgent("");
|
|
45
|
+
* // { browser: "Other", version: "0", os: "Other", device: "Desktop", engine: "Other" }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function parseUserAgent(ua: string): UserAgentInfo {
|
|
49
|
+
if (!ua) {
|
|
50
|
+
return {
|
|
51
|
+
browser: "Other",
|
|
52
|
+
version: "0",
|
|
53
|
+
os: "Other",
|
|
54
|
+
device: "Desktop",
|
|
55
|
+
engine: "Other",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const browserInfo = detectBrowser(ua);
|
|
60
|
+
return {
|
|
61
|
+
browser: browserInfo.name,
|
|
62
|
+
version: browserInfo.version,
|
|
63
|
+
os: detectOS(ua),
|
|
64
|
+
device: detectDeviceType(ua),
|
|
65
|
+
engine: detectEngine(ua),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Detects the browser name and version from a user-agent string.
|
|
71
|
+
*
|
|
72
|
+
* @param ua - The user-agent string.
|
|
73
|
+
* @returns An object with name and version.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // Success Example
|
|
78
|
+
* detectBrowser("Mozilla/5.0 ... Firefox/121.0");
|
|
79
|
+
* // { name: "Firefox", version: "121.0" }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Error/Fallback Example
|
|
85
|
+
* detectBrowser("UnknownBot/1.0");
|
|
86
|
+
* // { name: "Other", version: "0" }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
function detectBrowser(ua: string): { name: string; version: string } {
|
|
90
|
+
let name = "Other";
|
|
91
|
+
let version = "0";
|
|
92
|
+
|
|
93
|
+
if (ua.includes("Edg/")) {
|
|
94
|
+
name = "Edge";
|
|
95
|
+
version = ua.split("Edg/")[1]?.split(" ")[0] || "0";
|
|
96
|
+
} else if (ua.includes("Chrome/") && !ua.includes("Chromium/")) {
|
|
97
|
+
name = "Chrome";
|
|
98
|
+
version = ua.split("Chrome/")[1]?.split(" ")[0] || "0";
|
|
99
|
+
} else if (ua.includes("Safari/") && !ua.includes("Chrome/")) {
|
|
100
|
+
name = "Safari";
|
|
101
|
+
version = ua.split("Version/")[1]?.split(" ")[0] || ua.split("Safari/")[1]?.split(" ")[0] || "0";
|
|
102
|
+
} else if (ua.includes("Firefox/")) {
|
|
103
|
+
name = "Firefox";
|
|
104
|
+
version = ua.split("Firefox/")[1]?.split(" ")[0] || "0";
|
|
105
|
+
} else if (ua.includes("OPR/") || ua.includes("Opera/")) {
|
|
106
|
+
name = "Opera";
|
|
107
|
+
version = (ua.split("OPR/")[1] || ua.split("Opera/")[1])?.split(" ")[0] || "0";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { name, version };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Detects the operating system from a user-agent string.
|
|
115
|
+
*
|
|
116
|
+
* @param ua - The user-agent string.
|
|
117
|
+
* @returns The operating system name.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Success Example
|
|
122
|
+
* detectOS("Mozilla/5.0 (iPhone; ...)");
|
|
123
|
+
* // "iOS"
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Error/Fallback Example
|
|
129
|
+
* detectOS("Custom OS");
|
|
130
|
+
* // "Other"
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
function detectOS(ua: string): string {
|
|
134
|
+
if (ua.includes("iPhone") || ua.includes("iPad") || ua.includes("iPod")) { return "iOS"; }
|
|
135
|
+
if (ua.includes("Windows")) { return "Windows"; }
|
|
136
|
+
if (ua.includes("Mac OS X")) { return "macOS"; }
|
|
137
|
+
if (ua.includes("Android")) { return "Android"; }
|
|
138
|
+
if (ua.includes("Linux")) { return "Linux"; }
|
|
139
|
+
return "Other";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Detects the device type (Desktop, Mobile, Tablet) from a user-agent string.
|
|
144
|
+
*
|
|
145
|
+
* @param ua - The user-agent string.
|
|
146
|
+
* @returns The device type.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* // Success Example
|
|
151
|
+
* detectDeviceType("Mozilla/5.0 (iPad; ...)");
|
|
152
|
+
* // "Tablet"
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Error/Fallback Example
|
|
158
|
+
* detectDeviceType("Generic Browser");
|
|
159
|
+
* // "Desktop"
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
function detectDeviceType(ua: string): string {
|
|
163
|
+
if (ua.includes("iPad") || (ua.includes("Android") && !ua.includes("Mobile"))) {
|
|
164
|
+
return "Tablet";
|
|
165
|
+
}
|
|
166
|
+
if (ua.includes("Mobi")) {
|
|
167
|
+
return "Mobile";
|
|
168
|
+
}
|
|
169
|
+
return "Desktop";
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Detects the rendering engine from a user-agent string.
|
|
174
|
+
*
|
|
175
|
+
* @param ua - The user-agent string.
|
|
176
|
+
* @returns The engine name.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* // Success Example
|
|
181
|
+
* detectEngine("Mozilla/5.0 ... AppleWebKit/537.36 ...");
|
|
182
|
+
* // "Blink"
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* // Error/Fallback Example
|
|
188
|
+
* detectEngine("Unknown Engine");
|
|
189
|
+
* // "Other"
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
function detectEngine(ua: string): string {
|
|
193
|
+
// Blink check must come first: Chrome/Chromium browsers use AppleWebKit but are Blink-based
|
|
194
|
+
if (ua.includes("Chrome/") && ua.includes("AppleWebKit/")) { return "Blink"; }
|
|
195
|
+
if (ua.includes("AppleWebKit")) { return "WebKit"; }
|
|
196
|
+
if (ua.includes("Gecko/")) { return "Gecko"; }
|
|
197
|
+
if (ua.includes("Presto/")) { return "Presto"; }
|
|
198
|
+
return "Other";
|
|
199
|
+
}
|
package/DEV_CHECKLIST.md
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Development Checklist
|
|
2
|
-
|
|
3
|
-
- [ ] Have you written tests for your code?
|
|
4
|
-
- [ ] Does the code pass all tests? `npm run test`
|
|
5
|
-
- [ ] Have you upated documentation?
|
|
6
|
-
- [ ] Have you generated docs via `npm run docs && npm run docs:json`
|
|
7
|
-
- [ ] Have you reviewed the code locally?
|
|
8
|
-
- [ ] Have you used the code locally?
|
|
9
|
-
- [ ] Check your email and username. Protect PII. `git log -n1`
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm run build
|
|
13
|
-
npm run test
|
|
14
|
-
npm run docs && npm run docs:json
|
|
15
|
-
```
|
package/docs/_media/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 wtasg
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/docs/globals.md
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
[**@wtasnorg/node-lib**](README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
# @wtasnorg/node-lib
|
|
6
|
-
|
|
7
|
-
## Interfaces
|
|
8
|
-
|
|
9
|
-
- [FileSystemDependencies](interfaces/FileSystemDependencies.md)
|
|
10
|
-
- [FindDirectoriesOptions](interfaces/FindDirectoriesOptions.md)
|
|
11
|
-
|
|
12
|
-
## Functions
|
|
13
|
-
|
|
14
|
-
- [createFindDirectories](functions/createFindDirectories.md)
|
|
15
|
-
- [hello](functions/hello.md)
|
|
16
|
-
- [pojo](functions/pojo.md)
|