npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

platform-utils

v1.2.0

Published

Helper functions for working with platform names in the Node.js vernacular (darwin|win32|linux). Works in Node.js and browsers.

Downloads

846

Readme

platform-utils

Helper functions for working with platform names in the Node.js vernacular (darwin, win32, linux). Works in Node.js and browsers.

Plays well with the Node.js core modules os.platform() and process.platform.

Installation

npm install platform-utils --save

Usage

This module exports an object with utility functions.

const {
  getPlatformFromFilename,
  getPlatformFromUserAgent,
  getPlatformLabel
} = require('platform-utils')

API

getPlatformFromFilename(filename)

  • filename String - e.g. dist/my-cool-app.dmg

Returns String darwin, win32, linux, or null.

Here's the gist of how the detection works:

if (ext === 'exe') return 'win32'
if (ext === 'zip' && parts.includes('win32')) return 'win32'
if (ext === 'zip' && parts.includes('windows')) return 'win32'
if (ext === 'zip' && parts.includes('win')) return 'win32'
if (ext === 'zip' && parts.includes('ia32')) return 'win32'

if (ext === 'dmg') return 'darwin'
if (ext === 'pkg') return 'darwin'
if (ext === 'zip' && parts.includes('osx')) return 'darwin'
if (ext === 'zip' && parts.includes('mac')) return 'darwin'
if (ext === 'zip' && parts.includes('macos')) return 'darwin'
if (ext === 'zip' && parts.includes('mas')) return 'darwin'
if (ext === 'zip' && parts.includes('darwin')) return 'darwin'

if (ext === 'rpm') return 'linux'
if (ext === 'deb') return 'linux'
if (ext === 'appimage') return 'linux'
if (ext === 'zip' && parts.includes('linux')) return 'linux'

getPlatformFromUserAgent([agent])

  • agent String (optional) - Can be omitted when used in the browser, where navigator.userAgent will be used automatically.

Returns String darwin, win32, linux, or null.

getPlatformLabel(platform)

  • platform String - Can be darwin, win32, or linux.

Returns String macOS, Windows, Linux, or null.

Tests

npm install
npm test

Dependencies

  • ua-parser-js: Lightweight JavaScript-based user-agent string parser

Dev Dependencies

  • buble: The blazing fast, batteries-included ES2015 compiler
  • chai: BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
  • mocha: simple, flexible, fun test framework
  • random-useragent: Get a random useragent (with an optional filter)
  • standard: JavaScript Standard Style
  • standard-markdown: Test your Markdown files for Standard JavaScript Style™

License

MIT