Last active
September 13, 2019 09:45
-
-
Save Kiura/fc281007930befc4a82a32456d0e770a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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