What is platform?
The 'platform' npm package is a platform detection library that can be used to identify the operating system, browser, and engine of the platform on which the current script is running. It can be used in both browser and Node.js environments.
What are platform's main functionalities?
Operating System Detection
This feature allows you to detect the operating system of the user's device. The code sample demonstrates how to import the platform module and log the operating system information to the console.
const platform = require('platform');
console.log(platform.os);
Browser Detection
This feature enables you to detect the browser name and version. The code sample shows how to log the browser name and version to the console.
const platform = require('platform');
console.log(platform.name + ' ' + platform.version);
Engine Detection
This feature is used to detect the layout engine of the browser. The code sample illustrates how to log the layout engine information to the console.
const platform = require('platform');
console.log(platform.layout);
Device Detection
This feature allows you to detect the specific device (e.g., 'iPad', 'iPhone'). The code sample demonstrates how to log the device information to the console.
const platform = require('platform');
console.log(platform.product);
User-Agent Parsing
This feature provides a method to parse a user-agent string and extract detailed information about the platform. The code sample shows how to parse a user-agent string and log the resulting object.
const platform = require('platform');
const info = platform.parse('Mozilla/5.0 (Windows NT 10.0; Win64; x64)');
console.log(info);
Other packages similar to platform
ua-parser-js
ua-parser-js is a user-agent string parser that can detect browser, engine, OS, CPU, and device type/model from the user-agent string. It offers similar functionality to 'platform' but with a focus on user-agent string parsing and additional details like CPU architecture.
detect-browser
detect-browser is a simple package for detecting a browser. It is smaller and more lightweight than 'platform' but does not provide as much detailed information about the operating system or device.
bowser
bowser is a browser detection library that is more feature-rich than 'platform', providing detailed information about the browser, engine, platform, OS, and whether certain features are supported in the browser.
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.5-13, IE 6-9, Opera 9.25-12.01, 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:
<script src="platform.js"></script>
Via npm:
npm install platform
In Node.js and RingoJS:
var platform = require('platform');
In Rhino:
load('platform.js');
In an AMD loader like RequireJS:
require({
'paths': {
'platform': 'path/to/platform'
}
},
['platform'], function(platform) {
console.log(platform.name);
});
Usage example:
platform.name;
platform.version;
platform.layout;
platform.os;
platform.description;
platform.name;
platform.version;
platform.product;
platform.manufacturer;
platform.layout;
platform.os;
platform.description;
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');
info.name;
info.version;
info.layout;
info.os;
info.description;
Author
Contributors