forked from WhichBrowser/Parser-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseragent.js
More file actions
35 lines (30 loc) · 1.19 KB
/
Useragent.js
File metadata and controls
35 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable require-jsdoc */
const { Application, Bot, Browser, Device, Engine, Os, Using } = require('./Useragent/');
class Useragent {
constructor(header, data, options) {
this.data = data;
this.options = options;
/* Make sure we do not have a duplicate concatenated useragent string */
header = header.replace(/^(Mozilla\/[0-9]\.[0-9].{20,})\s+Mozilla\/[0-9]\.[0-9].*$/iu, '$1');
/* Detect the basic information */
Os.detectOperatingSystem.call(this, header);
Device.detectDevice.call(this, header);
Browser.detectBrowser.call(this, header);
Application.detectApplication.call(this, header);
Using.detectUsing.call(this, header);
Engine.detectEngine.call(this, header);
/* Detect bots */
if (typeof this.options.detectBots === 'undefined' || this.options.detectBots === true) {
Bot.detectBot.call(this, header);
}
/* Refine some of the information */
Browser.refineBrowser.call(this, header);
Os.refineOperatingSystem.call(this, header);
}
static removeKnownPrefixes(ua) {
ua = ua.replace(/^OneBrowser\/[0-9.]+\//, '');
ua = ua.replace(/^MQQBrowser\/[0-9.]+\//, '');
return ua;
}
}
module.exports = Useragent;