Platform.js v1.0.0

A platform detection library that works on nearly all JavaScript platforms1.

Disclaimer

Platform.js is for informational purposes only and not intended as a substitution for feature detection/inference checks.

BestieJS

Platform.js is part of the BestieJS “Best in Class” module collection. This means we promote solid browser/environment support, ES5 precedents, unit testing, and plenty of documentation.

Documentation

The documentation for Platform.js can be viewed here: /doc/README.md

For a list of upcoming features, check out our roadmap.

Support

Platform.js has been tested in at least Adobe AIR 3.1, Chrome 5-21, Firefox 1-14, IE 6-9, Opera 9.25-12, Safari 3-6, Node.js 0.8.6, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5.

Installation and usage

In a browser or Adobe AIR:

  1. <script src="platform.js"></script>

Via npm:

  1. npm install platform

In Node.js and RingoJS:

  1. var platform = require('platform');

In Rhino:

  1. load('platform.js');

In an AMD loader like RequireJS:

  1. require({
  2. 'paths': {
  3. 'platform': 'path/to/platform'
  4. }
  5. },
  6. ['platform'], function(platform) {
  7. console.log(platform.name);
  8. });

Usage example:

  1. // on IE10 x86 platform preview running in IE7 compatibility mode on Windows 7 64 bit edition
  2. platform.name; // 'IE'
  3. platform.version; // '10.0'
  4. platform.layout; // 'Trident'
  5. platform.os; // 'Windows Server 2008 R2 / 7 x64'
  6. platform.description; // 'IE 10.0 x86 (platform preview; running in IE 7 mode) on Windows Server 2008 R2 / 7 x64'
  7. // or on an iPad
  8. platform.name; // 'Safari'
  9. platform.version; // '5.1'
  10. platform.product; // 'iPad'
  11. platform.manufacturer; // 'Apple'
  12. platform.layout; // 'WebKit'
  13. platform.os; // 'iOS 5.0'
  14. platform.description; // 'Safari 5.1 on Apple iPad (iOS 5.0)'
  15. // or parsing a given UA string
  16. var info = platform.parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7.2; en; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 11.52');
  17. info.name; // 'Opera'
  18. info.version; // '11.52'
  19. info.layout; // 'Presto'
  20. info.os; // 'Mac OS X 10.7.2'
  21. info.description; // 'Opera 11.52 (identifying as Firefox 4.0) on Mac OS X 10.7.2'

Author

Contributors