New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

browser-detect

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-detect

Simplify detecting your browser.

  • 0.2.22
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28K
decreased by-17.64%
Maintainers
1
Weekly downloads
 
Created
Source

browser-detect

Simplify detecting your browser.

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

Build Status Coverage Status codecov

GitHub forks Maintainability Test Coverage

dependencies Status devDependencies Status


This library helps you detect user's browser and version.
And this project is focusing to support client and server(Node).

Getting Started

Installation

* NPM

$ npm install browser-detect --save

* Bower

$ bower install browser-catch --save

* Yarn

$ yarn add browser-detect

* Download zip

Download zip file from this link


How to use

Client (browser)

Add following code in your head tag.

<script src="node_modules/browser-detect/dist/browser-detect.min.js"></script>

And follow this code to detect browser.

var result = browser();
console.log(result);
> { name: 'chrome', version: '58.0.3029', versionNumber: 58.03029, mobile: false, os: 'Windows NT 10.0' } # Chrome v58.0.3029

Server (node)

Just simple :trollface:

const browser = require('browser-detect');
const result = browser();
console.log(result);
> { name: 'node', version: '7.9.0', versionNumber: 7.9, mobile: false, os: 'win32' } # Node v7.9

Server (node with express)

Using req.headers like following code.

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

router.get('/', function (req, res, next) {
    var result = browser(req.headers['user-agent']);
    console.log(result);
});

return router;
> { name: 'ie', version: '9.0', versionNumber: 9, mobile: false, os: 'Windows NT 10.0' } # IE 9

Or set a middleware and send to res.locals.

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

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

module.exports = MiddleWare;
// app.js

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

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

View will can access browser variable.

<!-- view.ejs -->

<%=JSON.stringify(browser)%>
> { name: 'firefox', version: '53.0.0', versionNumber: 53, mobile: false, os: 'Windows NT 10.0' } // Firefox v 53.0.0

Values

  • name

    Name of browser such as ie, chrome, firefox.

  • version

    Version of browser with comma (string).

  • versionNumber

    Version of browser of which format is only number.

  • mobile

    If browser is based mobile device it will be true, and if is not false.

  • os

    User OS type such as Windows NT 10.0.


Try with an example

Client

  • Open examples/client.html by your browser.

Server

  • Open command or terminal.
  • Move directory to browser-detect path that you download.
  • Type following code.
$ node ./examples/server.js

Features

  • Detect browser both compatible client and server.
  • Support AMD and CommonJS module feature.

Completed

  • Support typings.
  • Support guideline and documentations for contributors.
  • Support browser compatity to IE7.
  • Support to detect mobile and OS.
  • Support Webpack2.x. (Including build process with reactjs or angular4.x)

Plan for near near, very near future.

  • Support TDD. (UnitTest, e2e Test)
  • Support CI. (TravisCI)
  • Suport CDN. (JSDelivr)

Compatibility

Test completed

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

Expected

  • IOS
  • Window phone (Edge)
  • IE 6

Contribution

Setting environment for contribute

  1. Install project from GitHub
$ git clone git@github.com:KennethanCeyer/browser-detect.git
  1. Install all modules from NPM
$ cd browser-detect
$ npm install
  1. Install npx
$ npm install npx -g
  1. Build sources
$ npm run build

Testing

  1. run npm scripts
$ npm run test
  1. if you need coverage report try as follows
$ npm run coverage

Linting

  1. browser-detect is used tslint
$ npm run lint

Contributors

  • vlewin vlewin
    • fix pattern issue #2
    • add unit test with mocha + chai

License

browser-detect is under MIT license

of cource, You can use it, modify it and contribute it :trollface:

Keywords

FAQs

Package last updated on 06 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc