@denniskrol/device-profiles 1.20251122.0 → 1.20251123.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/README.md +12 -1
- package/dist/deviceprofiles.json +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +10 -6
- package/package.json +1 -1
- package/src/deviceprofiles.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ npm install @denniskrol/device-profiles
|
|
|
15
15
|
## Basic Usage
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import DeviceProfiles from '@denniskrol/device-profiles';
|
|
18
|
+
import { DeviceProfiles } from '@denniskrol/device-profiles';
|
|
19
19
|
|
|
20
20
|
// Get a weighted random profile
|
|
21
21
|
const profile = new DeviceProfiles();
|
|
@@ -33,6 +33,16 @@ const safari = new DeviceProfiles({ browser: /Safari/ });
|
|
|
33
33
|
|
|
34
34
|
// Inclusion list (e.g. mobile OR tablet)
|
|
35
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
|
+
);
|
|
36
46
|
```
|
|
37
47
|
|
|
38
48
|
## Static Helpers
|
|
@@ -135,6 +145,7 @@ const randomDesktop = DeviceProfiles.random({ deviceType: 'desktop' });
|
|
|
135
145
|
- Primitive equality (deviceType: `'mobile'`)
|
|
136
146
|
- Inclusion list (deviceType: `['mobile','tablet']`)
|
|
137
147
|
- RegExp match (browser: `/Safari/`)
|
|
148
|
+
- Function predicate (profile => boolean) for full custom logic
|
|
138
149
|
|
|
139
150
|
## Weighted Selection
|
|
140
151
|
Each profile has a weight. Random selection is proportional to weight.
|