Giter Club home page Giter Club logo

whoami.js's Introduction

Whoami.js is a lib that attempts to discover platform, os and browser of the user in a modular way.

Modular Way

You should only include module files that ACTUALLY make sense for your domain. This way the library can be smaller. Why test for iPad when you don't even provide an iPad version of your website?

Using whoami

Just include whoami.core.js and then the test files you want, like:

  • whoami.platforms.pc.js
  • whoami.platforms.mac.js
  • whoami.browsers.firefox.js
  • whoami.browsers.safari.js
  • whoami.browsers.chrome.js
  • whoami.browsers.ie.js
  • whoami.os.windows.js
  • whoami.os.macos.js
  • whoami.os.linux.js

Just to make sure, those are NOT all the available options, but those are just some examples. It should serve to prove the modular nature of whoami.

Creating My Own Module

Creating a module is as easy as creating a new call to whoami.register, like this::

whoami.register(whoami.platform, function(context) {
    //detects the browser or os or platform
    //the first argument specifies the type of check
    //if it is not this browser or platform or os, return false

    //if it's a platform detection set it
    context.platform = "ipad";

    //if it's an os detection set it
    context.os = "solaris";

    //if it's a browser detection set it
    context.browser = "safari";

});

Using whoami

After including in your page whoami and the modules you want (or a packaged version with all of them)::

if (whoami.platform == "pc" && 
    whoami.os == "windows" && 
    whoami.browser == "safari") {
    //does something ONLY for safari in windows in a pc
}

Modules

  • whoami.core.js - Core code for the library;
  • whoami.platform.android.js - Automatically identifies if the current user's platform is an android os;
  • whoami.platform.iphone.js - Automatically identifies if the current user's platform is an iphone;
  • whoami.platform.linux.js - Automatically identifies if the current user's platform is linux;
  • whoami.platform.windows.js - Automatically identifies if the current user's platform is windows;
  • whoami.platform.ipad.js - Automatically identifies if the current user's platform is an ipad;
  • whoami.platform.ipod.js - Automatically identifies if the current user's platform is an ipod;
  • whoami.platform.mac.js - Automatically identifies if the current user's platform is a mac;

whoami.js's People

Contributors

heynemann avatar

Stargazers

 avatar Kenji Yamamoto avatar

Watchers

 avatar James Cloos avatar  avatar

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.