1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

Fix getPlatformType, write tests

This commit is contained in:
Denis Demchenko 2018-07-04 23:09:33 +03:00
parent 48638e7363
commit e759592884
2 changed files with 22 additions and 6 deletions

View File

@ -198,14 +198,14 @@ class Parser {
* @param {Boolean} toLowerCase
* @return {*}
*/
getPlatformName(toLowerCase) {
const { name } = this.getPlatform();
getPlatformType(toLowerCase) {
const { type } = this.getPlatform();
if (toLowerCase) {
return String(name).toLowerCase() || '';
return String(type).toLowerCase() || '';
}
return name || '';
return type || '';
}
/**
@ -342,8 +342,18 @@ class Parser {
return this.getOSName(true) === String(osName).toLowerCase();
}
isPlatform(platformName) {
return this.getPlatformName(true) === String(platformName).toLowerCase();
isPlatform(platformType) {
return this.getPlatformType(true) === String(platformType).toLowerCase();
}
/**
* Is anything? Check if the browser is called "anything",
* the OS called "anything" or the platform called "anything"
* @param {String} anything
* @returns {Boolean}
*/
is(anything) {
return this.isBrowser(anything) || this.isOs(anything) || this.isPlatform(anything);
}
}

View File

@ -72,3 +72,9 @@ test('Parser.check should make complex comparison', (t) => {
opera: '>42',
}), true);
});
test('Parser.is should pass', (t) => {
t.is(parser.is('opera'), true);
t.is(parser.is('desktop'), true);
t.is(parser.is('macos'), true);
});