Huge News!Announcing our $40M Series B led by Abstract Ventures.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.28
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31K
decreased by-6.62%
Maintainers
1
Weekly downloads
 
Created
Source

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

:package: Installation

npm
$ npm install browser-detect
yarn
$ yarn add browser-detect

:page_with_curl: 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' }"

:page_with_curl: 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

:zap: Type

nametypedescriptionexample
namestringa browser nameie, chrome, firefox
versionstringbrowser or node version59.2.22
versionNumbernumberbrowser or node number casted to number59.222
mobilebooleanif browser is in mobile environment, it will be trueture
osstringos type nameWindows NT 10.0

:triangular_flag_on_post: 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

:mag_right: 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

:yellow_heart: Contributors

:mag_right: License

FOSSA Status

Keywords

FAQs

Package last updated on 08 Jun 2018

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