Platform.js

A platform detection library.

README

Platform.js v1.3.6


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

Disclaimer


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

Documentation


platform.js demo (See also whatsmyua.info for comparisons between platform.js and other platform detection libraries)

Installation


In a browser:

  1. ``` html
  2. <script src="platform.js"></script>
  3. ```

In an AMD loader:

  1. ``` js
  2. require(['platform'], function(platform) {/*…*/});
  3. ```

Using npm:

  1. ``` sh
  2. $ npm i --save platform
  3. ```

In Node.js:

  1. ``` js
  2. var platform = require('platform');
  3. ```

Usage example:

  1. ``` js
  2. // on IE10 x86 platform preview running in IE7 compatibility mode on Windows 7 64 bit edition
  3. platform.name; // 'IE'
  4. platform.version; // '10.0'
  5. platform.layout; // 'Trident'
  6. platform.os; // 'Windows Server 2008 R2 / 7 x64'
  7. platform.description; // 'IE 10.0 x86 (platform preview; running in IE 7 mode) on Windows Server 2008 R2 / 7 x64'

  8. // or on an iPad
  9. platform.name; // 'Safari'
  10. platform.version; // '5.1'
  11. platform.product; // 'iPad'
  12. platform.manufacturer; // 'Apple'
  13. platform.layout; // 'WebKit'
  14. platform.os; // 'iOS 5.0'
  15. platform.description; // 'Safari 5.1 on Apple iPad (iOS 5.0)'

  16. // or parsing a given UA string
  17. 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');
  18. info.name; // 'Opera'
  19. info.version; // '11.52'
  20. info.layout; // 'Presto'
  21. info.os; // 'Mac OS X 10.7.2'
  22. info.description; // 'Opera 11.52 (identifying as Firefox 4.0) on Mac OS X 10.7.2'
  23. ```

Support


Tested in Chrome 82-83, Firefox 77-78, IE 11, Edge 82-83, Safari 12-13, Node.js 4-14, & PhantomJS 2.1.1.

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, & plenty of documentation.