From c50d0449d3968f72c0dea4fce0c1266b1205e652 Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Sun, 9 Apr 2017 22:46:23 +0300 Subject: [PATCH] Add Parser#getBrowserName and Parser#getBrowserVersion --- src/parser.js | 31 ++++++++++++++++++++++--------- test/unit/parser.js | 9 +++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/parser.js b/src/parser.js index 9f665cb..c52ddc3 100644 --- a/src/parser.js +++ b/src/parser.js @@ -26,6 +26,15 @@ class Parser { return this._ua; } + /** + * Test a UA string for a regexp + * @param {RegExp} regex + * @return {Boolean} + */ + test(regex) { + return regex.test(this._ua); + } + /** * Get parsed browser object * @return {Object} @@ -71,18 +80,22 @@ class Parser { } /** - * Test a UA string for a regexp - * @param {RegExp} regex - * @return {Boolean} + * Get browser's name + * @return {String} Browser's name + * + * @public */ - test(regex) { - return regex.test(this._ua); + getBrowserName() { + return this.getBrowser().name; + } + + + getBrowserVersion() { + return this.getBrowser().version; } - parseBrowserName() {} - parseBrowserVersion() {} - parsePlatform(){} - parseOS(){} + getPlatform(){} + getOS(){} parseOSName(){} parseOSVersion(){} parseFullInfo(){} diff --git a/test/unit/parser.js b/test/unit/parser.js index cc30073..8893983 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -23,4 +23,13 @@ test('_parseBrowser', t => { t.truthy(spy.called); t.is(b.name, 'Opera'); t.is(b.version, '43.0.2442.1165'); + parser._parseBrowser.restore(); +}); + +test('getBrowserName', t => { + t.is(parser.getBrowserName(), 'Opera'); +}); + +test('getBrowserVersion', t => { + t.is(parser.getBrowserVersion(), '43.0.2442.1165'); });