https://github.com/sudongyuer/info-js
https://github.com/sudongyuer/info-js
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sudongyuer/info-js
- Owner: sudongyuer
- Created: 2021-09-21T07:37:40.000Z (about 4 years ago)
- Default Branch: dev
- Last Pushed: 2022-08-29T17:23:11.000Z (about 3 years ago)
- Last Synced: 2025-04-08T08:21:15.359Z (6 months ago)
- Language: TypeScript
- Size: 490 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# InfoJs ⚡
github:https://github.com/sudongyuer/info-js
更方便的获取客户端信息

## 声明
这个库是我在公司编写的,所以是属于imf团队,为了方便大家使用我将包发布到了我的npm仓库
## Install 💡
```shell
npm install sudongyu-info-js --savenpm install sudongyu-infojs-plugin --save-dev
or
yarn add sudongyu-info-js
yarn add sudongyu-infojs-plugin --dev
```## Useage 🌲
###
**step1: 配置vite插件**```ts
//在vite.config.js中进行配置
//引入我们安装的vite插件
import infoJsPlugin from 'sudongyu-infojs-plugin'
export default defineConfig({
plugins: [vue(),infoJsPlugin()],
//优化包依赖
optimizeDeps:{
//!!!在这里排除我们插件生成的虚拟路径
exclude:['@infoJs-plugin-virtual-module']
}
})```
**step2: 使用极其方便,并且在任意地方都可以使用**
```ts
import 'sudongyu-info-js'//仅需在main.ts导入即可
```tips:完成导入后,所有的信息对象都会被注入到window对象上
## API 🍉
### Window
```typescript
window.browserInfo : BrowserInfo
window.browserExtension : BrowserExtension
```### BrowserExtension (Writable/Readable)
| key | value | 解释 |
| :-----| ----: | :----: |
| language | zh-cn |客户端当前浏览器语言 |### BrowserInfo (OnlyRead)
| key | value | 解释 |
| :-----| ----: | :----: |
| screenResolution | 1080*1920 | 客户端浏览器的分辨率 |
| isMobileDevice | false| 客户端是否为移动设备 |
| userAgent | MacIntel | 客户度浏览器 |
| appPackageName | vue-demo-web | app包名 |
| appVersion |5.0 (Macintosh; Intel Mac OS X 10_15_7)...| 客户端浏览器的平台和版本信息 |
| appVersionCode | 1.0.1 | app版本号 |
| platform | MacIntel | 客户端运行浏览器的操作系统平台 |
| appIpAddress | 2409:8a62:810:93f0:1dd4:52b4:ab29:d752 | 客户端ip地址 |
| appIpCountry | CN | 客户端ip所在地理位置 |
| appMode | beta|prod | App的运行环境 |
| viteMode | development|build | App的运行环境 |
| client | ClientInfo | 客户端信息对象 |### window.browserInfo.client
```
window.browserInfo.client : ClientInfo
```
| key | 解释 |
| :-----| :----: |
| packageName | 客户端包名 |
| appVersionCode | 客户端版本号 |
| appVersionName | 客户端版本名称 |
| platform | 客户端平台 |
| platformVersion | 客户端平台版本号 |
| deviceId | 客户端设备Id |
| deviceBrand | 客户端设备品牌 |### example 📦
```ts
console.log(window.browserInfo.platform)//MacIntel
console.log(window.browserInfo.screenResolution)//1440*900
console.log(window.browserInfo.client)// a Object ^_^
console.log(window.browserInfo.isMobileDevice)// false
console.log(window.browserInfo.appIpAddress)//2409:8a62:810:93f0:1dd4:52b4:ab29:d752
console.log(window.browserInfo.appIpCountry)//CN
console.log(window.browserInfo.appMode)//beta
console.log(window.browserInfo.appPackageName)//vue-demo-web
console.log(window.browserInfo.appVersionCode)//1.0.0
......console.log(window.browserExtension.language)//zh-cn
window.browserExtension.language='zh-cn'//set language
```
## Future 🛠️已完成:✅ 未完成:❌
* 应用版本号 ✅
* 浏览器指纹 ❌
* 用户ip地址 ✅
* 用户所在国家 ✅
* 项目运行的环境类型(prod beat )✅