Registry / http-networking / platform

platform

JSON →
library1.3.6jsnpmunverified

Platform.js is a lightweight JavaScript library designed for comprehensive platform, browser, OS, and device detection across nearly all JavaScript environments, including browsers, Node.js, and AMD loaders. It is currently stable at version 1.3.6, with the README referencing 1.3.5. As part of the BestieJS 'Best in Class' module collection, it emphasizes solid environment support, ES5+ compatibility, and thorough testing. A key differentiator is its detailed output, providing granular information like browser name, version, layout engine, OS, and device manufacturer. However, it explicitly states it is for informational purposes only and not a substitute for robust feature detection or inference checks, which is a crucial distinction from modern approaches to browser capabilities.

npm install platform
INSTALL
IMPORT
SIG · PLATFORM
P
platform
http-networkingjavascriptv1.3.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

platform
const platform = require('platform');
import platform from 'platform';
Primary usage pattern for Node.js environments and CommonJS modules. The library's `package.json` points to a CJS entry point. Direct ESM import is not officially supported or documented in current versions and may require a build step or Node.js's CJS interoperability.
platform
require(['platform'], function(platform) { /* use platform object */ });
Standard usage pattern for environments employing Asynchronous Module Definition (AMD) loaders like RequireJS.
platform
<script src="platform.js"></script> // platform is now a global variable
import { platform } from 'platform';
When included directly via a script tag in a browser, `platform` is exposed as a global object. There are no named exports for browser global usage.

This quickstart demonstrates how to initialize the library in a Node.js environment, access current platform properties, and parse a custom user-agent string.

const platform = require('platform'); console.log('--- Current Platform Information ---'); console.log(`Name: ${platform.name}`); console.log(`Version: ${platform.version}`); console.log(`Layout: ${platform.layout}`); console.log(`OS: ${platform.os}`); console.log(`Description: ${platform.description}`); console.log('\n--- Parsing a custom User Agent string ---'); const customUA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36 Edg/100.0.1185.36'; const parsedInfo = platform.parse(customUA); console.log(`Parsed Name: ${parsedInfo.name}`); console.log(`Parsed Version: ${parsedInfo.version}`); console.log(`Parsed Layout: ${parsedInfo.layout}`); console.log(`Parsed OS: ${parsedInfo.os}`); console.log(`Parsed Description: ${parsedInfo.description}`);
Debug
Known issues
gotchaPlatform.js is for informational purposes only and explicitly states it is not intended as a substitution for feature detection or inference checks. Relying on user-agent strings for feature availability is an anti-pattern.
fix
Always use modern feature detection (e.g., `if ('serviceWorker' in navigator)`) or rely on established polyfills and transpilers for compatibility, rather than inferring capabilities from browser strings.
affects: >=1.0.0
gotchaUser-agent string parsing is inherently fragile and prone to inaccuracies due to browser spoofing, changing UA formats, and new browser releases. The information provided by Platform.js may become outdated or incorrect over time without updates.
fix
Regularly update the `platform` package to benefit from the latest UA parsing logic. Be aware that even the latest version might not correctly identify very new or niche browsers/OSes immediately. Prioritize feature detection where possible.
affects: >=1.0.0
gotchaThe library primarily uses CommonJS (`require()`) and global browser patterns. While Node.js allows `import` of CJS modules, direct, optimized ESM imports (`import { name } from 'platform'`) are not explicitly supported or documented for this package version, which could affect bundler tree-shaking.
fix
When using ESM, stick to `import platform from 'platform'` (which will resolve to the CJS default export) or continue using `require('platform')`. If bundle size is a critical concern, consider alternatives that offer explicit ESM support with named exports.
affects: <=1.3.6
Errors
Common errors & fixes
ReferenceError: platform is not defined
The `platform.js` script was not loaded or executed correctly in a browser environment, or `require('platform')` failed in Node.js/AMD.
fix
Ensure `<script src="platform.js"></script>` is correctly placed and accessible in your HTML (before its usage). In Node.js, verify `npm install platform` was run and the `require` path is correct. For AMD, confirm the loader configuration is correct.
TypeError: Cannot read properties of undefined (reading 'name') (or similar property access errors)
The `platform` object itself is undefined, usually because the module failed to load or initialize, or the `require()` call returned `undefined`.
fix
Check the import/require statement. For CommonJS, `const platform = require('platform');`. For AMD, `require(['platform'], function(platform) { ... });`. In a browser, ensure the script loaded successfully and no other script overwrote the global `platform` object.
Error: "platform" is not a valid package in the project.
The package 'platform' is not listed in `package.json` or not installed in `node_modules`.
fix
Run `npm install platform` or `yarn add platform` to install the package and add it to your project's dependencies.
Upgrade
Version history
1.3.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
platform — npm install platform · libregistry