Add parser.some function

pull/235/head
Matías Lescano 6 years ago
parent 2ae6ce1820
commit 53e7af3a38

@ -427,6 +427,15 @@ class Parser {
is(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;

@ -114,3 +114,11 @@ test('Parser.is should pass', (t) => {
t.is(parser.is('desktop'), 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);
});

Loading…
Cancel
Save