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

inp

v1.35.0

Published

State-based input library for the browser.

Downloads

12

Readme

Inp

State based input library for the browser.


Installation:

Either install with npm or use a CDN such as unpkg (eg. https://unpkg.com/inp/index.js).

Usage:

import InputReader from 'path/to/inp.js';

let input = InputReader();
const frameRate = 1000/60;
function main() {
	/* input.down tells you if that button is down in the current frame / step. */
	if(input.down('a')) console.log('Key "A" pressed!');
	/* input.up does much the same as input.down but instead tells you if the button was released this frame */
	if(input.up('MouseLeft')) console.log('Left Mouse Button was released this timestep.');
	/* use input.mouse to get the position of the mouse this frame */
	console.log(input.mouse('x'), input.mouse('y'));
	console.log(input.mouse().x, input.mouse('both').y);
	/* and input.step at the end of you main loop to step forward. Nothing will work unless you do this. */
	input.step();
	setTimeout(main, frameRate);
}
main();

API:

InputReader.down(key: string): boolean

Takes in a string that is either a valid event.key, "MouseLeft", "MouseRight", "MouseMiddle", "MouseBack", or "MouseForward". Returns a boolean of whether it's down.


InputReader.up(key: string): boolean

Similar InputReader.down, tells you if a key has been released this timestep, takes the same arguments as InputReader.down.


InputReader.mouse(which?: string): number | Object

Takes in a string that is either "x", "y", or "both", returns the X position of the mouse, the Y position of the mouse, or {x: <number>, y: <number>}, respectively. If no argument is given it defaults to "both".


InputReader.step(): void

Steps forward once and updates everything. Required to be called before any inputs can be read correctly.


(: