aki-info-detect 2.0.0 โ 2.0.2
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 +192 -0
- package/dist/aki-info-detect.js +2 -2
- package/dist/aki-info-detect.umd.cjs +2 -2
- package/dist/index.html +1377 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,6 +6,198 @@ A lightweight JavaScript library for detecting device, browser, hardware, and ne
|
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](https://bundlephobia.com/package/aki-info-detect)
|
|
8
8
|
|
|
9
|
+
## Introduction
|
|
10
|
+
|
|
11
|
+
**aki-info-detect** is a modern, lightweight JavaScript library designed to provide comprehensive device, browser, and system information detection for web applications. Built with performance and developer experience in mind, it leverages modern browser APIs including the Client Hints API for accurate hardware detection while maintaining a small footprint (~3.8 kB gzipped).
|
|
12
|
+
|
|
13
|
+
Whether you need to customize user experiences based on device capabilities, gather analytics data, or implement platform-specific features, aki-info-detect provides a unified, easy-to-use API that works seamlessly across all modern browsers.
|
|
14
|
+
|
|
15
|
+
### Why aki-info-detect?
|
|
16
|
+
|
|
17
|
+
- **๐ฏ Comprehensive Detection**: Get detailed information about browser, OS, CPU, GPU, RAM, network, battery, and more from a single library
|
|
18
|
+
- **โก Performance-First**: Minimal bundle size with tree-shakeable exportsโimport only what you need
|
|
19
|
+
- **๐ฎ Future-Proof**: Built on modern Web APIs with graceful fallbacks for older browsers
|
|
20
|
+
- **๐ช Apple Silicon Ready**: Advanced detection for Apple M-series chips (M1, M2, M3, M4, and beyond)
|
|
21
|
+
- **๐ Privacy-Conscious**: Implements caching for network requests to minimize external API calls
|
|
22
|
+
- **๐ฆ Zero Dependencies**: No external runtime dependenciesโjust pure, optimized JavaScript
|
|
23
|
+
- **๐จ Developer-Friendly**: TypeScript declarations included, intuitive API design, comprehensive documentation
|
|
24
|
+
|
|
25
|
+
## Use Cases
|
|
26
|
+
|
|
27
|
+
### 1. **Adaptive User Interfaces**
|
|
28
|
+
Dynamically adjust your UI based on device capabilities and screen properties:
|
|
29
|
+
```javascript
|
|
30
|
+
const info = await akiInfoDetect();
|
|
31
|
+
if (info.isMobile) {
|
|
32
|
+
// Load mobile-optimized components
|
|
33
|
+
loadMobileUI();
|
|
34
|
+
} else if (info.RAM < 4) {
|
|
35
|
+
// Use lightweight version for low-memory devices
|
|
36
|
+
enableLowMemoryMode();
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. **Analytics & User Insights**
|
|
41
|
+
Gather detailed technical data to understand your user base:
|
|
42
|
+
```javascript
|
|
43
|
+
const info = await akiInfoDetect();
|
|
44
|
+
analytics.track('page_view', {
|
|
45
|
+
browser: info.browser,
|
|
46
|
+
os: info.os.string,
|
|
47
|
+
device: info.isMobile ? 'mobile' : 'desktop',
|
|
48
|
+
gpu: info.GPU,
|
|
49
|
+
country: await info.getCountry()
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 3. **Feature Detection & Progressive Enhancement**
|
|
54
|
+
Enable or disable features based on browser capabilities:
|
|
55
|
+
```javascript
|
|
56
|
+
const info = await akiInfoDetect();
|
|
57
|
+
if (info.browser.includes('Chrome') && parseInt(info.browser.split(' ')[1]) >= 90) {
|
|
58
|
+
// Enable features requiring Chrome 90+
|
|
59
|
+
enableAdvancedFeatures();
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 4. **Platform-Specific Optimization**
|
|
64
|
+
Optimize content delivery based on hardware capabilities:
|
|
65
|
+
```javascript
|
|
66
|
+
const info = await akiInfoDetect();
|
|
67
|
+
if (info.CPU === 'Apple Silicon') {
|
|
68
|
+
// Load optimized assets for Apple Silicon
|
|
69
|
+
loadWebPImages();
|
|
70
|
+
} else if (info.GPU.includes('NVIDIA')) {
|
|
71
|
+
// Enable GPU-accelerated features
|
|
72
|
+
enableHardwareAcceleration();
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 5. **Targeted User Support**
|
|
77
|
+
Provide context-aware help and troubleshooting:
|
|
78
|
+
```javascript
|
|
79
|
+
const info = await akiInfoDetect();
|
|
80
|
+
if (info.browser.includes('Safari') && info.os.name === 'ios') {
|
|
81
|
+
showMessage('For best experience on iOS Safari, please enable...');
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 6. **Network-Aware Loading**
|
|
86
|
+
Adapt content loading strategies based on connection quality:
|
|
87
|
+
```javascript
|
|
88
|
+
const info = await akiInfoDetect();
|
|
89
|
+
const conn = info.getConnection();
|
|
90
|
+
if (conn.type === '4g' && conn.downlink > 5) {
|
|
91
|
+
// High-speed connection: load high-quality assets
|
|
92
|
+
loadHDContent();
|
|
93
|
+
} else {
|
|
94
|
+
// Optimize for slower connections
|
|
95
|
+
loadCompressedContent();
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Comparison with Similar Libraries
|
|
100
|
+
|
|
101
|
+
| Feature | aki-info-detect | Platform.js | UA-Parser.js | Detect.js |
|
|
102
|
+
|---------|----------------|-------------|--------------|-----------|
|
|
103
|
+
| **Bundle Size (gzipped)** | ~3.8 kB | ~2.5 kB | ~9 kB | Varies |
|
|
104
|
+
| **Client Hints API** | โ
Full Support | โ No | โ No | โ No |
|
|
105
|
+
| **GPU Detection** | โ
Yes | โ No | โ No | โ No |
|
|
106
|
+
| **Apple Silicon Detection** | โ
Yes (M1-MX) | โ No | โ No | โ No |
|
|
107
|
+
| **Network Info (IP/ISP)** | โ
Yes (cached) | โ No | โ No | โ No |
|
|
108
|
+
| **Battery Status** | โ
Yes | โ No | โ No | โ No |
|
|
109
|
+
| **Geolocation** | โ
Yes | โ No | โ No | โ No |
|
|
110
|
+
| **Tree-shakeable** | โ
Yes | โ ๏ธ Partial | โ ๏ธ Partial | โ ๏ธ Partial |
|
|
111
|
+
| **TypeScript** | โ
Full declarations | โ ๏ธ Community types | โ
Yes | โ No |
|
|
112
|
+
| **Active Maintenance** | โ
Yes | โ ๏ธ Sporadic | โ
Yes | โ Archived |
|
|
113
|
+
| **Modern Build System** | โ
Vite | โ Legacy | โ
Webpack | โ Legacy |
|
|
114
|
+
|
|
115
|
+
### Key Differentiators
|
|
116
|
+
|
|
117
|
+
**vs. Platform.js**
|
|
118
|
+
- aki-info-detect is a modern evolution with Client Hints API support for more accurate detection
|
|
119
|
+
- Adds hardware detection (GPU, RAM) and network capabilities not available in Platform.js
|
|
120
|
+
- Built with modern tooling (Vite) for better tree-shaking and optimization
|
|
121
|
+
|
|
122
|
+
**vs. UA-Parser.js**
|
|
123
|
+
- Lighter bundle size while providing more comprehensive information
|
|
124
|
+
- Includes hardware and network detection beyond just user agent parsing
|
|
125
|
+
- Native async/await support with modern API design
|
|
126
|
+
|
|
127
|
+
**vs. Detect.js**
|
|
128
|
+
- Active maintenance (Detect.js is archived)
|
|
129
|
+
- Smaller, more focused API surface with better performance
|
|
130
|
+
- Modern Web API integration for enhanced detection capabilities
|
|
131
|
+
|
|
132
|
+
## Frequently Asked Questions (FAQ)
|
|
133
|
+
|
|
134
|
+
### General Questions
|
|
135
|
+
|
|
136
|
+
**Q: What browsers does aki-info-detect support?**
|
|
137
|
+
A: All modern browsers with ES2020+ support: Chrome/Edge 89+, Firefox 88+, Safari 14+, Opera 76+. Client Hints features work best in Chromium-based browsers.
|
|
138
|
+
|
|
139
|
+
**Q: Does it work in Node.js or server-side environments?**
|
|
140
|
+
A: No, aki-info-detect is specifically designed for browser environments. It relies on browser APIs like `navigator`, `screen`, and Web APIs that are not available in Node.js.
|
|
141
|
+
|
|
142
|
+
**Q: How accurate is the detection?**
|
|
143
|
+
A: Very accurate for modern browsers that support Client Hints API. For browsers without Client Hints, it falls back to user agent parsing which is still reliable but less detailed. GPU and CPU detection is most accurate in Chromium-based browsers.
|
|
144
|
+
|
|
145
|
+
**Q: Is user agent string spoofing a concern?**
|
|
146
|
+
A: While user agents can be spoofed, Client Hints API provides more reliable detection. For critical functionality, always combine with feature detection rather than relying solely on browser/platform detection.
|
|
147
|
+
|
|
148
|
+
### Privacy & Security
|
|
149
|
+
|
|
150
|
+
**Q: Does aki-info-detect collect or transmit user data?**
|
|
151
|
+
A: No. The library only detects information locally in the browser. The optional network info feature (`getNetworkInfo()`) makes a request to a public IP API, but this is only triggered when you explicitly call that method.
|
|
152
|
+
|
|
153
|
+
**Q: What about user privacy?**
|
|
154
|
+
A: aki-info-detect is privacy-conscious. Network requests are cached for 1 hour to minimize external API calls, and all detection happens client-side. No data is sent to our servers.
|
|
155
|
+
|
|
156
|
+
**Q: Is it GDPR compliant?**
|
|
157
|
+
A: Detection of browser/device information is generally considered functional data necessary for website operation. However, always review your local regulations and privacy policies, especially when using geolocation or storing detected data.
|
|
158
|
+
|
|
159
|
+
### Technical Questions
|
|
160
|
+
|
|
161
|
+
**Q: Why do I need to configure server headers?**
|
|
162
|
+
A: The Client Hints API requires the server to explicitly request detailed information via `Accept-CH` headers. Without these headers, browsers will only provide basic user agent data. This is a browser security feature designed to enhance user privacy.
|
|
163
|
+
|
|
164
|
+
**Q: Can I use it with React, Vue, or other frameworks?**
|
|
165
|
+
A: Absolutely! aki-info-detect is framework-agnostic. See the React Hook and Vue Composable examples in the documentation for integration patterns.
|
|
166
|
+
|
|
167
|
+
**Q: How do I reduce bundle size further?**
|
|
168
|
+
A: Use tree-shakeable imports to include only the functions you need:
|
|
169
|
+
```javascript
|
|
170
|
+
import { detectBrowser, detectOS } from 'aki-info-detect';
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Q: Does it support TypeScript?**
|
|
174
|
+
A: Yes, full TypeScript declarations are included in the package.
|
|
175
|
+
|
|
176
|
+
**Q: How often is the network information cached?**
|
|
177
|
+
A: Network info (IP, ISP, country) is cached for 1 hour by default. You can force a refresh by passing `true` to `getNetworkInfo(true)`.
|
|
178
|
+
|
|
179
|
+
### Troubleshooting
|
|
180
|
+
|
|
181
|
+
**Q: Why am I getting generic hardware info?**
|
|
182
|
+
A: Make sure your server is configured to send the required `Accept-CH` headers. Without these headers, detailed Client Hints data won't be available.
|
|
183
|
+
|
|
184
|
+
**Q: Why is GPU detection returning "Unknown"?**
|
|
185
|
+
A: GPU detection works best in Chromium browsers with Client Hints. Safari and Firefox have limited support. Also, some browsers may restrict this information for privacy reasons.
|
|
186
|
+
|
|
187
|
+
**Q: The library says "Unknown" for many fields. What's wrong?**
|
|
188
|
+
A: Check browser console for errors, ensure you're using a supported browser version, and verify that your server is sending proper Client Hints headers (see Server Configuration section).
|
|
189
|
+
|
|
190
|
+
### Usage & Development
|
|
191
|
+
|
|
192
|
+
**Q: Can I contribute to the project?**
|
|
193
|
+
A: Yes! Contributions are welcome. Please check the GitHub repository for contribution guidelines.
|
|
194
|
+
|
|
195
|
+
**Q: How do I report a bug or request a feature?**
|
|
196
|
+
A: Open an issue on the [GitHub repository](https://github.com/lacvietanh/akiInfoDetect.js/issues) with details about the bug or feature request.
|
|
197
|
+
|
|
198
|
+
**Q: Is there a demo I can try?**
|
|
199
|
+
A: Yes! Visit the [live demo](https://akiinfodetect-js.pages.dev/) to see the library in action.
|
|
200
|
+
|
|
9
201
|
## Features
|
|
10
202
|
|
|
11
203
|
- ๐ **Browser Detection** โ Name, version, rendering engine
|
package/dist/aki-info-detect.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* aki-info-detect v2.0.
|
|
2
|
+
* aki-info-detect v2.0.2
|
|
3
3
|
* (c) 2025 lacvietanh
|
|
4
4
|
* Released under the MIT License
|
|
5
|
-
* https://
|
|
5
|
+
* https://akiinfodetect-js.pages.dev/
|
|
6
6
|
*/
|
|
7
7
|
function parseUserAgent(ua = navigator.userAgent) {
|
|
8
8
|
let os = null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).akiInfoDetect={})}(this,function(e){"use strict";
|
|
2
2
|
/*!
|
|
3
|
-
* aki-info-detect v2.0.
|
|
3
|
+
* aki-info-detect v2.0.2
|
|
4
4
|
* (c) 2025 lacvietanh
|
|
5
5
|
* Released under the MIT License
|
|
6
|
-
* https://
|
|
6
|
+
* https://akiinfodetect-js.pages.dev/
|
|
7
7
|
*/function t(e=navigator.userAgent){let t=null,n="",r="",i="",o="";const a=[{test:/Edg(?:e)?\//,name:"Edge",regex:/Edg(?:e)?\/([\d.]+)/},{test:/OPR\/|Opera\//,name:"Opera",regex:/(?:OPR|Opera)\/([\d.]+)/},{test:/Firefox\//,name:"Firefox",regex:/Firefox\/([\d.]+)/,exclude:/Seamonkey/},{test:/Chrome\//,name:"Chrome",regex:/Chrome\/([\d.]+)/,exclude:/Edge|Edg|OPR|Opera/},{test:/Safari\//,name:"Safari",regex:/Version\/([\d.]+)/,exclude:/Chrome|Edge|Edg|OPR|Opera/},{test:/MSIE|Trident/,name:"IE",regex:/(?:MSIE |rv:)([\d.]+)/}];for(const{test:c,name:u,regex:l,exclude:d}of a)if(c.test(e)&&(!d||!d.test(e))){n=u;const t=e.match(l);r=(null==t?void 0:t[1])||"";break}const s=[{test:/Windows/,parse:()=>{const t=e.match(/Windows NT ([\d.]+)/),n=(null==t?void 0:t[1])||"",r={"10.0":"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.1:"XP"}[n]||n;return{family:`Windows ${r}`,version:r,architecture:/WOW64|Win64|x64/.test(e)?64:32}}},{test:/Mac OS X/,parse:()=>{var t;const n=e.match(/Mac OS X ([\d_.]+)/),r=(null==(t=null==n?void 0:n[1])?void 0:t.replace(/_/g,"."))||"";return{family:`macOS ${r}`,version:r,architecture:64}}},{test:/Android/,parse:()=>{const t=e.match(/Android ([\d.]+)/),n=(null==t?void 0:t[1])||"";return{family:`Android ${n}`,version:n,architecture:64}}},{test:/iPhone|iPad|iPod/,parse:()=>{var t;const n=e.match(/OS ([\d_]+)/),r=(null==(t=null==n?void 0:n[1])?void 0:t.replace(/_/g,"."))||"";return{family:`iOS ${r}`,version:r,architecture:64}}},{test:/Linux/,parse:()=>({family:"Linux",version:"",architecture:/x86_64|amd64/.test(e)?64:32})}];for(const{test:c,parse:u}of s)if(c.test(e)){t=u();break}if(/iPhone/.test(e))i="iPhone",o="Apple";else if(/iPad/.test(e))i="iPad",o="Apple";else if(/Android/.test(e)){const t=e.match(/Android[^;]+;\s*([^;)]+)/);if(t){i=t[1].trim();const e=i.match(/^(Samsung|LG|Motorola|HTC|Huawei|Xiaomi|OnePlus|Google|Sony|OPPO|Vivo|Realme)/i);o=(null==e?void 0:e[1])||""}}return{name:n,version:r,product:i,manufacturer:o,os:t,layout:/AppleWebKit/.test(e)?"WebKit":/Gecko\//.test(e)?"Gecko":/Trident/.test(e)?"Trident":""}}async function n(){var e;if(!(null==(e=navigator.userAgentData)?void 0:e.getHighEntropyValues))return{};try{return await navigator.userAgentData.getHighEntropyValues(["platform","platformVersion","architecture","model","mobile","bitness","brands","fullVersionList"])}catch{return{}}}function r(){try{const e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");if(!t)return"No WebGL support";const n=t.getExtension("WEBGL_debug_renderer_info");return n?t.getParameter(n.UNMASKED_RENDERER_WEBGL)||"Unknown GPU":"GPU info restricted"}catch{return"GPU detection failed"}}const i={IP:"",ISP:"",country:"",lastUpdated:0,TTL:36e5};async function o(e,t=2500){const n=new AbortController,r=setTimeout(()=>n.abort(),t);try{const t=await fetch(e,{signal:n.signal});return clearTimeout(r),t.ok?await t.json():null}catch{return clearTimeout(r),null}}async function a(e=!1){if(!e&&i.IP&&Date.now()-i.lastUpdated<i.TTL)return{IP:i.IP,ISP:i.ISP,country:i.country};const t=[{url:"https://ipinfo.io/json",parse:e=>({IP:e.ip,ISP:e.org||"",country:e.country||""})},{url:"https://ipwhois.app/json/",parse:e=>({IP:e.ip,ISP:e.isp||"",country:e.country_code||""})},{url:"https://api.ipify.org?format=json",parse:e=>({IP:e.ip,ISP:"",country:""})}];for(const{url:n,parse:r}of t){const e=await o(n);if(e){const t=r(e);if(t.IP)return i.IP=t.IP,i.ISP=t.ISP||i.ISP,i.country=t.country||i.country,i.lastUpdated=Date.now(),t}}return{IP:i.IP,ISP:i.ISP,country:i.country}}async function s(e=!1){return(await a(e)).IP}async function c(e=!1){return(await a(e)).ISP}async function u(e=!1){return(await a(e)).country}function l(){const e=navigator.connection||navigator.mozConnection||navigator.webkitConnection;return e?{type:e.type||"unknown",effectiveType:e.effectiveType||"unknown",downlink:e.downlink||0,rtt:e.rtt||0,saveData:e.saveData||!1}:null}function d(e={timeout:1e4,enableHighAccuracy:!1}){return new Promise(t=>{navigator.geolocation?navigator.geolocation.getCurrentPosition(e=>t({latitude:e.coords.latitude,longitude:e.coords.longitude,accuracy:e.coords.accuracy,timestamp:e.timestamp}),()=>t(null),e):t(null)})}const g=i;function m(){var e;const{screen:t}=window;return{width:t.width,height:t.height,availWidth:t.availWidth,availHeight:t.availHeight,colorDepth:t.colorDepth,pixelRatio:window.devicePixelRatio||1,orientation:(null==(e=t.orientation)?void 0:e.type)||(window.innerWidth>window.innerHeight?"landscape-primary":"portrait-primary")}}async function p(){if(!("getBattery"in navigator))return{isCharging:!1,level:0,chargingTime:1/0,dischargingTime:1/0};try{const e=await navigator.getBattery();return{isCharging:e.charging,level:Math.round(100*e.level),chargingTime:e.chargingTime,dischargingTime:e.dischargingTime}}catch{return{isCharging:!1,level:0,chargingTime:1/0,dischargingTime:1/0}}}
|
|
8
8
|
/**
|
|
9
9
|
* @fileoverview aki-info-detect - Browser information detection library
|