• Stars
    star
    643
  • Rank 70,000 (Top 2 %)
  • Language
    JavaScript
  • Created over 12 years ago
  • Updated almost 2 years ago

Reviews

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

Repository Details

๐Ÿ” Library to detect browser, os and device based on the UserAgent String

Detect.js

Note: Detect.js is a JavaScript library to detect platforms, versions, manufacturers and types based on the navigator.userAgent string. This code is based on, and modified from, the original work of Tobie Langel's UA-Parser: https://github.com/tobie/ua-parser. UA-Parser is subsequently a port of BrowserScope's user agent string parser.

As initially touted, the biggest contribution to this code is the work of Steve Souders and the list of regex tests.

Features

  • User-Agent parsing (obviously)
  • AMD/Common.js support
  • device, os and browser detection of:
    • name
    • family
    • version
    • major
    • minor
    • patch
    • device supports: manufacturer and type as well
  • Custom regex builds using node.js

Creating a Custom Build

Creating a custom build of the regex profiles will help reduce file size and is strongly recommended. The default detect.js and detect.min.js files include all regex profiles and is therefor much larger then, I'm sure, your needs.

  1. Install Node.js: https://github.com/joyent/node/wiki/Installation
  2. Edit build/config.js with you're preferred oss, devices and browsers
  3. Run node build/build.js --input=build/detect.js --output=build/detect.custom.js
  4. The build script should create a custom version of Detect.js at build/detect.custom.js

Example Use

Plain JS:

<script src="detect.js"></script>
/*
iPhone 4 Example User Agent:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
*/

var ua = detect.parse(navigator.userAgent);

ua.browser.family // "Mobile Safari"
ua.browser.name // "Mobile Safari 4.0.5"
ua.browser.version // "4.0.5"
ua.browser.major // 4
ua.browser.minor // 0
ua.browser.patch // 5

ua.device.family // "iPhone"
ua.device.name // "iPhone"
ua.device.version // ""
ua.device.major // null
ua.device.minor // null
ua.device.patch // null
ua.device.type // "Mobile"
ua.device.manufacturer // "Apple"

ua.os.family // "iOS"
ua.os.name // "iOS 4"
ua.os.version // "4"
ua.os.major // 4
ua.os.minor // 0
ua.os.patch // null

Common.js:

var detect = require('detect');
var ua = detect.parse(navigator.userAgent);
...

Hacking

  • Install development dependencies using npm install.
  • Install the pre-commit hook by running hooks/install.sh.
  • Kick off the default build (which will generate detect.js and detect.min.js) with npm start.

Credits

Thanks to Adriano Cahetรฉ and Julian

Licensing

  • Some data contained in build/regexes.js is Copyright 2009 Google Inc. and available under the Apache License, Version 2.0.
  • All other code is licensed under a Dual MIT and GPL licence

More Repositories

1

Repo.js

๐Ÿ“„ A plugin to embed Github repos on your site
912
star
2

rawkit

๐ŸฆŠ Immediately Open Chrome DevTools when debugging Node.js apps
JavaScript
320
star
3

Watch.js

๐Ÿ‘€ Watches elements for changes in properties and attributes
JavaScript
130
star
4

jQuery-Fullscreen-Plugin

A full suite fullscreen plugin with fallback support
JavaScript
25
star
5

WordPress-Deploy-Sync

๐Ÿšš A WordPress Deployment/Syncing workflow that doesn't kill braincells
JavaScript
17
star
6

octofiles

โฌ†๏ธ Browser Extension to easily upload files to the cloud using GitHub
JavaScript
15
star
7

sleepover

๐Ÿ’ค Sleep, snooze & step methods
JavaScript
14
star
8

jQuery-TypeOut-Plugin

A plugin to sequentially type out an elements text like a ghost . Similar to old news tickers.
JavaScript
9
star
9

is-ship-stuck

Is the ship stuck still?
JavaScript
8
star
10

jQuery-Animate-Auto-Plugin

๐Ÿš A lightweight jQuery plugin that allows you to animate "auto" values
JavaScript
8
star
11

github-activity-extension

:octocat: Toggle display of noisy activity notifications in issue & PR threads
JavaScript
8
star
12

pet-a-day-action

Change your GitHub/Gravatar photo to a different cute animal each day...
JavaScript
7
star
13

javascripting-golf

โ›ณ๏ธ Solving NodeSchool's "javascripting" workshopper with the least amount of code
JavaScript
6
star
14

thoughts

๐Ÿ’ญ Thoughts on development, design, news etc..
5
star
15

minargs

minimal argument parsing - bring your own validationโ„ข๏ธ
JavaScript
5
star
16

jQuery-Sort-Grid-Plugin

A lightweight jQuery plugin that lets you animate/sort elements
JavaScript
5
star
17

Refined-Azure

๐Ÿ—ป A clean theme for the Azure Portal (web extension)
CSS
5
star
18

Space-Apps

๐ŸŒŽ Team TWG's Space Apps Project
Objective-C
4
star
19

torontojs-workshop

๐Ÿšœ Fun with canvas
JavaScript
4
star
20

iso-theme

๐Ÿš€ An Isomorphic JavaScript WordPress Theme utilizing Node.js and Express on a LAMP stack
HTML
4
star
21

faq

Frequently Asked Questions
3
star
22

jQuery-Flickr-Video-Plugin

A plugin to generate a flickr video from a url
JavaScript
3
star
23

darcy

๐Ÿ‘ค all my info, centralized in one place
JavaScript
3
star
24

jQuery-Flickr-Photo-Plugin

A plugin to generate a flickr photo froma url
JavaScript
3
star
25

minargs-cli

cli for the minimum viable argument parser
JavaScript
2
star
26

gh-testing

JavaScript
2
star
27

solving-monty-hall

Some code to show probablities for the "Monty Hall Problem"
JavaScript
2
star
28

jQuery-Flickr-Gallery-Plugin

A plugin to generate a flickr gallery from a set url
JavaScript
2
star
29

W3C-Mailing-List-Extension

๐Ÿ“ซ A Chrome Extension to Update the look and feel of the W3C Mailing List Archives
JavaScript
2
star
30

npm-offline-cache

๐Ÿ“ฆ An example of how to set up npm to point to a local project's cached/mirrored deps
JavaScript
2
star
31

darcyclarke

:octocat: Global stuffs
2
star
32

semver-typescript

2
star
33

jamming-with-npm

A static site... to showcase npm hooks + netfliy
HTML
1
star
34

react-insta-feed

Instagram Feed in React
JavaScript
1
star
35

npm-optional-peer-deps

1
star
36

NodeSchool-CLI

NodeSchool CLI - As defined in: https://github.com/nodeschool/toronto/issues/68
1
star
37

Boilerplate

My project boilerplate
CSS
1
star
38

github-improved-textarea

Simple set of improvements for the GitHub textarea inputs
1
star
39

npm-update-latest-windows-repro

1
star
40

dotfiles

1
star
41

npm-workspaces-ci

Example CI setup for npm workspace project
1
star
42

Set-Rectangle-Sketch-Plugin

๐Ÿ”ณ A Sketch Plugin for setting default dimensions on creation of rectangle
JavaScript
1
star