platform.js

A dependency-free JavaScript library that parses user-agent strings to identify browser, OS, device, and layout engine across almost any runtime.

Library
npm
v1.3.6
3,243stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity0
Maintenance0
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
68/100Good
Architecture70
Code Quality78
Innovation45
Learning Curve80

Platform.js is a small, dependency-free library that inspects the current environment — or a user-agent string you hand it — and returns a structured platform object describing what’s running: browser name and version, layout engine, operating system and architecture, device manufacturer and product, and more. It works nearly anywhere JavaScript runs: browsers, Node.js, PhantomJS, and other embedded engines, thanks to careful feature detection instead of assuming a DOM or a specific global.

Under the hood it’s a single self-contained UMD module (no build step, no runtime dependencies) that walks an internal table of known browser, OS, and product signatures and applies a large set of regular expressions and heuristics to the user-agent string, correcting for known quirks (browsers that spoof other browsers’ UA strings, layout engines that misreport themselves, etc.). The library exposes both a ready-made platform object for the current environment and a platform.parse(ua) function for parsing an arbitrary UA string, which is what makes it useful server-side for request logging and analytics as well as client-side for feature/compat messaging.

It has been part of the BestieJS “Best in Class” collection since 2011, with an emphasis on broad environment support, solid unit testing (a QUnit suite exercising a huge range of real-world UA strings), and thorough documentation. Development has slowed in recent years as the ecosystem shifts toward Client Hints and dedicated feature-detection libraries, but the library remains a stable, widely depended-upon building block (tens of millions of weekly downloads) for anyone who needs a quick, synchronous read on “what is this running on.”

What You Get

  • A ready-to-use platform object (name, version, layout, os, description, product, manufacturer) describing the current JS environment with zero configuration
  • platform.parse(ua) to parse any arbitrary user-agent string, useful for server-side request logging or analytics pipelines
  • Cross-environment support: works in browsers, Node.js, PhantomJS, and AMD/CommonJS/global loading contexts via a single UMD build
  • Corrections for common UA spoofing and misreporting quirks (e.g. browsers that identify as other browsers, or layout engines that misreport their own name)
  • A zero-dependency, single-file distribution with no build step required to consume

Common Use Cases

  • Logging structured browser/OS/device metadata alongside server-side request logs for analytics or support tooling
  • Tailoring UI messaging or feature-availability notices based on detected browser/layout engine rather than raw UA sniffing
  • Powering internal QA/bug-report tooling that needs to display a human-readable environment description alongside a stack trace
  • Normalizing inconsistent or spoofed user-agent strings from incoming traffic before further processing or classification

Under The Hood

Architecture The entire library is a single self-executing UMD wrapper in platform.js that detects its host (browser window, CommonJS exports/module, or an AMD loader via define) and exports one thing: the parse(ua) function and a pre-computed platform object built by calling it once against the current environment’s user-agent at load time. Internally, parse runs the UA string through an ordered set of small private helpers (cleanupOS, getLayout, getManufacturer, getProduct, and friends) that each apply a table of regular expressions for one facet of the result (OS family/version, layout engine, manufacturer, product), assembling the final object property-by-property; there’s no class hierarchy or dependency injection, just a flat set of pure string-matching functions composed in sequence, so changing the detection logic for one facet (say, OS naming) is isolated to its own helper.

Tech Stack Platform.js has zero runtime dependencies and targets ES5+ so it can run anywhere: browsers back to older IE, Node.js, PhantomJS, and Rhino/Java-hosted JS. Its devDependencies (qunitjs, qunit-extras, docdown, requirejs, replace) are used only for testing, generating the doc/README.md API reference, and the release/bump script — none ship to consumers. It’s distributed as a single UMD file with no bundler or transpilation step, installable via npm, Bower, or a plain <script> tag.

Code Quality The project has an extensive QUnit test suite (test/test.js, thousands of lines) that runs a very large number of real-world user-agent strings through parse() and asserts each detected field, plus environment-specific tests for AMD/CommonJS/global loading paths; CI is wired via Travis (.travis.yml) to run this suite across supported engines. Code style favors small, well-documented private helpers with full JSDoc-style comments explaining parameters and intent throughout platform.js; there’s no TypeScript or runtime type checking, and no linter/formatter config is present in the repo — correctness relies on the UA-string test corpus rather than static analysis.

What Makes It Unique What sets platform.js apart from a typical UA regex snippet is its breadth of environment-corrective heuristics — normalizing browsers that intentionally spoof other engines’ UA strings, correcting layout-engine misreporting, and covering an extensive manufacturer/product signature table (Apple, Samsung, Amazon, Nintendo, and many others) alongside standard browser/OS detection. Combined with true zero-dependency, any-JS-environment portability and a long-maintained BestieJS pedigree, it functions as a stable, well-tested primitive rather than a novel detection technique.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search