@denniskrol/device-profiles 1.20251122.0 → 1.20251122.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.
package/LICENSE CHANGED
@@ -1,24 +1,24 @@
1
- This is free and unencumbered software released into the public domain.
2
-
3
- Anyone is free to copy, modify, publish, use, compile, sell, or
4
- distribute this software, either in source code form or as a compiled
5
- binary, for any purpose, commercial or non-commercial, and by any
6
- means.
7
-
8
- In jurisdictions that recognize copyright laws, the author or authors
9
- of this software dedicate any and all copyright interest in the
10
- software to the public domain. We make this dedication for the benefit
11
- of the public at large and to the detriment of our heirs and
12
- successors. We intend this dedication to be an overt act of
13
- relinquishment in perpetuity of all present and future rights to this
14
- software under copyright law.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- For more information, please refer to <https://unlicense.org>
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
package/README.md CHANGED
@@ -1,151 +1,162 @@
1
- # Device Profiles
2
-
3
- Daily updated browser/device profiles with weighted random selection. Useful for realistic client fingerprint spoofing, testing, load generation.
4
-
5
- Data comes from a website with about 65% mobile and 35% desktop traffic, and uses [browser-profiler](https://github.com/denniskrol/browser-profiler) to get data.
6
-
7
- This is inspired by [intoli/user-agents](https://github.com/intoli/user-agents) which doesn't seem to get updated anymore and lacks some data that I needed.
8
-
9
- ## Install
10
-
11
- ```bash
12
- npm install @denniskrol/device-profiles
13
- ```
14
-
15
- ## Basic Usage
16
-
17
- ```ts
18
- import DeviceProfiles from '@denniskrol/device-profiles';
19
-
20
- // Get a weighted random profile
21
- const profile = new DeviceProfiles();
22
- console.log(profile.userAgent, profile.deviceType);
23
- ```
24
-
25
- ## Filtered Random
26
-
27
- ```ts
28
- // Only mobile devices
29
- const mobile = new DeviceProfiles({ deviceType: 'mobile' });
30
-
31
- // Regex match browser name
32
- const safari = new DeviceProfiles({ browser: /Safari/ });
33
-
34
- // Inclusion list (e.g. mobile OR tablet)
35
- const touch = new DeviceProfiles({ deviceType: ['mobile', 'tablet'] });
36
- ```
37
-
38
- ## Static Helpers
39
-
40
- ```ts
41
- import { DeviceProfiles } from '@denniskrol/device-profiles';
42
-
43
- // Get array of all profiles
44
- const all = DeviceProfiles.all();
45
-
46
- // Get random with filter without instantiating
47
- const randomDesktop = DeviceProfiles.random({ deviceType: 'desktop' });
48
- ```
49
-
50
- ## Profile example
51
-
52
- ```json
53
- {
54
- "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
55
- "platform": "Win32",
56
- "deviceMemory": 8,
57
- "hardwareConcurrency": 8,
58
- "vendor": "Google Inc.",
59
- "screenHeight": 720,
60
- "screenWidth": 1280,
61
- "viewportHeight": 568,
62
- "viewportWidth": 1251,
63
- "devicePixelRatio": 1.5,
64
- "webglRenderer": "ANGLE (Intel, Intel(R) UHD Graphics (0x00009B41) Direct3D11 vs_5_0 ps_5_0, D3D11)",
65
- "webglVendor": "Google Inc. (Intel)",
66
- "webGpuArchitecture": "gen-9",
67
- "webGpuVendor": "intel",
68
- "storageQuota": {
69
- "quota": 113282066841,
70
- "usage": 0,
71
- "available": 113282066841
72
- },
73
- "jsHeapSizeLimit": 2248146944,
74
- "fonts": [
75
- "Aldhabi",
76
- "Bahnschrift",
77
- "Cambria Math",
78
- "Gadugi",
79
- "HoloLens MDL2 Assets",
80
- "Ink Free",
81
- "Javanese Text",
82
- "Leelawadee UI",
83
- "Lucida Console",
84
- "MS Outlook",
85
- "Myanmar Text",
86
- "Nirmala UI",
87
- "Segoe MDL2 Assets",
88
- "Segoe UI Emoji"
89
- ],
90
- "userAgentData": {
91
- "architecture": "x86",
92
- "bitness": "64",
93
- "brands": [
94
- {
95
- "brand": "Chromium",
96
- "version": "142"
97
- },
98
- {
99
- "brand": "Google Chrome",
100
- "version": "142"
101
- },
102
- {
103
- "brand": "Not_A Brand",
104
- "version": "99"
105
- }
106
- ],
107
- "fullVersionList": [
108
- {
109
- "brand": "Chromium",
110
- "version": "142.0.7444.134"
111
- },
112
- {
113
- "brand": "Google Chrome",
114
- "version": "142.0.7444.134"
115
- },
116
- {
117
- "brand": "Not_A Brand",
118
- "version": "99.0.0.0"
119
- }
120
- ],
121
- "mobile": false,
122
- "model": null,
123
- "platform": "Windows",
124
- "platformVersion": "10.0.0",
125
- "uaFullVersion": "142.0.7444.134"
126
- },
127
- "weight":26,
128
- "deviceType":"desktop",
129
- "browser":"Chrome",
130
- "osName":"Windows"
131
- }
132
- ```
133
-
134
- ## Filtering Rules
135
- - Primitive equality (deviceType: `'mobile'`)
136
- - Inclusion list (deviceType: `['mobile','tablet']`)
137
- - RegExp match (browser: `/Safari/`)
138
-
139
- ## Weighted Selection
140
- Each profile has a weight. Random selection is proportional to weight.
141
-
142
- ## JSON Access
143
- You can also import the raw JSON:
144
-
145
- ```ts
146
- import profilesJson from '@denniskrol/device-profiles/deviceprofiles.json';
147
- console.log(profilesJson.length);
148
- ```
149
-
150
- ## License
151
- Unlicense
1
+ # Device Profiles
2
+
3
+ Daily updated browser/device profiles with weighted random selection. Useful for realistic client fingerprint spoofing, testing, load generation.
4
+
5
+ Data comes from a website with about 65% mobile and 35% desktop traffic, and uses [browser-profiler](https://github.com/denniskrol/browser-profiler) to get data.
6
+
7
+ This is inspired by [intoli/user-agents](https://github.com/intoli/user-agents) which doesn't seem to get updated anymore and lacks some data that I needed.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @denniskrol/device-profiles
13
+ ```
14
+
15
+ ## Basic Usage
16
+
17
+ ```ts
18
+ import { DeviceProfiles } from '@denniskrol/device-profiles';
19
+
20
+ // Get a weighted random profile
21
+ const profile = new DeviceProfiles();
22
+ console.log(profile.userAgent, profile.deviceType);
23
+ ```
24
+
25
+ ## Filtered Random
26
+
27
+ ```ts
28
+ // Only mobile devices
29
+ const mobile = new DeviceProfiles({ deviceType: 'mobile' });
30
+
31
+ // Regex match browser name
32
+ const safari = new DeviceProfiles({ browser: /Safari/ });
33
+
34
+ // Inclusion list (e.g. mobile OR tablet)
35
+ const touch = new DeviceProfiles({ deviceType: ['mobile', 'tablet'] });
36
+
37
+ // Function predicate (custom logic)
38
+ const chromeWithUAData = new DeviceProfiles(profile =>
39
+ profile.userAgent.includes('Chrome') && !!profile.userAgentData
40
+ );
41
+
42
+ // Using static random with predicate
43
+ const randomChrome = DeviceProfiles.random(profile =>
44
+ /Chrome/.test(profile.userAgent) && profile.deviceType === 'desktop'
45
+ );
46
+ ```
47
+
48
+ ## Static Helpers
49
+
50
+ ```ts
51
+ import { DeviceProfiles } from '@denniskrol/device-profiles';
52
+
53
+ // Get array of all profiles
54
+ const all = DeviceProfiles.all();
55
+
56
+ // Get random with filter without instantiating
57
+ const randomDesktop = DeviceProfiles.random({ deviceType: 'desktop' });
58
+ ```
59
+
60
+ ## Profile example
61
+
62
+ ```json
63
+ {
64
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
65
+ "platform": "Win32",
66
+ "deviceMemory": 8,
67
+ "hardwareConcurrency": 8,
68
+ "vendor": "Google Inc.",
69
+ "screenHeight": 720,
70
+ "screenWidth": 1280,
71
+ "viewportHeight": 568,
72
+ "viewportWidth": 1251,
73
+ "devicePixelRatio": 1.5,
74
+ "webglRenderer": "ANGLE (Intel, Intel(R) UHD Graphics (0x00009B41) Direct3D11 vs_5_0 ps_5_0, D3D11)",
75
+ "webglVendor": "Google Inc. (Intel)",
76
+ "webGpuArchitecture": "gen-9",
77
+ "webGpuVendor": "intel",
78
+ "storageQuota": {
79
+ "quota": 113282066841,
80
+ "usage": 0,
81
+ "available": 113282066841
82
+ },
83
+ "jsHeapSizeLimit": 2248146944,
84
+ "fonts": [
85
+ "Aldhabi",
86
+ "Bahnschrift",
87
+ "Cambria Math",
88
+ "Gadugi",
89
+ "HoloLens MDL2 Assets",
90
+ "Ink Free",
91
+ "Javanese Text",
92
+ "Leelawadee UI",
93
+ "Lucida Console",
94
+ "MS Outlook",
95
+ "Myanmar Text",
96
+ "Nirmala UI",
97
+ "Segoe MDL2 Assets",
98
+ "Segoe UI Emoji"
99
+ ],
100
+ "userAgentData": {
101
+ "architecture": "x86",
102
+ "bitness": "64",
103
+ "brands": [
104
+ {
105
+ "brand": "Chromium",
106
+ "version": "142"
107
+ },
108
+ {
109
+ "brand": "Google Chrome",
110
+ "version": "142"
111
+ },
112
+ {
113
+ "brand": "Not_A Brand",
114
+ "version": "99"
115
+ }
116
+ ],
117
+ "fullVersionList": [
118
+ {
119
+ "brand": "Chromium",
120
+ "version": "142.0.7444.134"
121
+ },
122
+ {
123
+ "brand": "Google Chrome",
124
+ "version": "142.0.7444.134"
125
+ },
126
+ {
127
+ "brand": "Not_A Brand",
128
+ "version": "99.0.0.0"
129
+ }
130
+ ],
131
+ "mobile": false,
132
+ "model": null,
133
+ "platform": "Windows",
134
+ "platformVersion": "10.0.0",
135
+ "uaFullVersion": "142.0.7444.134"
136
+ },
137
+ "weight":26,
138
+ "deviceType":"desktop",
139
+ "browser":"Chrome",
140
+ "osName":"Windows"
141
+ }
142
+ ```
143
+
144
+ ## Filtering Rules
145
+ - Primitive equality (deviceType: `'mobile'`)
146
+ - Inclusion list (deviceType: `['mobile','tablet']`)
147
+ - RegExp match (browser: `/Safari/`)
148
+ - Function predicate (profile => boolean) for full custom logic
149
+
150
+ ## Weighted Selection
151
+ Each profile has a weight. Random selection is proportional to weight.
152
+
153
+ ## JSON Access
154
+ You can also import the raw JSON:
155
+
156
+ ```ts
157
+ import profilesJson from '@denniskrol/device-profiles/deviceprofiles.json';
158
+ console.log(profilesJson.length);
159
+ ```
160
+
161
+ ## License
162
+ Unlicense
package/dist/index.d.ts CHANGED
@@ -29,13 +29,16 @@ export interface DeviceProfile {
29
29
  [key: string]: any;
30
30
  }
31
31
  export type DeviceProfileFilter = Partial<Record<keyof DeviceProfile, any>> & {};
32
+ export type DeviceProfilePredicate = (profile: DeviceProfile) => boolean;
32
33
  export declare class DeviceProfiles {
33
34
  [key: string]: any;
34
35
  userAgent: string;
35
36
  private _profile;
36
- constructor(filter?: DeviceProfileFilter);
37
+ constructor(filter?: DeviceProfileFilter | DeviceProfilePredicate);
37
38
  static all(): DeviceProfile[];
38
- static random(filter?: DeviceProfileFilter): DeviceProfile;
39
+ static random(): DeviceProfile;
40
+ static random(filter: DeviceProfileFilter): DeviceProfile;
41
+ static random(predicate: DeviceProfilePredicate): DeviceProfile;
39
42
  get profile(): DeviceProfile;
40
43
  }
41
44
  export default DeviceProfiles;
package/dist/index.js CHANGED
@@ -26,6 +26,14 @@ function matchesFilter(profile, filter) {
26
26
  }
27
27
  return true;
28
28
  }
29
+ // Helper to unify object or predicate filtering
30
+ function filterProfiles(input) {
31
+ if (!input || (typeof input === 'object' && Object.keys(input).length === 0))
32
+ return profiles;
33
+ if (typeof input === 'function')
34
+ return profiles.filter(p => input(p));
35
+ return profiles.filter(p => matchesFilter(p, input));
36
+ }
29
37
  function pickWeightedRandom(items) {
30
38
  var _a;
31
39
  if (!items.length) {
@@ -43,9 +51,7 @@ function pickWeightedRandom(items) {
43
51
  }
44
52
  class DeviceProfiles {
45
53
  constructor(filter = {}) {
46
- const filtered = Object.keys(filter).length
47
- ? profiles.filter(p => matchesFilter(p, filter))
48
- : profiles;
54
+ const filtered = filterProfiles(filter);
49
55
  this._profile = pickWeightedRandom(filtered);
50
56
  this.userAgent = this._profile.userAgent; // explicit assignment
51
57
  Object.assign(this, this._profile);
@@ -54,9 +60,7 @@ class DeviceProfiles {
54
60
  return [...profiles];
55
61
  }
56
62
  static random(filter = {}) {
57
- const filtered = Object.keys(filter).length
58
- ? profiles.filter(p => matchesFilter(p, filter))
59
- : profiles;
63
+ const filtered = filterProfiles(filter);
60
64
  return pickWeightedRandom(filtered);
61
65
  }
62
66
  get profile() { return this._profile; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@denniskrol/device-profiles",
3
- "version": "1.20251122.0",
3
+ "version": "1.20251122.1",
4
4
  "description": "Daily updated browser device profiles",
5
5
  "keywords": [
6
6
  "device-profiles",