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

gamepad-type

v1.0.2

Published

Detection and enumeration of gamepad types.

Downloads

4

Readme

gamepad-type

Determine gamepad models, brands, and layouts based on the user operating system.

Detects the following per gamepad:

  • gamepad model
  • gamepad brand
  • gamepad input names

based on hardcoded, pre-collected data. You are also able to define new values for each in case any data is missing.

If you notice incorrect mappings, please enter updated information on the demo page. Every browser, browser version, operating system, and operating system version combination produces different values so it's impossible for me to single-handedly account for them all.

It is encouraged that you use the package input-device-handler in conjunction with this one, but it is not required.

links

install

npm i gamepad-type

usage

The primary exports of this package are the following:

  • findMatchingGamepadModel: given the system-level gamepad id, determines the gamepad's model and brand. Also includes a model description string. Allows custom model and brand map inputs to handle edge cases that this package doesn't cover. (If you find those edge cases please either open a ticket in the GitHub repo or submit your fixed data on the demo page.)
  • findMatchingGamepadLayout: given the system-level gamepad id, determines the gamepad's button and axe names (based on gamepad model and user operating system). Allows custom model and input map inputs to handle edge cases that this package doesn't cover. (If you find those edge cases please either open a ticket in the GitHub repo or submit your fixed data on the demo page.)

examples

  • findMatchingGamepadModel

    import {InputDeviceHandler} from 'input-device-handler';
    import {findMatchingGamepadModel} from 'gamepad-type';
    
    // using window.navigator directly
    {
        const {gamepadBrand, gamepadModel, gamepadModelDescription} = findMatchingGamepadModel({
            gamepad: window.navigator.getGamepads()[0]?.id,
        });
    }
    
    // using InputDeviceHandler
    {
        const deviceHandler = new InputDeviceHandler();
    
        const {gamepadBrand, gamepadModel, gamepadModelDescription} = findMatchingGamepadModel({
            gamepad: deviceHandler.readAllDevices()[0],
        });
    }
  • findMatchingGamepadLayout

    import {InputDeviceHandler} from 'input-device-handler';
    import {findMatchingGamepadLayout} from 'gamepad-type';
    
    // using window.navigator directly
    {
        const maybeLayout = findMatchingGamepadLayout({
            gamepad: window.navigator.getGamepads()[0]?.id,
        });
    
        maybeLayout?.inputMappings;
    }
    
    // using InputDeviceHandler
    {
        const deviceHandler = new InputDeviceHandler();
    
        const maybeLayout = findMatchingGamepadLayout({
            gamepad: deviceHandler.readAllDevices()[0],
        });
    
        maybeLayout?.inputMappings;
    }

predefined mappings

You can access all predefined mappings and values with the following exported values:

  • PredefinedGamepadModel: an enum of known gamepad models.
  • PredefinedGamepadBrand: an enum of known gamepad brands.
  • predefinedGamepadModelDescriptions: a map of PredefinedGamepadModel to description strings.
  • defaultGamepadModelMap: a map of known gamepad ids / names to their known gamepad models.
  • defaultGamepadBrandMap: a map of known gamepad models to their known gamepad brands.
  • defaultGamepadLayouts: an array of all known gamepad layouts.