Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Kiura
Last active September 13, 2019 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kiura/fc281007930befc4a82a32456d0e770a to your computer and use it in GitHub Desktop.
Save Kiura/fc281007930befc4a82a32456d0e770a to your computer and use it in GitHub Desktop.
import Utils from './utils.js';
const browsersNames = [
/* Googlebot */
{
test: [/googlebot/i],
name: 'Googlebot',
},
];
const browsersVersions = {
'Googlebot': function(ua) {
return Utils.getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
}
}
class Parser {
parseName() {
this.name = '';
for (let i = 0; i < browsersNames.length; i++) {
let browser = browsersNames[i]
if (typeof browser.test === 'function' && browser.test(this)) {
return this.name = browser.name
}
if (browser.test instanceof Array) {
for (let j = 0; j < browser.test.length; j++) {
let regex = browser.test[j]
if (regex.test(this.getUA())) {
return this.name = browser.name
}
}
}
}
return '';
}
parseVersion() {
if (!this.name || this.name == '') this.name = parseName()
if (!browsersVersions[this.name]) return 'Unknown'
return browsersVersions[this.name](this.getUA())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment