• Stars
    star
    884
  • Rank 51,646 (Top 2 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🐶 客户端环境识别模块。(UserAgent detector)

detector


NPM version Build Status Coverage Status

中文文档

Client information detector by user agent, detect information include:

  1. Device.
  2. Operation System (OS).
  3. Browser.
  4. Rendering Engine.

Detected information is a "detector object", data structure like:

detector = {
    device: {
        name: "iphone",
        version: -1,
        fullVersion: "-1",
        [iphone]: -1
    },
    os: {
        name: "ios",
        version: 6.1,
        fullVersion: "6.1",
        [ios]: 6.1
    },
    browser: {
        name: "chrome":
        version: 26.0,
        fullVersion: "26.0.1410.50",
        mode: 26.0,
        fullMode: "26.0.1410.50",
        compatible: false,
        [chrome]: 26.0
    },
    engine: {
        name: "webkit",
        version: 536.26,
        fullVersion: "536.26",
        mode: 523.26,
        fullMode: "523.26",
        compatible: false,
        [webkit]: 536.26
    }
}

Note: Above [iphone], [ios], [chrome], [webkit] is dynamically from actual environment, different device, operation system, browser and rendering engine is different.

Note:

  • This version of detector's code is follow CommonJS sepcification, and support NodeJS and Web Browser environment at the same time.
  • Some times, you just need simple detect a litter information, please reference to #18, without detector.

Installation

via npm:

Installation to global (with -g argument), you can use detector command in terminal.

npm install detector [-g]

Usage

for Web Browser

Some examples in common use:

// import detector, variable detector is "detector object".
const detector = require('detector');

// Detect browser name.
detector.browser.name === "chrome" // true

// An other example for detect browser name.
!!detector.browser.ie // false

// Detect the old browseres.
if(detector.browser.ie && detector.browser.version < 8){
    alert("You browser is too old.");
}

// Detect rendering engine below Trident 4 (IE8).
if(detector.engine.trident && detector.engine.mode < 4){
    // hack code.
}

// Collect client detail informations.
detector.browser.name + "/" + detector.browser.fullVersion;

for Node.js

const detector = require('detector');

// variable `d` is a "detector object"
const d = detector.parse(userAgent);
d.browser.name === "chrome";

API

{String} detector.device.name

Name of hardware device.

{Number} detector.device.version

Version of hardware device.

{String} detector.device.fullVersion

Full version of hardware device.

{Number} detector.device[device_name]

Detect name of hardware device.

Support hardware devices:

  • pc: Windows PC.
  • mac: Macintosh PC.
  • iphone: iPhone.
  • ipad: iPad.
  • ipod: iPod.
  • android: Android.
  • blackberry: Blackberry mobile.
  • wp: Windows Phone.
  • mi: Xiaomi.
  • meizu: meizu.
  • nexus: Nexus.
  • nokia: Nokia.
  • samsung: samsung.
  • aliyun: Aliyun.
  • huawei: Huawei (华为)
  • lenovo: lenovo.
  • zte: ZTE Corporation (中兴)
  • vivo: vivo (步步高)
  • htc: HTC.
  • oppo: OPPO.
  • konka: konka (康佳)
  • sonyericsson: sonyericsson (索尼爱立信)
  • coolpad: coolpad (酷派)
  • lg: LG.
NODE ONLY

Following hardware device support in NodeJS version of detector:

  • noain: 诺亚信
  • huawei-honor: 华为荣耀
  • lephone: 乐 Phone
  • asus: 华硕
  • alcatel
  • 一加
  • 蓝米
  • E 派
  • hike
  • qmi
  • 友信达: 友信达
  • 优米
  • 嘉源
  • intki
  • 星语
  • 欧奇
  • 海派
  • 广信: 广信
  • nibiru: nibiru
  • 神州
  • 青橙
  • 海信
  • 金立
  • eton
  • bohp
  • 小杨树
  • 语信
  • nubia
  • 爱讯达
  • 寰宇通
  • mofut
  • infocus
  • 大唐
  • 邦华
  • 天迈
  • 大显
  • 博瑞
  • lingwin
  • iusai
  • 波导
  • 德赛
  • 蓝魔
  • 美图
  • opsson
  • benwee
  • hosin
  • smartisan: 锤子, Smartisan.
  • ephone
  • 佰事讯
  • newman
  • konka
  • haier
  • moto
  • tcl
  • 天语
  • doov
  • 天时达

{String} detector.os.name

Name of operation system.

{Number} detector.os.version

Version of operation system.

{String} detector.os.fullVersion

Full version of operation system.

{Number} detector.os[os_name]

Detect name of operation system.

Support operation system list:

  • windows: Windows.
  • macosx: Macintosh.
  • ios: iOS.
  • android: Android.
  • chromeos: Chrome OS.
  • linux: Linux.
  • wp: Windows Phone.
  • windowsce: Windows CE, include Windows Mobile, Smartphone, PPC.
  • symbian: Symbian OS.
  • blackberry: Blackberry OS.
  • yunos: Aliyun OS.
NODE ONLY

Following operation system support in NodeJS version of detector:

  • meego: Meego.
  • smartisan: Smartisan.

{String} detector.browser.name

Name of browser.

{Number} detector.browser.version

Real version of browser.

In compatibility-mode, Internet Explorer declare it is a old browser. but detector.browser.version return the real version of browser.

For example:

IE9 declare it is a IE7 in compatibility-mode, but detector.browser.version return 9.0.

{String} detector.browser.fullVersion

Full (real) version of browser.

{Number} detector.browser.mode

Browser-mode. In Internet Explorer's compatibility-mode, version and mode is different.

{String} detector.browser.fullMode

Full mode of browser.

{Number} detector.browser[browser_name]

Detect name of browser.

Support browser list:

  • edge: Microsoft Edge browser.
  • ie: Microsoft Internet Explorer.
  • chrome: Google Chrome.
  • firefox: Mozilla Firefox.
  • safari: Apple Safari.
  • opera: Opera.
  • 360: Qihu 360 browser.
  • maxthon: Maxthon.
  • sogou: Sogou.
  • theworld: TheWorld.
  • green: GreenBrowser.
  • qq: QQ Browser.
  • tt: TencentTraveler.
  • liebao: Cheetah Mobile Inc. (猎豹) Browser.
  • tao: Taobao (淘宝) Browser.
  • coolnovo: coolnovo (枫树)
  • saayaa: Saayaa (闪游)
  • uc: UC Browser.
  • mi: Build-in browser in Xiaomi (小米).
  • baidu: Baidu (百度) browser.
  • nokia: Build-in Browser in Nokia (诺基亚)
  • blackberry: 黑莓默认浏览器,版本号与系统版本相同。
  • webview: iOS WebView.
  • yandex: Yandex YaBrowser.
  • micromessenger WeChat (微信)
  • ali-ap: 支付宝手机钱包。
  • ali-ap-pd: 支付宝平板客户端。
  • ali-am: 支付宝商户客户端。
  • ali-tb: 淘宝手机客户端。
  • ali-tb-pd: 淘宝平板客户端。
  • ali-tm: 天猫手机客户端。
  • ali-tm-pd: 天猫平板客户端。
NODE ONLY
  • googlebot: Googlebot
  • baiduspider: Baiduspider ,百度无线、网页搜索
  • baiduspider-image: 百度图片搜索
  • baiduspider-video: 百度视频搜索
  • baiduspider-news: 百度新闻搜索
  • baiduspider-favo: 百度收藏搜索
  • baiduspider-cpro: 百度联盟
  • baiduspider-ads: 百度商务搜索
  • baiduboxapp: 百度手机搜索客户端
  • bingbot: Bingbot 网络爬虫。
  • msnbot: MSNBot
  • nuhkbot: Nuhkbot
  • alexabot: Alexabot.
  • curl: curl.
  • slurpbot: Yahoo! Slurp

{Boolean} detector.browser.compatible

Judge is browser in compatibility-mode.


{String} detector.engine.name

Name of rendering engine.

{Number} detector.engine.version

Version of rendering engine.

{String} detector.engine.fullVersion

Full version of rendering engine.

{Number} detector.engine.mode

Mode of rendering engine.

{String} detector.engine.fullMode

Full-mode of rendering engine.

{Number} detector.engine[engine_name]

Detect name of rendering engine.

Support rendering engine list:

  • edgehtml: Microsoft Edge browser's rendering engine. (Note: version same browser version now.)
  • trident: Microsoft Trident.
  • blink: Google Blink.
  • webkit: Apple Webkit.
  • gecko: Mozilla Gecko.
  • presto: Opera Presto.
  • androidwebkit: Android Webkit.
  • coolpadwebkit: Coolpad Webkit.
  • u2: UC browser rendering engine v2.
  • u3: UC browser rendering engine v3.

{detector} detector.parse(String ua)

Parse user agent string, return a detector object.


Not Available information:

  • Not Available name will be na.
  • Not Available version will be -1.

Releases

https://github.com/hotoo/detector/tree/gh-pages

More Repositories

1

pinyin

🇨🇳 汉字拼音 ➜ hàn zì pīn yīn
JavaScript
7,048
star
2

pangu.vim

『盘古之白』中文排版自动规范化的 Vim 插件
Vim Script
328
star
3

markline

Ⓜ️ Timeline via Markdown.
JavaScript
162
star
4

nong

中国农历 (Nong Li)
JavaScript
129
star
5

rime

闲耘的 rime 输入法配置
Makefile
98
star
6

gitlab-notifications

👍 Notifications Center for GitLab
58
star
7

gitplus

🔀 git+ is a hack of git, smart for you.
JavaScript
57
star
8

gitopen

🔀 Open git/hg/svn remote url via web browser from terminal.
JavaScript
43
star
9

obsidian-markline

Markline: Markdown timeline view in Obsidian.
TypeScript
24
star
10

unistring

Unicode String for JavaScript
TypeScript
23
star
11

template.vim

Smart load template for Vim.
Vim Script
18
star
12

rm-trash

rm-trash is utility for safely remove files in Termail.app of macOS.
Shell
18
star
13

hongbao

叫花不理红包
18
star
14

vim-desktop-calendar

Printable Vim desktop Calendar 2024
17
star
15

versioning

Semantic Versioning Number Compare
JavaScript
14
star
16

lcal

lcal: 农历事件自动生成器 (Lunar Calender)
JavaScript
12
star
17

jsgf.vim

Improved `gf` for JavaScript, TypeScript and package.json.
Vim Script
11
star
18

hotoo.github.io

HTML
11
star
19

vimlide

Vimlide: Vim-like HTML(5) Slide.
JavaScript
10
star
20

chrommon.js

A Module Loader for Google Chrome Extensions.
JavaScript
9
star
21

url

Uniform Resource Locator.
JavaScript
9
star
22

Vimmer

Vim user contact list.
8
star
23

star

Star
JavaScript
7
star
24

vimwiki-to-markdown

Convert Vimwiki to Markdown
JavaScript
7
star
25

apassword

移动端密码控件
JavaScript
7
star
26

spm-build-deps

Build project all deps
JavaScript
7
star
27

jstidy

Javascript tidy (Lexical analysis, Syntax Analysis, Semantic Analysis, Formatter, Compression, Outline view)
C++
7
star
28

kissy-editor

KISSY Rich-Text Editor
JavaScript
6
star
29

vimkey

Vim-like key mapping
JavaScript
6
star
30

Edit-with-Vim-tabs

Edit with Vim tabs
6
star
31

perf-javascript-error

Performance test for JavaScript Error.
JavaScript
5
star
32

jobs

🐜 蚂蚁集团・数字金融技术部招聘
5
star
33

markdown.vim

5
star
34

rhythmaware

节奏感知器:根据用户的输入速度自动感知停顿状态。
JavaScript
5
star
35

eggjs-gf.vim

goto file for eggjs( support router, controllers, services, proxy, enums)
Vim Script
4
star
36

round-percent

Round Percent Widget
JavaScript
4
star
37

BaiduIndexAPI.java

第三方百度指数 API (Java版)
Java
4
star
38

js2json

Convert JavaScript Object to JSON format.
JavaScript
4
star
39

smartree

Smart Tree
JavaScript
4
star
40

blog

 · 闲耘™・博客
JavaScript
3
star
41

jsonmatter

JSON formatter tool by stream.
JavaScript
3
star
42

orderby

SQL like sort function.
JavaScript
3
star
43

blacklint

Check certain words.
Shell
3
star
44

highlight-cursor-word.vim

Highlight words which under text-cursor(caret) for Vim.
Vim Script
3
star
45

echo

Echo for Web UI, a replicator.
JavaScript
3
star
46

life

@hotoo's life line. A sample for use [markline](https://github.com/hotoo/markline).
Makefile
3
star
47

hundun

盘古之白,浑沌之初。
JavaScript
3
star
48

csspretty.vim

Vim Script
3
star
49

gitruth

Clean Git Files Forever.
Shell
3
star
50

firebug-lite-ie

Firebug Lite for IE.
3
star
51

chinese-lunar-calendar

中国农历
3
star
52

gaegtalk

基于gae和gtalk群聊服务
Python
2
star
53

Jumsoft-Money-zh_CN.lproj

Jumsoft Money 简体中文语言包。
2
star
54

Doit.vim

Vim plugin for Doit.im
2
star
55

fastclone

The fast clone way
JavaScript
2
star
56

linkage

无限级联动
JavaScript
2
star
57

seajs-gettext

GNU `gettext` like for seajs.
JavaScript
2
star
58

hotoo

1
star
59

scripts

很久之前在 Google Code 上备份的代码
JavaScript
1
star
60

.gitblacklist

Check and Reject certain words commit into git repository.
Shell
1
star
61

Chronos

Sync Server and Client Time by Javascript.
JavaScript
1
star
62

pasteboard

批量粘贴通用解决方案。
JavaScript
1
star
63

BaiduIndexAPI.php

第三方百度指数 API (PHP版)
1
star
64

imagic

Imagic send data by image, for tests mock.
JavaScript
1
star
65

samoyed

The samoyed life timeline who named Summer.
Makefile
1
star
66

open-basketball-court

开放篮球场地标工程
1
star
67

jquery.mousepause.js

Add mousepause event for jQuery (trigger when mouse move stoped).
JavaScript
1
star
68

jquery.editable.js

JavaScript
1
star
69

spm-xgettext

GUN xgettext-like for spm.
JavaScript
1
star
70

family-tree-builder-zh_cn

Family Tree Builder 简体中文语言包
1
star
71

tabbar

TabBar
JavaScript
1
star
72

jquery.checkallable.js

支持Checkbox 和 Radio,及 shiftKey 多选功能。
JavaScript
1
star
73

twitter

@hotoo tweets page.
JavaScript
1
star
74

.n-completion

n completion
1
star
75

repeatable

之前写的『可重复新增』模块,后来写了全新的 Echo,这个模块闲置没管,因为换电脑先备份在这。
JavaScript
1
star
76

Snotra

Vim-like WYSIWYG Web Editor
1
star
77

jsbc

JavaScript code Batch Compiler
JavaScript
1
star