mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
feat: add support for using alias in 'is' method
This commit is contained in:
parent
d1a6532d82
commit
a9c4677c86
@ -474,10 +474,12 @@ class Parser {
|
|||||||
* Is anything? Check if the browser is called "anything",
|
* Is anything? Check if the browser is called "anything",
|
||||||
* the OS called "anything" or the platform called "anything"
|
* the OS called "anything" or the platform called "anything"
|
||||||
* @param {String} anything
|
* @param {String} anything
|
||||||
|
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
is(anything) {
|
is(anything, includingAlias = false) {
|
||||||
return this.isBrowser(anything) || this.isOS(anything) || this.isPlatform(anything);
|
return this.isBrowser(anything, includingAlias) || this.isOS(anything)
|
||||||
|
|| this.isPlatform(anything);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,6 +165,30 @@ test('Parser.is should pass', (t) => {
|
|||||||
t.is(parser.is('macos'), true);
|
t.is(parser.is('macos'), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Parser.is should pass when not including aliases', (t) => {
|
||||||
|
t.is(edgeParser.is('Microsoft Edge', false), true);
|
||||||
|
t.is(edgeParser.is('microsoft edge', false), true);
|
||||||
|
t.is(edgeParser.is('mIcrosoft eDge', false), true);
|
||||||
|
t.is(edgeParser.is('edge', false), false);
|
||||||
|
t.is(edgeParser.is('Edge', false), false);
|
||||||
|
t.is(edgeParser.is('desktop', false), false);
|
||||||
|
t.is(edgeParser.is('macos', false), false);
|
||||||
|
t.is(edgeParser.is('mobile', false), true);
|
||||||
|
t.is(edgeParser.is('android', false), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Parser.is should pass when including aliases', (t) => {
|
||||||
|
t.is(edgeParser.is('Microsoft Edge', true), true);
|
||||||
|
t.is(edgeParser.is('microsoft edge', true), true);
|
||||||
|
t.is(edgeParser.is('mIcrosoft eDge', true), true);
|
||||||
|
t.is(edgeParser.is('edge', true), true);
|
||||||
|
t.is(edgeParser.is('Edge', true), true);
|
||||||
|
t.is(edgeParser.is('desktop', true), false);
|
||||||
|
t.is(edgeParser.is('macos', true), false);
|
||||||
|
t.is(edgeParser.is('mobile', true), true);
|
||||||
|
t.is(edgeParser.is('android', true), true);
|
||||||
|
});
|
||||||
|
|
||||||
test('Parser.is using constants should pass', (t) => {
|
test('Parser.is using constants should pass', (t) => {
|
||||||
t.is(parser.is(Bowser.BROWSER_MAP.opera), true);
|
t.is(parser.is(Bowser.BROWSER_MAP.opera), true);
|
||||||
t.is(parser.is(Bowser.PLATFORMS_MAP.desktop), true);
|
t.is(parser.is(Bowser.PLATFORMS_MAP.desktop), true);
|
||||||
@ -199,3 +223,8 @@ test('Parser.isBrowser should pass for non-aliased browsers', (t) => {
|
|||||||
t.is(focusParser.isBrowser('Focus', true), true);
|
t.is(focusParser.isBrowser('Focus', true), true);
|
||||||
t.is(focusParser.isBrowser('Focus', false), true);
|
t.is(focusParser.isBrowser('Focus', false), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Parser.isEngine should pass', (t) => {
|
||||||
|
t.is(parser.isEngine('blink'), true);
|
||||||
|
t.is(parser.isEngine('webkit'), false);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user