mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
Merge pull request #275 from deployed/master
Support non strict equality in satisfies method
This commit is contained in:
commit
d39f2fe125
@ -68,6 +68,7 @@
|
|||||||
"lint": "eslint ./src",
|
"lint": "eslint ./src",
|
||||||
"testem": "testem",
|
"testem": "testem",
|
||||||
"test": "nyc --reporter=html --reporter=text ava",
|
"test": "nyc --reporter=html --reporter=text ava",
|
||||||
|
"test:watch": "ava --watch",
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"docs": "jsdoc -c jsdoc.json"
|
"docs": "jsdoc -c jsdoc.json"
|
||||||
},
|
},
|
||||||
|
@ -395,7 +395,7 @@ class Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compareVersion(version) {
|
compareVersion(version) {
|
||||||
let expectedResult = 0;
|
let expectedResults = [0];
|
||||||
let comparableVersion = version;
|
let comparableVersion = version;
|
||||||
let isLoose = false;
|
let isLoose = false;
|
||||||
|
|
||||||
@ -405,12 +405,19 @@ class Parser {
|
|||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version[0] === '>' || version[0] === '<') {
|
||||||
|
comparableVersion = version.substr(1);
|
||||||
|
if (version[1] === '=') {
|
||||||
|
isLoose = true;
|
||||||
|
comparableVersion = version.substr(2);
|
||||||
|
} else {
|
||||||
|
expectedResults = [];
|
||||||
|
}
|
||||||
if (version[0] === '>') {
|
if (version[0] === '>') {
|
||||||
expectedResult = 1;
|
expectedResults.push(1);
|
||||||
comparableVersion = version.substr(1);
|
} else {
|
||||||
} else if (version[0] === '<') {
|
expectedResults.push(-1);
|
||||||
expectedResult = -1;
|
}
|
||||||
comparableVersion = version.substr(1);
|
|
||||||
} else if (version[0] === '=') {
|
} else if (version[0] === '=') {
|
||||||
comparableVersion = version.substr(1);
|
comparableVersion = version.substr(1);
|
||||||
} else if (version[0] === '~') {
|
} else if (version[0] === '~') {
|
||||||
@ -418,7 +425,9 @@ class Parser {
|
|||||||
comparableVersion = version.substr(1);
|
comparableVersion = version.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return compareVersions(currentBrowserVersion, comparableVersion, isLoose) === expectedResult;
|
return expectedResults.indexOf(
|
||||||
|
compareVersions(currentBrowserVersion, comparableVersion, isLoose),
|
||||||
|
) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
isOS(osName) {
|
isOS(osName) {
|
||||||
|
@ -63,6 +63,14 @@ test('Parser.satisfies should make simple comparisons', (t) => {
|
|||||||
t.is(parser.satisfies({ opera: '<44' }), true);
|
t.is(parser.satisfies({ opera: '<44' }), true);
|
||||||
t.is(parser.satisfies({ opera: '=43.0.2442.1165' }), true);
|
t.is(parser.satisfies({ opera: '=43.0.2442.1165' }), true);
|
||||||
t.is(parser.satisfies({ opera: '~43.0' }), true);
|
t.is(parser.satisfies({ opera: '~43.0' }), true);
|
||||||
|
t.is(parser.satisfies({ opera: '>=43' }), true);
|
||||||
|
t.is(parser.satisfies({ opera: '<=43' }), true);
|
||||||
|
t.is(parser.satisfies({ opera: '>=43.0' }), true);
|
||||||
|
t.is(parser.satisfies({ opera: '>=43.0.2442.1165' }), true);
|
||||||
|
t.is(parser.satisfies({ opera: '<=43.0.2442.1165' }), true);
|
||||||
|
t.is(parser.satisfies({ opera: '>=43.0.2443' }), false);
|
||||||
|
t.is(parser.satisfies({ opera: '<=43.0.2443' }), true);
|
||||||
|
t.is(parser.satisfies({ opera: '>=43.0.2441' }), true);
|
||||||
t.is(parser.satisfies({ opera: '~43' }), true);
|
t.is(parser.satisfies({ opera: '~43' }), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user