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

Add parser.some function

This commit is contained in:
Matías Lescano 2018-07-17 17:43:54 -03:00
parent 2ae6ce1820
commit 53e7af3a38
2 changed files with 17 additions and 0 deletions

View File

@ -427,6 +427,15 @@ class Parser {
is(anything) { is(anything) {
return this.isBrowser(anything) || this.isOS(anything) || this.isPlatform(anything); return this.isBrowser(anything) || this.isOS(anything) || this.isPlatform(anything);
} }
/**
* Check if any of the given values satifies this.is(anything)
* @param {String[]} anythings
* @returns {Boolean}
*/
some(anythings = []) {
return anythings.some(anything => this.is(anything));
}
} }
export default Parser; export default Parser;

View File

@ -114,3 +114,11 @@ test('Parser.is should pass', (t) => {
t.is(parser.is('desktop'), true); t.is(parser.is('desktop'), true);
t.is(parser.is('macos'), true); t.is(parser.is('macos'), true);
}); });
test('Parser.some should pass', (t) => {
t.is(parser.some(['opera', 'chrome', 'firefox']), true);
t.is(parser.some(['macos', 'windows']), true);
t.is(parser.some(['chrome', 'firefox']), false);
t.is(parser.some([]), false);
t.is(parser.some(), false);
});