@wtasnorg/node-lib 0.0.6 → 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 -34
- package/docs/docs.json +1538 -0
- 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 +4 -4
- 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 +52 -0
- 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 +10 -3
- package/{README.md → readme.txt} +3 -1
- package/src/find.d.ts +4 -4
- package/src/find.js +13 -7
- package/src/find.test.js +2 -6
- package/src/find.test.ts +3 -11
- package/src/find.ts +13 -13
- package/src/index.d.ts +4 -2
- package/src/index.js +2 -1
- package/src/index.ts +6 -2
- package/src/pojo.d.ts +2 -2
- package/src/pojo.js +2 -2
- package/src/pojo.test.js +1 -3
- package/src/pojo.test.ts +2 -1
- package/src/pojo.ts +3 -3
- 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/test_report +26 -0
- package/typedoc.json +6 -2
- package/DEV_CHECKLIST.md +0 -15
- package/docs/_media/LICENSE +0 -21
- package/docs/globals.md +0 -16
|
@@ -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/test_report
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
> @wtasnorg/node-lib@0.0.7 test
|
|
3
|
+
> bash -c 'node --test src/**/*.test.js'
|
|
4
|
+
|
|
5
|
+
[32m✔ find: findDirectories success [90m(1.077042ms)[39m[39m
|
|
6
|
+
[32m✔ find: findDirectories symlink is NOT treated as a directory [90m(0.181028ms)[39m[39m
|
|
7
|
+
[32m✔ find: findDirectories at depth=2 [90m(0.264408ms)[39m[39m
|
|
8
|
+
[32m✔ find: findDirectories at depth=3 [90m(0.225558ms)[39m[39m
|
|
9
|
+
hello from @wtasnorg/node-lib
|
|
10
|
+
hello from @wtasnorg/node-lib
|
|
11
|
+
▶ hello
|
|
12
|
+
[32m✔ returns a string that has the word 'hello' in it [90m(0.855703ms)[39m[39m
|
|
13
|
+
[32m✔ returns exact string [90m(0.132439ms)[39m[39m
|
|
14
|
+
[32m✔ hello [90m(1.649597ms)[39m[39m
|
|
15
|
+
[32m✔ pojo() should return only enumerable data fields [90m(0.948072ms)[39m[39m
|
|
16
|
+
[32m✔ pojo() should exclude methods [90m(0.137609ms)[39m[39m
|
|
17
|
+
[32m✔ pojo() should exclude prototype properties [90m(0.141089ms)[39m[39m
|
|
18
|
+
[32m✔ pojo() should ignore non-enumerable own properties [90m(0.671565ms)[39m[39m
|
|
19
|
+
[34mℹ tests 10[39m
|
|
20
|
+
[34mℹ suites 1[39m
|
|
21
|
+
[34mℹ pass 10[39m
|
|
22
|
+
[34mℹ fail 0[39m
|
|
23
|
+
[34mℹ cancelled 0[39m
|
|
24
|
+
[34mℹ skipped 0[39m
|
|
25
|
+
[34mℹ todo 0[39m
|
|
26
|
+
[34mℹ duration_ms 50.692585[39m
|
package/typedoc.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://typedoc.org/schema.json",
|
|
3
|
-
"entryPoints": [
|
|
3
|
+
"entryPoints": [
|
|
4
|
+
"./src/index.ts"
|
|
5
|
+
],
|
|
4
6
|
"excludePrivate": true,
|
|
5
7
|
"excludeProtected": true,
|
|
6
8
|
"name": "@wtasnorg/node-lib",
|
|
7
9
|
"out": "docs",
|
|
8
|
-
"plugin": [
|
|
10
|
+
"plugin": [
|
|
11
|
+
"typedoc-plugin-markdown"
|
|
12
|
+
],
|
|
9
13
|
"theme": "default",
|
|
10
14
|
"tsconfig": "./tsconfig.json",
|
|
11
15
|
}
|
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)
|