From 196d94507bfd8abbf0d2f60b094467941c0759c3 Mon Sep 17 00:00:00 2001 From: Damon Oehlman Date: Thu, 14 Sep 2017 21:06:00 +1000 Subject: [PATCH 1/5] remove console.log statement --- browser.js | 9 --------- index.js | 17 +++++++++++++++-- package.json | 1 - parse-user-agent.js | 42 ++++++++++++++++++++++++++++++++++++++++++ test/logic.js | 2 +- 5 files changed, 58 insertions(+), 13 deletions(-) delete mode 100644 browser.js create mode 100644 parse-user-agent.js diff --git a/browser.js b/browser.js deleted file mode 100644 index c14bd97..0000000 --- a/browser.js +++ /dev/null @@ -1,9 +0,0 @@ -var detectBrowser = require('./lib/detectBrowser'); - -var agent; - -if (typeof navigator !== 'undefined' && navigator) { - agent = navigator.userAgent; -} - -module.exports = detectBrowser(agent); diff --git a/index.js b/index.js index a781915..908d56f 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +var parseUserAgent = require('./parse-user-agent'); + /** # detect-browser @@ -38,5 +40,16 @@ **/ -exports.name = 'node'; -exports.version = process.version.slice(1); +module.exports = function() { + var isNode = typeof navigator === 'undefined' && typeof process !== 'undefined'; + if (isNode) { + return { + name: 'node', + version: process.version.slice(1) + }; + } else if (typeof navigator === 'undefined') { + return null; + } else { + return parseUserAgent(navigator.userAgent); + } +}(); diff --git a/package.json b/package.json index 4d16f59..bcd690d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "version": "1.12.0", "description": "Unpack a browser type and version from the useragent string", "main": "index.js", - "browser": "browser.js", "scripts": { "test": "node test", "prepublish": "npm run test", diff --git a/parse-user-agent.js b/parse-user-agent.js new file mode 100644 index 0000000..6991cb8 --- /dev/null +++ b/parse-user-agent.js @@ -0,0 +1,42 @@ +var browsers = [ + [ 'edge', /Edge\/([0-9\._]+)/ ], + [ 'yandexbrowser', /YaBrowser\/([0-9\._]+)/ ], + [ 'vivaldi', /Vivaldi\/([0-9\.]+)/ ], + [ 'kakaotalk', /KAKAOTALK\s([0-9\.]+)/ ], + [ 'chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/ ], + [ 'phantomjs', /PhantomJS\/([0-9\.]+)(:?\s|$)/ ], + [ 'crios', /CriOS\/([0-9\.]+)(:?\s|$)/ ], + [ 'firefox', /Firefox\/([0-9\.]+)(?:\s|$)/ ], + [ 'fxios', /FxiOS\/([0-9\.]+)/ ], + [ 'opera', /Opera\/([0-9\.]+)(?:\s|$)/ ], + [ 'opera', /OPR\/([0-9\.]+)(:?\s|$)$/ ], + [ 'ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/ ], + [ 'ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ ], + [ 'ie', /MSIE\s(7\.0)/ ], + [ 'bb10', /BB10;\sTouch.*Version\/([0-9\.]+)/ ], + [ 'android', /Android\s([0-9\.]+)/ ], + [ 'ios', /Version\/([0-9\._]+).*Mobile.*Safari.*/ ], + [ 'safari', /Version\/([0-9\._]+).*Safari/ ] +]; + +module.exports = function(userAgentString) { + if (!userAgentString) { + return null; + } + + return browsers.map(function (rule) { + if (rule[1].test(userAgentString)) { + var match = rule[1].exec(userAgentString); + var version = match && match[1].split(/[._]/).slice(0,3); + + if (version && version.length < 3) { + Array.prototype.push.apply(version, (version.length == 1) ? [0, 0] : [0]); + } + + return { + name: rule[0], + version: version.join('.') + }; + } + }).filter(Boolean).shift(); +}; diff --git a/test/logic.js b/test/logic.js index ca26090..269e291 100644 --- a/test/logic.js +++ b/test/logic.js @@ -1,5 +1,5 @@ var test = require('tape'); -var detectBrowser = require('../lib/detectBrowser'); +var detectBrowser = require('../parse-user-agent'); function assertAgentString(t, agentString, expectedResult) { t.deepEqual(detectBrowser(agentString), expectedResult); From b54294be45e6368a0fb779564b5bede60b84a6f9 Mon Sep 17 00:00:00 2001 From: Damon Oehlman Date: Thu, 14 Sep 2017 21:24:19 +1000 Subject: [PATCH 2/5] . --- index.js | 76 ++++++++++++++++++++++++++++++++++++++------- parse-user-agent.js | 42 ------------------------- test/highLevel.js | 7 +++-- test/logic.js | 4 +-- 4 files changed, 71 insertions(+), 58 deletions(-) delete mode 100644 parse-user-agent.js diff --git a/index.js b/index.js index 908d56f..c06df0f 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,3 @@ -var parseUserAgent = require('./parse-user-agent'); - /** # detect-browser @@ -40,16 +38,70 @@ var parseUserAgent = require('./parse-user-agent'); **/ -module.exports = function() { +var browsers = [ + [ 'edge', /Edge\/([0-9\._]+)/ ], + [ 'yandexbrowser', /YaBrowser\/([0-9\._]+)/ ], + [ 'vivaldi', /Vivaldi\/([0-9\.]+)/ ], + [ 'kakaotalk', /KAKAOTALK\s([0-9\.]+)/ ], + [ 'chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/ ], + [ 'phantomjs', /PhantomJS\/([0-9\.]+)(:?\s|$)/ ], + [ 'crios', /CriOS\/([0-9\.]+)(:?\s|$)/ ], + [ 'firefox', /Firefox\/([0-9\.]+)(?:\s|$)/ ], + [ 'fxios', /FxiOS\/([0-9\.]+)/ ], + [ 'opera', /Opera\/([0-9\.]+)(?:\s|$)/ ], + [ 'opera', /OPR\/([0-9\.]+)(:?\s|$)$/ ], + [ 'ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/ ], + [ 'ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ ], + [ 'ie', /MSIE\s(7\.0)/ ], + [ 'bb10', /BB10;\sTouch.*Version\/([0-9\.]+)/ ], + [ 'android', /Android\s([0-9\.]+)/ ], + [ 'ios', /Version\/([0-9\._]+).*Mobile.*Safari.*/ ], + [ 'safari', /Version\/([0-9\._]+).*Safari/ ] +]; + +function detect() { + const nodeVersion = getNodeVersion(); + if (nodeVersion) { + return nodeVersion; + } else if (typeof navigator !== 'undefined') { + return parseUserAgent(navigator.userAgent); + } + + return null; +} + +function getNodeVersion() { var isNode = typeof navigator === 'undefined' && typeof process !== 'undefined'; - if (isNode) { - return { - name: 'node', - version: process.version.slice(1) - }; - } else if (typeof navigator === 'undefined') { + return isNode ? { + name: 'node', + version: process.version.slice(1) + } : null; +} + +function parseUserAgent(userAgentString) { + if (!userAgentString) { return null; - } else { - return parseUserAgent(navigator.userAgent); } -}(); + + return browsers.map(function (rule) { + if (rule[1].test(userAgentString)) { + var match = rule[1].exec(userAgentString); + var version = match && match[1].split(/[._]/).slice(0,3); + + if (version && version.length < 3) { + Array.prototype.push.apply(version, (version.length == 1) ? [0, 0] : [0]); + } + + return { + name: rule[0], + version: version.join('.') + }; + } + }).filter(Boolean).shift(); +} + +module.exports = { + detect: detect, + getNodeVersion: getNodeVersion, + parseUserAgent: parseUserAgent +}; diff --git a/parse-user-agent.js b/parse-user-agent.js deleted file mode 100644 index 6991cb8..0000000 --- a/parse-user-agent.js +++ /dev/null @@ -1,42 +0,0 @@ -var browsers = [ - [ 'edge', /Edge\/([0-9\._]+)/ ], - [ 'yandexbrowser', /YaBrowser\/([0-9\._]+)/ ], - [ 'vivaldi', /Vivaldi\/([0-9\.]+)/ ], - [ 'kakaotalk', /KAKAOTALK\s([0-9\.]+)/ ], - [ 'chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/ ], - [ 'phantomjs', /PhantomJS\/([0-9\.]+)(:?\s|$)/ ], - [ 'crios', /CriOS\/([0-9\.]+)(:?\s|$)/ ], - [ 'firefox', /Firefox\/([0-9\.]+)(?:\s|$)/ ], - [ 'fxios', /FxiOS\/([0-9\.]+)/ ], - [ 'opera', /Opera\/([0-9\.]+)(?:\s|$)/ ], - [ 'opera', /OPR\/([0-9\.]+)(:?\s|$)$/ ], - [ 'ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/ ], - [ 'ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ ], - [ 'ie', /MSIE\s(7\.0)/ ], - [ 'bb10', /BB10;\sTouch.*Version\/([0-9\.]+)/ ], - [ 'android', /Android\s([0-9\.]+)/ ], - [ 'ios', /Version\/([0-9\._]+).*Mobile.*Safari.*/ ], - [ 'safari', /Version\/([0-9\._]+).*Safari/ ] -]; - -module.exports = function(userAgentString) { - if (!userAgentString) { - return null; - } - - return browsers.map(function (rule) { - if (rule[1].test(userAgentString)) { - var match = rule[1].exec(userAgentString); - var version = match && match[1].split(/[._]/).slice(0,3); - - if (version && version.length < 3) { - Array.prototype.push.apply(version, (version.length == 1) ? [0, 0] : [0]); - } - - return { - name: rule[0], - version: version.join('.') - }; - } - }).filter(Boolean).shift(); -}; diff --git a/test/highLevel.js b/test/highLevel.js index e73ac3a..ded0581 100644 --- a/test/highLevel.js +++ b/test/highLevel.js @@ -1,23 +1,26 @@ var semver = require('semver'); -var browser = require('../'); +var { detect } = require('../'); var test = require('tape'); test('can run detection', function(t) { - t.ok(browser, require.cache[require.resolve('../')]); + t.ok(detect(), 'detection ran ok'); t.end(); }); test('name detected', function(t) { + const browser = detect(); t.ok(browser.name, browser.name); t.end(); }); test('version detected', function(t) { + const browser = detect(); t.ok(browser.version, browser.version); t.end(); }); test('version is semver compatible', function(t) { + const browser = detect(); t.ok(semver.valid(browser.version)); t.end(); }); diff --git a/test/logic.js b/test/logic.js index 269e291..26e64bd 100644 --- a/test/logic.js +++ b/test/logic.js @@ -1,8 +1,8 @@ var test = require('tape'); -var detectBrowser = require('../parse-user-agent'); +var { parseUserAgent } = require('../'); function assertAgentString(t, agentString, expectedResult) { - t.deepEqual(detectBrowser(agentString), expectedResult); + t.deepEqual(parseUserAgent(agentString), expectedResult); } test('detects Chrome', function(t) { From c00c8a049716bd6456f4ece08d9d802d3b885850 Mon Sep 17 00:00:00 2001 From: Damon Oehlman Date: Thu, 21 Sep 2017 22:19:49 +1000 Subject: [PATCH 3/5] rebase and include slightly modified os detection --- index.js | 133 ++++++++++++++++++++++++++++++------------- lib/detectBrowser.js | 43 -------------- lib/detectOS.js | 112 ------------------------------------ 3 files changed, 95 insertions(+), 193 deletions(-) delete mode 100644 lib/detectBrowser.js delete mode 100644 lib/detectOS.js diff --git a/index.js b/index.js index c06df0f..dd5cbaa 100644 --- a/index.js +++ b/index.js @@ -38,29 +38,8 @@ **/ -var browsers = [ - [ 'edge', /Edge\/([0-9\._]+)/ ], - [ 'yandexbrowser', /YaBrowser\/([0-9\._]+)/ ], - [ 'vivaldi', /Vivaldi\/([0-9\.]+)/ ], - [ 'kakaotalk', /KAKAOTALK\s([0-9\.]+)/ ], - [ 'chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/ ], - [ 'phantomjs', /PhantomJS\/([0-9\.]+)(:?\s|$)/ ], - [ 'crios', /CriOS\/([0-9\.]+)(:?\s|$)/ ], - [ 'firefox', /Firefox\/([0-9\.]+)(?:\s|$)/ ], - [ 'fxios', /FxiOS\/([0-9\.]+)/ ], - [ 'opera', /Opera\/([0-9\.]+)(?:\s|$)/ ], - [ 'opera', /OPR\/([0-9\.]+)(:?\s|$)$/ ], - [ 'ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/ ], - [ 'ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ ], - [ 'ie', /MSIE\s(7\.0)/ ], - [ 'bb10', /BB10;\sTouch.*Version\/([0-9\.]+)/ ], - [ 'android', /Android\s([0-9\.]+)/ ], - [ 'ios', /Version\/([0-9\._]+).*Mobile.*Safari.*/ ], - [ 'safari', /Version\/([0-9\._]+).*Safari/ ] -]; - -function detect() { - const nodeVersion = getNodeVersion(); +function detectBrowser() { + var nodeVersion = getNodeVersion(); if (nodeVersion) { return nodeVersion; } else if (typeof navigator !== 'undefined') { @@ -70,38 +49,116 @@ function detect() { return null; } +function detectOS(userAgentString) { + var rules = getOperatingSystemRules(); + var detected = rules.filter(function (os) { + return os.rule && os.rule.test(userAgentString); + })[0]; + + return detected ? detected.name : null; +} + function getNodeVersion() { var isNode = typeof navigator === 'undefined' && typeof process !== 'undefined'; return isNode ? { name: 'node', - version: process.version.slice(1) + version: process.version.slice(1), + os: require('os').type().toLowerCase() } : null; } function parseUserAgent(userAgentString) { + var browsers = getBrowserRules(); if (!userAgentString) { return null; } - return browsers.map(function (rule) { - if (rule[1].test(userAgentString)) { - var match = rule[1].exec(userAgentString); - var version = match && match[1].split(/[._]/).slice(0,3); - - if (version && version.length < 3) { - Array.prototype.push.apply(version, (version.length == 1) ? [0, 0] : [0]); - } + var detected = browsers.map(function(browser) { + var match = browser.rule.exec(userAgentString); + var version = match && match[1].split(/[._]/).slice(0,3); - return { - name: rule[0], - version: version.join('.') - }; + if (version && version.length < 3) { + version = version.concat(version.length == 1 ? [0, 0] : [0]); } - }).filter(Boolean).shift(); + + return match && { + name: browser.name, + version: version.join('.') + }; + }).filter(Boolean)[0] || null; + + if (detected) { + detected.os = detectOS(userAgentString); + } + + return detected; +} + +function getBrowserRules() { + return buildRules([ + [ 'edge', /Edge\/([0-9\._]+)/ ], + [ 'yandexbrowser', /YaBrowser\/([0-9\._]+)/ ], + [ 'vivaldi', /Vivaldi\/([0-9\.]+)/ ], + [ 'kakaotalk', /KAKAOTALK\s([0-9\.]+)/ ], + [ 'chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/ ], + [ 'phantomjs', /PhantomJS\/([0-9\.]+)(:?\s|$)/ ], + [ 'crios', /CriOS\/([0-9\.]+)(:?\s|$)/ ], + [ 'firefox', /Firefox\/([0-9\.]+)(?:\s|$)/ ], + [ 'fxios', /FxiOS\/([0-9\.]+)/ ], + [ 'opera', /Opera\/([0-9\.]+)(?:\s|$)/ ], + [ 'opera', /OPR\/([0-9\.]+)(:?\s|$)$/ ], + [ 'ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/ ], + [ 'ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ ], + [ 'ie', /MSIE\s(7\.0)/ ], + [ 'bb10', /BB10;\sTouch.*Version\/([0-9\.]+)/ ], + [ 'android', /Android\s([0-9\.]+)/ ], + [ 'ios', /Version\/([0-9\._]+).*Mobile.*Safari.*/ ], + [ 'safari', /Version\/([0-9\._]+).*Safari/ ] + ]); +} + +function getOperatingSystemRules() { + return buildRules([ + [ 'iOS', /iP(hone|od|ad)/ ], + [ 'Android OS', /Android/ ], + [ 'BlackBerry OS', /BlackBerry|BB10/ ], + [ 'Windows Mobile', /IEMobile/ ], + [ 'Amazon OS', /Kindle/ ], + [ 'Windows 3.11', /Win16/ ], + [ 'Windows 95', /(Windows 95)|(Win95)|(Windows_95)/ ], + [ 'Windows 98', /(Windows 98)|(Win98)/ ], + [ 'Windows 2000', /(Windows NT 5.0)|(Windows 2000)/ ], + [ 'Windows XP', /(Windows NT 5.1)|(Windows XP)/ ], + [ 'Windows Server 2003', /(Windows NT 5.2)/ ], + [ 'Windows Vista', /(Windows NT 6.0)/ ], + [ 'Windows 7', /(Windows NT 6.1)/ ], + [ 'Windows 8', /(Windows NT 6.2)/ ], + [ 'Windows 8.1', /(Windows NT 6.3)/ ], + [ 'Windows 10', /(Windows NT 10.0)/ ], + [ 'Windows ME', /Windows ME/ ], + [ 'Open BSD', /OpenBSD/ ], + [ 'Sun OS', /SunOS/ ], + [ 'Linux', /(Linux)|(X11)/ ], + [ 'Mac OS', /(Mac_PowerPC)|(Macintosh)/ ], + [ 'QNX', /QNX/ ], + [ 'BeOS', /BeOS/ ], + [ 'OS/2', /OS\/2/ ], + [ 'Search Bot', /(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/ ] + ]); +} + +function buildRules(ruleTuples) { + return ruleTuples.map(function(tuple) { + return { + name: tuple[0], + rule: tuple[1] + }; + }); } module.exports = { - detect: detect, + detect: detectBrowser, + detectOS: detectOS, getNodeVersion: getNodeVersion, parseUserAgent: parseUserAgent }; diff --git a/lib/detectBrowser.js b/lib/detectBrowser.js deleted file mode 100644 index ade9129..0000000 --- a/lib/detectBrowser.js +++ /dev/null @@ -1,43 +0,0 @@ -var detectOS = require('./detectOS.js'); - -module.exports = function detectBrowser(userAgentString) { - if (!userAgentString) return null; - - var browsers = [ - [ 'edge', /Edge\/([0-9\._]+)/ ], - [ 'yandexbrowser', /YaBrowser\/([0-9\._]+)/ ], - [ 'vivaldi', /Vivaldi\/([0-9\.]+)/ ], - [ 'kakaotalk', /KAKAOTALK\s([0-9\.]+)/ ], - [ 'chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/ ], - [ 'phantomjs', /PhantomJS\/([0-9\.]+)(:?\s|$)/ ], - [ 'crios', /CriOS\/([0-9\.]+)(:?\s|$)/ ], - [ 'firefox', /Firefox\/([0-9\.]+)(?:\s|$)/ ], - [ 'fxios', /FxiOS\/([0-9\.]+)/ ], - [ 'opera', /Opera\/([0-9\.]+)(?:\s|$)/ ], - [ 'opera', /OPR\/([0-9\.]+)(:?\s|$)$/ ], - [ 'ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/ ], - [ 'ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ ], - [ 'ie', /MSIE\s(7\.0)/ ], - [ 'bb10', /BB10;\sTouch.*Version\/([0-9\.]+)/ ], - [ 'android', /Android\s([0-9\.]+)/ ], - [ 'ios', /Version\/([0-9\._]+).*Mobile.*Safari.*/ ], - [ 'safari', /Version\/([0-9\._]+).*Safari/ ] - ]; - - return browsers.map(function (rule) { - if (rule[1].test(userAgentString)) { - var match = rule[1].exec(userAgentString); - var version = match && match[1].split(/[._]/).slice(0,3); - - if (version && version.length < 3) { - Array.prototype.push.apply(version, (version.length == 1) ? [0, 0] : [0]); - } - - return { - name: rule[0], - version: version.join('.'), - os: detectOS(userAgentString) - }; - } - }).filter(Boolean).shift(); -}; diff --git a/lib/detectOS.js b/lib/detectOS.js deleted file mode 100644 index 09f8650..0000000 --- a/lib/detectOS.js +++ /dev/null @@ -1,112 +0,0 @@ -module.exports = function detectOS(userAgentString) { - var operatingSystems = [ - { - name: 'iOS', - rule: /iP(hone|od|ad)/ - }, - { - name: 'Android OS', - rule: /Android/ - }, - { - name: 'BlackBerry OS', - rule: /BlackBerry|BB10/ - }, - { - name: 'Windows Mobile', - rule: /IEMobile/ - }, - { - name: 'Amazon OS', - rule: /Kindle/ - }, - { - name: 'Windows 3.11', - rule: /Win16/ - }, - { - name: 'Windows 95', - rule: /(Windows 95)|(Win95)|(Windows_95)/ - }, - { - name: 'Windows 98', - rule: /(Windows 98)|(Win98)/ - }, - { - name: 'Windows 2000', - rule: /(Windows NT 5.0)|(Windows 2000)/ - }, - { - name: 'Windows XP', - rule: /(Windows NT 5.1)|(Windows XP)/ - }, - { - name: 'Windows Server 2003', - rule: /(Windows NT 5.2)/ - }, - { - name: 'Windows Vista', - rule: /(Windows NT 6.0)/ - }, - { - name: 'Windows 7', - rule: /(Windows NT 6.1)/ - }, - { - name: 'Windows 8', - rule: /(Windows NT 6.2)/ - }, - { - name: 'Windows 8.1', - rule: /(Windows NT 6.3)/ - }, - { - name: 'Windows 10', - rule: /(Windows NT 10.0)/ - }, - { - name: 'Windows ME', - rule: /Windows ME/ - }, - { - name: 'Open BSD', - rule: /OpenBSD/ - }, - { - name: 'Sun OS', - rule: /SunOS/ - }, - { - name: 'Linux', - rule: /(Linux)|(X11)/ - }, - { - name: 'Mac OS', - rule: /(Mac_PowerPC)|(Macintosh)/ - }, - { - name: 'QNX', - rule: /QNX/ - }, - { - name: 'BeOS', - rule: /BeOS/ - }, - { - name: 'OS/2', - rule: /OS\/2/ - }, - { - name: 'Search Bot', - rule: /(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/ - } - ]; - - var detected = operatingSystems.filter(function (os) { - if (userAgentString.match(os.rule)) { - return true; - } - }); - - return detected && detected[0] ? detected[0].name : null; -}; From 622fc57867b3c886e11c554209e37cb635913d06 Mon Sep 17 00:00:00 2001 From: Damon Oehlman Date: Thu, 21 Sep 2017 22:29:01 +1000 Subject: [PATCH 4/5] s/detectBrowser/detect/ --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index dd5cbaa..7f93378 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ **/ -function detectBrowser() { +function detect() { var nodeVersion = getNodeVersion(); if (nodeVersion) { return nodeVersion; @@ -157,7 +157,7 @@ function buildRules(ruleTuples) { } module.exports = { - detect: detectBrowser, + detect: detect, detectOS: detectOS, getNodeVersion: getNodeVersion, parseUserAgent: parseUserAgent From bf8dcf4756abc5f16d844fe880a460b154ba3c97 Mon Sep 17 00:00:00 2001 From: Damon Oehlman Date: Mon, 25 Sep 2017 18:31:24 +1000 Subject: [PATCH 5/5] examples and docs update --- README.md | 13 +++++++++++-- examples/simple.js | 3 ++- examples/switch.js | 3 ++- index.js | 7 +++++++ package.json | 1 + 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f6f6b75..4120212 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,18 @@ a semver compatible format) using a navigator useragent in a browser or [![stable](https://img.shields.io/badge/stability-stable-green.svg)](https://github.com/dominictarr/stability#stable) [![Build Status](https://api.travis-ci.org/DamonOehlman/detect-browser.svg?branch=master)](https://travis-ci.org/DamonOehlman/detect-browser) [![bitHound Score](https://www.bithound.io/github/DamonOehlman/detect-browser/badges/score.svg)](https://www.bithound.io/github/DamonOehlman/detect-browser) +## NOTE: Version 2.x release + +Release 2.0 introduces a breaking API change (hence the major release) +which requires invocation of a `detect` function rather than just inclusion of +the module. PR [#46](https://github.com/DamonOehlman/detect-browser/pull/46) +provides more context as to why this change has been made. + ## Example Usage ```js -const browser = require('detect-browser'); +const { detect } = require('detect-browser'); +const browser = detect(); // handle the case where we don't detect the browser if (browser) { @@ -26,7 +34,8 @@ if (browser) { Or you can use a switch statement: ```js -const browser = require('detect-browser'); +const { detect } = require('detect-browser'); +const browser = detect(); // handle the case where we don't detect the browser switch (browser && browser.name) { diff --git a/examples/simple.js b/examples/simple.js index fbd1c80..2987c48 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -1,4 +1,5 @@ -const browser = require('..'); +const { detect } = require('..'); +const browser = detect(); // handle the case where we don't detect the browser if (browser) { diff --git a/examples/switch.js b/examples/switch.js index 6936933..fe7e320 100644 --- a/examples/switch.js +++ b/examples/switch.js @@ -1,4 +1,5 @@ -const browser = require('..'); +const { detect } = require('..'); +const browser = detect(); // handle the case where we don't detect the browser switch (browser && browser.name) { diff --git a/index.js b/index.js index 7f93378..ce07847 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,13 @@ a semver compatible format) using a navigator useragent in a browser or `process.version` in node. + ## NOTE: Version 2.x release + + Release 2.0 introduces a breaking API change (hence the major release) + which requires invocation of a `detect` function rather than just inclusion of + the module. PR [#46](https://github.com/DamonOehlman/detect-browser/pull/46) + provides more context as to why this change has been made. + ## Example Usage <<< examples/simple.js diff --git a/package.json b/package.json index bcd690d..7dd470b 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ }, "homepage": "https://github.com/DamonOehlman/detect-browser", "devDependencies": { + "gendocs": "^2.0.0", "semver": "^5.0.3", "tape": "^4.2.2" }