mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Change license paragraph in readme from GPL2 to MIT
This commit is contained in:
parent
eaacb14ef2
commit
ac1f92d3c6
@ -1,7 +1,7 @@
|
||||
{
|
||||
"title": "UA-Parser.js",
|
||||
"title": "UA-Parser.JS",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
|
43
readme.md
43
readme.md
@ -1,6 +1,6 @@
|
||||
# UA-Parser.js
|
||||
# UA-Parser.JS
|
||||
|
||||
Light-weight JavaScript-based all-in-one user-agent parser
|
||||
Lightweight JavaScript-based User-Agent string parser
|
||||
|
||||
* Author : Faisalman <<fyzlman@gmail.com>>
|
||||
* Home : http://faisalman.github.com/ua-parser-js
|
||||
@ -9,14 +9,15 @@ Light-weight JavaScript-based all-in-one user-agent parser
|
||||
|
||||
## Features
|
||||
|
||||
Get detailed type and version of web browser, layout engine, operating system, and device.
|
||||
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string.
|
||||
|
||||
## Methods
|
||||
|
||||
* `getBrowser([uastring])`
|
||||
* `getDevice([uastring])`
|
||||
* `getEngine([uastring])`
|
||||
* `getOS([uastring])`
|
||||
* `getBrowser()`
|
||||
* `getDevice()`
|
||||
* `getEngine()`
|
||||
* `getOS()`
|
||||
* `getUA()`
|
||||
* `setUA(uastring)`
|
||||
|
||||
## Properties
|
||||
@ -31,7 +32,7 @@ Get detailed type and version of web browser, layout engine, operating system, a
|
||||
|
||||
var parser = new UAParser();
|
||||
|
||||
// by default it takes ua string from current browser's window.navigator
|
||||
// by default it takes ua string from current browser's window.navigator.userAgent
|
||||
console.log(parser.result);
|
||||
/*
|
||||
/// this will print an object structured like this:
|
||||
@ -77,23 +78,23 @@ var parser = new UAParser();
|
||||
var ua1 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11';
|
||||
var ua2 = 'Midori/0.2 (X11; Linux; U; cs-cz) WebKit/531.2+';
|
||||
|
||||
parser.setUA(ua1).getDevice().name; // "PlayBook"
|
||||
parser.getOS() // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||
parser.getOS(ua2) // {name: "Linux", version: undefined}
|
||||
parser.getOS() // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||
parser.getEngine().name; // "AppleWebKit"
|
||||
console.log(parser.setUA(ua1).getDevice().name); // "PlayBook"
|
||||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||
console.log(parser.getOS(ua2)) // {name: "Linux", version: undefined}
|
||||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||
console.log(parser.getEngine().name); // "AppleWebKit"
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2012 Faisalman <<fyzlman@gmail.com>>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
16
ua-parser.js
16
ua-parser.js
@ -1,4 +1,4 @@
|
||||
// UA-Parser.js v0.3.2
|
||||
// UA-Parser.JS v0.3.3
|
||||
// Lightweight JavaScript-based User-Agent string parser
|
||||
// https://github.com/faisalman/ua-parser-js
|
||||
//
|
||||
@ -12,10 +12,10 @@
|
||||
|
||||
// regexp mapper
|
||||
var regxMap = function (ua) {
|
||||
var result = {}, i, j, k, l;
|
||||
var result = {}, i, j, k, l, m;
|
||||
for (i = 1; i < arguments.length; i += 2) {
|
||||
var regex = arguments[i], // odd sequence (2,4,6,..)
|
||||
props = arguments[i + 1]; // even sequence (3,5,7,..)
|
||||
var regex = arguments[i], // odd sequence (2,4,6,..)
|
||||
props = arguments[i + 1]; // even sequence (3,5,7,..)
|
||||
for (k = 0; k < props.length; k++) {
|
||||
if (typeof props[k] == 'object') {
|
||||
result[props[k][0]] = undefined;
|
||||
@ -24,17 +24,17 @@
|
||||
}
|
||||
}
|
||||
for (j = 0; j < regex.length; j++) {
|
||||
var match = regex[j].exec(ua);
|
||||
if (!!match) {
|
||||
m = regex[j].exec(ua);
|
||||
if (!!m) {
|
||||
l = 1;
|
||||
for (k = 0; k < props.length; k++) {
|
||||
if (typeof props[k] === 'object' && props[k].length === 2) {
|
||||
result[props[k][0]] = props[k][1];
|
||||
l -= 1;
|
||||
} else if (typeof props[k] === 'object' && props[k].length === 3) {
|
||||
result[props[k][0]] = (!!match[k + l]) ? match[k + l].replace(props[k][1], props[k][2]) : undefined;
|
||||
result[props[k][0]] = (!!m[k + l]) ? m[k + l].replace(props[k][1], props[k][2]) : undefined;
|
||||
} else {
|
||||
result[props[k]] = (!!match[k + l]) ? match[k + l] : undefined;
|
||||
result[props[k]] = (!!m[k + l]) ? m[k + l] : undefined;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user