mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
fixes #359 IE11 Added Array.prototype.find and Object.assign polyfills
This commit is contained in:
parent
ea8d9c5427
commit
f5a908584c
@ -82,7 +82,7 @@ class Parser {
|
|||||||
parseBrowser() {
|
parseBrowser() {
|
||||||
this.parsedResult.browser = {};
|
this.parsedResult.browser = {};
|
||||||
|
|
||||||
const browserDescriptor = browserParsersList.find((_browser) => {
|
const browserDescriptor = Utils.find(browserParsersList, _browser => {
|
||||||
if (typeof _browser.test === 'function') {
|
if (typeof _browser.test === 'function') {
|
||||||
return _browser.test(this);
|
return _browser.test(this);
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ class Parser {
|
|||||||
parseOS() {
|
parseOS() {
|
||||||
this.parsedResult.os = {};
|
this.parsedResult.os = {};
|
||||||
|
|
||||||
const os = osParsersList.find((_os) => {
|
const os = Utils.find(osParsersList, _os => {
|
||||||
if (typeof _os.test === 'function') {
|
if (typeof _os.test === 'function') {
|
||||||
return _os.test(this);
|
return _os.test(this);
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ class Parser {
|
|||||||
parsePlatform() {
|
parsePlatform() {
|
||||||
this.parsedResult.platform = {};
|
this.parsedResult.platform = {};
|
||||||
|
|
||||||
const platform = platformParsersList.find((_platform) => {
|
const platform = Utils.find(platformParsersList, _platform => {
|
||||||
if (typeof _platform.test === 'function') {
|
if (typeof _platform.test === 'function') {
|
||||||
return _platform.test(this);
|
return _platform.test(this);
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ class Parser {
|
|||||||
parseEngine() {
|
parseEngine() {
|
||||||
this.parsedResult.engine = {};
|
this.parsedResult.engine = {};
|
||||||
|
|
||||||
const engine = enginesParsersList.find((_engine) => {
|
const engine = Utils.find(enginesParsersList, _engine => {
|
||||||
if (typeof _engine.test === 'function') {
|
if (typeof _engine.test === 'function') {
|
||||||
return _engine.test(this);
|
return _engine.test(this);
|
||||||
}
|
}
|
||||||
@ -328,7 +328,7 @@ class Parser {
|
|||||||
* @return {ParsedResult}
|
* @return {ParsedResult}
|
||||||
*/
|
*/
|
||||||
getResult() {
|
getResult() {
|
||||||
return Object.assign({}, this.parsedResult);
|
return Utils.assign({}, this.parsedResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -370,7 +370,7 @@ class Parser {
|
|||||||
|
|
||||||
if (platformsAndOSCounter > 0) {
|
if (platformsAndOSCounter > 0) {
|
||||||
const platformsAndOSNames = Object.keys(platformsAndOSes);
|
const platformsAndOSNames = Object.keys(platformsAndOSes);
|
||||||
const OSMatchingDefinition = platformsAndOSNames.find(name => (this.isOS(name)));
|
const OSMatchingDefinition = Utils.find(platformsAndOSNames, name => (this.isOS(name)));
|
||||||
|
|
||||||
if (OSMatchingDefinition) {
|
if (OSMatchingDefinition) {
|
||||||
const osResult = this.satisfies(platformsAndOSes[OSMatchingDefinition]);
|
const osResult = this.satisfies(platformsAndOSes[OSMatchingDefinition]);
|
||||||
@ -380,7 +380,7 @@ class Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const platformMatchingDefinition = platformsAndOSNames.find(name => (this.isPlatform(name)));
|
const platformMatchingDefinition = Utils.find(platformsAndOSNames, name => (this.isPlatform(name)));
|
||||||
if (platformMatchingDefinition) {
|
if (platformMatchingDefinition) {
|
||||||
const platformResult = this.satisfies(platformsAndOSes[platformMatchingDefinition]);
|
const platformResult = this.satisfies(platformsAndOSes[platformMatchingDefinition]);
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ class Parser {
|
|||||||
|
|
||||||
if (browsersCounter > 0) {
|
if (browsersCounter > 0) {
|
||||||
const browserNames = Object.keys(browsers);
|
const browserNames = Object.keys(browsers);
|
||||||
const matchingDefinition = browserNames.find(name => (this.isBrowser(name, true)));
|
const matchingDefinition = Utils.find(browserNames, name => (this.isBrowser(name, true)));
|
||||||
|
|
||||||
if (matchingDefinition !== void 0) {
|
if (matchingDefinition !== void 0) {
|
||||||
return this.compareVersion(browsers[matchingDefinition]);
|
return this.compareVersion(browsers[matchingDefinition]);
|
||||||
|
38
src/utils.js
38
src/utils.js
@ -231,6 +231,44 @@ export default class Utils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array::find polyfill
|
||||||
|
*
|
||||||
|
* @param {Array} arr
|
||||||
|
* @param {Function} predicate
|
||||||
|
* @return {Array}
|
||||||
|
*/
|
||||||
|
static find(arr, predicate) {
|
||||||
|
let i;
|
||||||
|
let l;
|
||||||
|
for (i = 0, l = arr.length; i < l; i++ ) {
|
||||||
|
const value = arr[i];
|
||||||
|
if (!predicate(value, i)) continue;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object::assign polyfill
|
||||||
|
*
|
||||||
|
* @param {Object} obj
|
||||||
|
* @param {Object} ...objs
|
||||||
|
* @return {Object}
|
||||||
|
*/
|
||||||
|
static assign(obj) {
|
||||||
|
let i;
|
||||||
|
let l;
|
||||||
|
let k;
|
||||||
|
for (i = 1, l = arguments.length; i < l; i++) {
|
||||||
|
const assigner = arguments[i];
|
||||||
|
if (!(typeof assigner === "object")) continue;
|
||||||
|
for (k in assigner) {
|
||||||
|
obj[k] = assigner[k]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get short version/alias for a browser name
|
* Get short version/alias for a browser name
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user