Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

68 lines (44 sloc) 2.094 kb

ua-parser

ua-parser is a port to node.js and python of BrowserScope's user agent string parser.

The crux of the original parser--the data collected by Steve Souders over the years--has been extracted into a separate YAML file so as to be reusable as is by implementations in other programming languages.

ua-parser is just a small wrapper around this data.

Usage

var uaParser = require('ua-parser');
var ua = uaParser.parse(navigator.userAgent);

console.log(ua.tostring());
// -> "Safari 5.0.1"

console.log(ua.toVersionString());
// -> "5.0.1"

console.log(ua.family);
// -> "Safari"

console.log(ua.major);
// -> 5

console.log(ua.minor);
// -> 0

console.log(ua.patch);
// -> 1

Usage :: python

# Python won't do with dashes in module names so you'll need to rename
# this directory. i.e. mv ua-parser ua_parser
from ua_parser.py import user_agent_parser

# On the server, let's say you have a WebOB request object.
user_agent_string = request.META.get('HTTP_USER_AGENT')
family, v1, v2, v3 = user_agent_parser.Parse(user_agent_string)

License

The data contained in regexes.yaml is Copyright 2009 Google Inc. and available under the Apache License, Version 2.0.

The original python code is Copyright 2008 Google Inc. and is available under the Apache License, Version 2.0.

The JS port is Copyright 2010 Tobie Langel and is available under your choice of MIT or Apache Version 2.0 license.

The PHP port is Copyright (c) 2011-2012 Dave Olsen and is available under the MIT license.

Jump to Line
Something went wrong with that request. Please try again.