From 0224f26bfc5af6270417ceff2488bae559c8d130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mati=CC=81as=20Lescano?= Date: Tue, 17 Jul 2018 17:43:54 -0300 Subject: [PATCH] Add parser.some function --- src/parser.js | 9 +++++++++ test/unit/parser.js | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/parser.js b/src/parser.js index 2ce0fc9..df98540 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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; diff --git a/test/unit/parser.js b/test/unit/parser.js index a600752..afb643e 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -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); +});