-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathBrowser.js
140 lines (121 loc) · 3.11 KB
/
Browser.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const NameVersion = require('./primitive/NameVersion');
const Constants = require('../constants');
/**
* Represents a Browser
*
* @param {Object|null} properties An optional Object of properties to set after setting it to the default values
*
* @internal
*/
class Browser extends NameVersion {
/**
* constructor
*
* @param {object} [properties]
* @param {Using} [properties.using] Information about web views the browser is using
* @param {Family} [properties.family] To which browser family does this browser belong
* @param {string} [properties.channel]
* @param {boolean} [properties.stock=true]
* @param {boolean} [properties.hidden=false]
* @param {string} [properties.mode='']
* @param {string} [properties.type='']
*
* @internal
*/
constructor(properties = {}) {
super(Object.assign({}, { stock: true, hidden: false, mode: '', type: '' }, properties));
}
/**
* Set the properties to the default values
*
* @param {Object|null} properties An optional Object of properties to set after setting it to the default values
*
* @internal
*/
reset(properties = null) {
super.reset();
this.channel = null;
this.using = null;
this.family = null;
this.stock = true;
this.hidden = false;
this.mode = '';
this.type = '';
properties && this.set(properties);
}
/**
* Get the name in a human readable format
*
* @return {string}
*/
getName() {
const name = super.getName();
return name ? `${name}${this.channel ? ` ${this.channel}` : ''}` : '';
}
/**
* Is the browser from the specified family
*
* @param {string} name The name of the family
*
* @return {boolean}
*/
isFamily(name) {
return this.getName() === name || (!!this.family && this.family.getName() === name);
}
/**
* Is the browser using the specified webview
*
* @param {string} name The name of the webview
*
* @return {boolean}
*/
isUsing(name) {
return !!this.using && this.using.getName() === name;
}
/**
* Get a combined name and version number in a human readable format
*
* @return {string}
*/
toString() {
if (this.hidden) {
return '';
}
const result = `${this.getName()} ${!!this.version && !this.version.hidden ? this.getVersion() : ''}`.trim();
if (!result && this.using) {
return this.using.toString();
}
return result;
}
/**
* Get object with all defined properties
*
* @internal
*
* @return {object}
*/
toObject() {
const result = {};
if (this.name) {
result.name = this.name;
}
if (this.alias) {
result.alias = this.alias;
}
if (this.using) {
result.using = this.using.toObject();
}
if (this.family) {
result.family = this.family.toObject();
}
let versionObj;
if (this.version && Object.keys((versionObj = this.version.toObject())).length) {
result.version = versionObj;
}
if (this.type && this.type !== Constants.browserType.UNKNOWN) {
result.type = this.type;
}
return result;
}
}
module.exports = Browser;