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

typing-monitor

v0.1.0

Published

Keyboard typing detection made easy

Downloads

1

Readme

Build Status Coverage Status License

Keyboard typing detection made easy.

Why?

TypingMonitor is a keyboard-input detection library for the web.

It helps you detect when a user starts or stops typing inside your app. One of the most common use cases of this library is detecting input/keyboard activity in messaging and chat-based applications.

Installation

To install TypingMonitor as a CommonJS module via a package manager:

# using npm
npm install --save typing-monitor

# using yarn
yarn add typing-monitor
import TypingMonitor from 'typing-monitor'

If you are not using a package manager or a module bundler, you can access the pre-compiled production and development UMD builds from here.

You can include the build file in a script tag on your page. The UMD builds make TypingMonitor available as a window.TypingMonitor global variable.

API

TypingMonitor offers 3 different interfaces to handle different scenarios:

new TypingMonitor.Static(options: Object)StaticTypingMonitor

Highlights

  • Meant to be used within an exiting input event handler (e.g. React's onInput).
  • TypingMonitor.Static is an alias of TypingMonitor
import TypingMonitor from 'typing-monitor';

const monitor = new TypingMonitor({/* options */});

// or

const monitor = new TypingMonitor.Static({/* options */});

Options

  • wait (Number): duration, in milliseconds, between each call to determine if the user has stopped typing.

Instance Methods

monitor.listen(listener: boolean → void)

Used to detect whether or not the user is typing.

Arguments
  1. listener: boolean → void: A callback function to be called every time the user started or stopped typing. Has one argument of type boolean indicating the typing status.

Example

import TypingMonitor from 'typing-monitor';

class MessageInput extends React.Component {
  componentDidMount() {
    const { discussion, user } = this.props;
    this.dbRef = db.ref(`/discussions/${discussion.id}/users/${user.id}`);
    // using TypingMonitor is the same as using TypingMonitor.Static
    this.typingMonitor = new TypingMonitor.Static({ wait: 1000 });
  }

  handleInput(e) {
    this.setState({ value: e.target.value });
    this.typingMonitor.listen((isTyping) => {
      this.dbRef.child('userTyping').set(isTyping);
    });
  }

  render() {
    return (
      <input onInput={this.handleInput} value={this.state.value} />
    );
  }
}

new TypingMonitor.Global(options)GlobalTypingMonitor

Highlights

  • Listens to the input event on the global/window.
  • New instances of GlobalTypingMonitor references a singleton.
  • Every monitor#listen registers a new listener.
  • Each monitor#listen returns a function to unsubscribe the listener.

Options

  • wait (Number): duration, in milliseconds, between each input change to determine if the user stopped typing.

Instance Methods

monitor.listen(listener: boolean → void): unsubscribe

Used to detect whether or not the user is typing.

Arguments
  1. listener (Function): A callback function to be called every time the user starts or stops typing. Has one argument of type boolean indicating the typing status.
Returns

unsubscribe (Function): A function that unsubscribes the listener

Example

import TypingMonitor from 'typing-monitor';

const globalMonitor = new TypingMonitor.Global({ wait: 1000 });

const unsubscribe = globalMonitor.listen((isTyping) => {
  console.log(isTyping ? 'user is typing' : 'user stopped typing');
});

unsubscribe(); // stop listening

new TypingMonitor.Listener(options)ListenerTypingMonitor

Highlights

  • Listens to the input event of the element passed to options.input
  • Works only on <input /> and <textarea />
  • Every monitor#listen registers a new listener

Options

  • wait (Number): duration, in milliseconds, between each input change to determine if the user stopped typing.
  • input: HTMLInputElement | HTMLTextAreaElement.

Instance Methods

monitor.listen(listener: boolean → void): unsubscribe

Used to detect whether or not the user is typing.

Arguments
  1. listener (Function): A callback function to be called every time the user starts or stops typing. Has one argument of type boolean indicating the typing status.
Returns

unsubscribe (Function): A function that unsubscribes the listener

Example

import TypingMonitor from 'typing-monitor';

const listenerMonitor = new TypingMonitor.Listener({
  input: document.querySelector('input.MyFancyInput'),
  wait: 1000,
});

const unsubscribe = listenerMonitor.listen((isTyping) => {
  console.log(isTyping ? 'typing' : 'stopped');
});

unsubscribe(); // stop listening

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

License

MIT