🌐 simplify detecting your browser.
Clone or download
PIGNOSE
PIGNOSE fix vulnerability issue (#19)
* fix vulnerability issue

* fix hoek dependency version manually
Latest commit 307fb9a Jul 30, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist feature/update-version-0-2-27 (#16) Jun 8, 2018
docs feature/update-all-npm-dependencies (#14) Apr 30, 2018
examples merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
src added ipad support (#15) Jun 8, 2018
test
.babelrc migrate to typescript Dec 6, 2017
.codeclimate feature/increase code quality (#8) Apr 1, 2018
.coveralls.yml merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
.editorconfig merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
.eslintignore merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
.gitattributes merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
.gitignore merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
.travis.yml merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
LICENSE Initial commit May 13, 2017
README.md update README.md (#17) Jun 15, 2018
codecov.yml merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
logo.svg merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
package-lock.json fix vulnerability issue (#19) Jul 30, 2018
package.json fix vulnerability issue (#19) Jul 30, 2018
rollup.config.ts merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018
tsconfig.json feature/pull request 12 (#13) Apr 2, 2018
tslint.json merge pull request #5 from KennethanCeyer/feature/improve-deployment Mar 31, 2018

README.md

NPM

npm version npm Join the chat at https://gitter.im/KennethanCeyer/PIGNOSE GitHub stars License: MIT

Build Status Coverage Status codecov

CodeFactor Maintainability Test Coverage dependencies Status devDependencies Status

📦 Installation

npm

$ npm install browser-detect

yarn

$ yarn add browser-detect

📃 Example

Web

<script src="node_modules/browser-detect/dist/browser-detect.umd.js"></script>
const result = browserDetect();
console.log(result);

output

{
    name: 'chrome',
    version: '58.0.3029',
    versionNumber: 58.03029,
    mobile: false,
    os: 'Windows NT 10.0'
}

Web with module

import browser from 'browser-detect';

const result = browser();
console.log(result);

output

{
    name: 'chrome',
    version: '58.0.3029',
    versionNumber: 58.03029,
    mobile: false,
    os: 'Windows NT 10.0'
}

NodeJS

Just simple :trollface:

const browser = require('browser-detect');
const result = browser();

console.log(result);

output

{
    name: 'node',
    version: '9.9.0',
    versionNumber: 9.9,
    mobile: false,
    os: 'win32'
}

NodeJS with Express

const router = express.Router();
const browser = require('browser-detect');

router.get('/', req => {
    const result = browser(req.headers['user-agent']);
    console.log(result);
});

return router;

output

{
    name: 'ie',
    version: '9.0',
    versionNumber: 9,
    mobile: false,
    os: 'Windows NT 10.0'
}

Or set a middleware and send to res.locals.

// browserDetectMiddleware.js
const browser = require('browser-detect');

const MiddleWare = () => req => {
    res.locals.browser = browser(req.headers['user-agent']);
    next();
};

module.exports = MiddleWare;
// app.js

const express = require('express');
const browserDetectMiddleware = require('./browserDetectMiddleware');

const app = express();
app.use(browserDetectMiddleware())

View will can access browser variable.

<!-- view.ejs -->

<%=JSON.stringify(browser)%>

output

"{ name: 'firefox', version: '53.0.0', versionNumber: 53, mobile: false, os: 'Windows NT 10.0' }"

📃 Demo

Web

  • open examples/client.html by your browser.

NodeJS

  • open command or terminal
  • move directory to browser-detect path that you download
  • type following code
$ node ./examples/server.js

⚡️ Type

name type description example
name string a browser name ie, chrome, firefox
version string browser or node version 59.2.22
versionNumber number browser or node number casted to number 59.222
mobile boolean if browser is in mobile environment, it will be true true
os string os type name Windows NT 10.0

🚩 Roadmap

  • detect browser both compatible client and server
  • support AMD and CommonJS module feature
  • support typings
  • support guideline and documentations for contributors
  • support browser compatity to IE7
  • support to detect mobile and OS
  • support CI (TravisCI)
  • support unit tests
  • support e2e tests
  • suport cdn

🔎 Compatibility

  • IE 7+
  • Chrome (Windows, MacOS)
  • Edge
  • Firefox
  • Safari (Windows, MacOS)
  • Opera
  • Android
  • Chromium Browsers (Will be named chrome)

:octocat: Contribution

environment

  1. clone project from Github
$ git clone git@github.com:KennethanCeyer/browser-detect.git
  1. install npm packages
$ cd browser-detect
$ npm install
  1. build sources
$ npm run build

test

$ npm run test

💛 Contributors

🔎 License

FOSSA Status