GithubHelp home page GithubHelp logo

agent-detection's Introduction

INFO

Agent detection is an small utility to detect commonly used user agents. It uses several approaches to detect user agents, most common userAgent chunk strings from the current userAgent String.

It also uses custom checks by feature in some situations, like the existence of documentMode property on internetExplorer 6-11 user agents.

This utility is intented to be used to add custom CSS classes to the HTML DOM element in order to style elements in different user agents, by doing for example:

.ua-ie .mycomponent { css only for ua-ie}

Code Example

Require the utility and use the public method to add the classes to element

  var AgentDetection  = require('agent-detection');
  var ag = new AgentDetection();
  ag.addClasses();

Also you can ask in your javascript code for an specific userAgent.

  var AgentDetection  = require('agent-detection');
  var ag = new AgentDetection();

  if( ag.isTouch() ) { ... }

Installation

To make it available in your projects, just install the package

npm i --save agent-detection

And require it with

var AgentDetection = require('agent-detection');

Tests

We use mocha to test the utility. To make the test available in a headless environment we use jsdom to mock some properties.

To run the tests:

npm run test

License

The MIT License (MIT)

agent-detection's People

Contributors

oscar-hanzo avatar sergiathanzo avatar katamo avatar ozke avatar

Stargazers

Adrian Carballo avatar

Watchers

Borja Delgado avatar Sergi Meseguer avatar  avatar James Cloos avatar  avatar Alejandro León avatar

Forkers

canufeel

agent-detection's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.