mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
Change Parser.check to Parser.compare
This commit is contained in:
parent
0c1564f1cd
commit
48638e7363
@ -285,6 +285,7 @@ class Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getResult() {
|
getResult() {
|
||||||
|
/* TODO: Make this function pure, return a new object instead of the reference */
|
||||||
return this.parsedResult;
|
return this.parsedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,14 +304,14 @@ class Parser {
|
|||||||
* // or with platforms
|
* // or with platforms
|
||||||
* if (browser.check({desktop: { chrome: '>118.01.1322' } }))
|
* if (browser.check({desktop: { chrome: '>118.01.1322' } }))
|
||||||
*/
|
*/
|
||||||
check(checkTree) {
|
compare(checkTree) {
|
||||||
const keysToProcess = Object.keys(checkTree);
|
const keysToProcess = Object.keys(checkTree);
|
||||||
return keysToProcess.some((browserAttribute) => {
|
return keysToProcess.some((browserAttribute) => {
|
||||||
const objectOrVersion = checkTree[browserAttribute];
|
const objectOrVersion = checkTree[browserAttribute];
|
||||||
|
|
||||||
if (typeof objectOrVersion === 'object') {
|
if (typeof objectOrVersion === 'object') {
|
||||||
return (this.isOs(browserAttribute) || this.isPlatform(browserAttribute))
|
return (this.isOs(browserAttribute) || this.isPlatform(browserAttribute))
|
||||||
&& this.check(objectOrVersion);
|
&& this.compare(objectOrVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.isBrowser(browserAttribute) && this.satisfies(objectOrVersion);
|
return this.isBrowser(browserAttribute) && this.satisfies(objectOrVersion);
|
||||||
|
10
test.old.js
10
test.old.js
@ -118,28 +118,28 @@ describe('Unsupported browser check', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT be passed by #check for IE10.6 and for IE11 miminal version specified', function() {
|
it('should NOT be passed by #check for IE10.6 and for IE11 miminal version specified', function() {
|
||||||
var supported = browser.check({msie: "11"}, this.ie10_6);
|
var supported = browser.compare({msie: "11"}, this.ie10_6);
|
||||||
assert.equal(supported, false);
|
assert.equal(supported, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT be passed by #check for IE10.6 and for IE11 miminal version specified in strict mode', function() {
|
it('should NOT be passed by #check for IE10.6 and for IE11 miminal version specified in strict mode', function() {
|
||||||
var supported = browser.check({msie: "11"}, true, this.ie10_6);
|
var supported = browser.compare({msie: "11"}, true, this.ie10_6);
|
||||||
assert.equal(supported, false);
|
assert.equal(supported, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when minVersion map has a number, but not a string', function() {
|
it('should throw an error when minVersion map has a number, but not a string', function() {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
browser.check({msie: 11}, this.ie10_6);
|
browser.compare({msie: 11}, this.ie10_6);
|
||||||
}, /Browser version in the minVersion map should be a string/);
|
}, /Browser version in the minVersion map should be a string/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be passed by #check for IE10.6 when version was not specified', function() {
|
it('should be passed by #check for IE10.6 when version was not specified', function() {
|
||||||
var supported = browser.check({}, this.ie10_6);
|
var supported = browser.compare({}, this.ie10_6);
|
||||||
assert.equal(supported, true);
|
assert.equal(supported, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT be passed by #check for IE10.6 when version was not specified in strict mode', function() {
|
it('should NOT be passed by #check for IE10.6 when version was not specified in strict mode', function() {
|
||||||
var supported = browser.check({}, true, this.ie10_6);
|
var supported = browser.compare({}, true, this.ie10_6);
|
||||||
assert.equal(supported, false);
|
assert.equal(supported, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ test('Skip parsing shouldn\'t parse', (t) => {
|
|||||||
t.deepEqual((new Parser(UA, true)).getResult(), {});
|
t.deepEqual((new Parser(UA, true)).getResult(), {});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Parser.check should make simple check', (t) => {
|
test('Parser.check should make simple comparison', (t) => {
|
||||||
t.is(parser.check({ opera: '>42' }), true);
|
t.is(parser.compare({ opera: '>42' }), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Parser.check should make simple check', (t) => {
|
test('Parser.check should make complex comparison', (t) => {
|
||||||
t.is(parser.check({
|
t.is(parser.compare({
|
||||||
macos: {
|
macos: {
|
||||||
safari: '>11',
|
safari: '>11',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user