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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vanyamishra05/typing-stats-js

v1.0.1

Published

Zero-dependency, framework-agnostic typing metrics engine.

Readme

# typing-stats-js

A zero-dependency, framework-agnostic TypeScript/JavaScript library for calculating typing statistics.

It accepts target text and raw typing/keystroke data and returns useful typing metrics such as WPM, accuracy, errors, backspaces, consistency, and an error heatmap.

## Features

* WPM

* Raw WPM

* Accuracy

* Correct and incorrect character counts

* Backspace count

* Backspace ratio

* Error heatmap

* Typing consistency

* Typing duration

* Complete keystroke log

* recordKeystroke() API

* recordInput() API

* Unicode and multilingual text support

* TypeScript types

* Framework agnostic

* Browser and Node.js compatible

* Zero runtime dependencies

## Installation


npm install typing-stats-js

## Basic Usage


import { TypingSession } from "typing-stats-js";



const session = new TypingSession("hello world");



session.recordKeystroke({

  key: "h",

  timestamp: 0

});



session.recordKeystroke({

  key: "e",

  timestamp: 100

});



session.recordKeystroke({

  key: "l",

  timestamp: 200

});



session.recordKeystroke({

  key: "l",

  timestamp: 300

});



session.recordKeystroke({

  key: "o",

  timestamp: 400

});



const results = session.getResults();



console.log(results);

## Example Result

A result object contains:


{

  wpm: 150,

  rawWpm: 150,

  accuracy: 100,

  totalChars: 5,

  correctChars: 5,

  incorrectChars: 0,

  backspaceCount: 0,

  backspaceRatio: 0,

  errorHeatmap: {},

  consistency: 100,

  durationMs: 400,

  keystrokeLog: \[

    {

      key: "h",

      timestamp: 0,

      correct: true

    }

  ]

}

The exact values depend on the supplied timestamps and keystrokes.

## recordKeystroke()

Record individual keystrokes:


session.recordKeystroke({

  key: "h",

  timestamp: 1000

});

The correct property can be supplied explicitly:


session.recordKeystroke({

  key: "x",

  timestamp: 1100,

  correct: false

});

If correct is omitted, the session compares the typed character with the expected character from the target text.

### Backspace

Backspaces are recorded using:


session.recordKeystroke({

  key: "Backspace",

  timestamp: 1200

});

Every backspace press is counted separately.

## recordInput()

Applications that receive the current input value can use:


session.recordInput("hello", 1000);

For example:


const session = new TypingSession("hello world");



session.recordInput("hello", 1000);

session.recordInput("hello ", 2000);

session.recordInput("hello world", 3000);



console.log(session.getResults());

## Metrics

### WPM

Words per minute is calculated using the standard five-character word convention:


WPM = (correct characters / 5) / duration in minutes

### Raw WPM

Raw WPM uses all typed characters:


Raw WPM = (total typed characters / 5) / duration in minutes

### Accuracy


Accuracy = correct characters / total characters × 100

Incorrect characters that are later corrected using Backspace are still counted as errors.

### Error Heatmap

The error heatmap records how frequently individual characters were mistyped.

Example:


{

  x: 3,

  a: 2

}

This means x was mistyped three times and a was mistyped twice.

### Backspace Ratio


Backspace ratio = backspace count / total keystrokes

### Consistency

Typing consistency is calculated using five-second windows. WPM is calculated for each window and the variation between those windows is used to produce a consistency score.

## Unicode Support

The library supports Unicode and multilingual text.

For example:


const session = new TypingSession("नमस्ते दुनिया");



session.recordInput(

  "नमस्ते दुनिया",

  1000

);



console.log(session.getResults());

## Resetting a Session

Reset the current session:


session.reset();

After resetting, the session contains no recorded keystrokes.

## TypeScript

Types are exported:


import type {

  Keystroke,

  TypingResult

} from "typing-stats-js";

## Framework Agnostic

The core library does not require React, Vue, Angular, or another framework.

It can be used with:

* Plain JavaScript

* TypeScript

* React

* Vue

* Angular

* Node.js

* Browser applications

The core package does not use DOM or browser-specific APIs.

## Development

Install dependencies:


npm install

Run tests:


npm test

Run tests with coverage:


npm run coverage

Build the package:


npm run build

## Test Results

The project includes unit tests covering:

* WPM

* Raw WPM

* Accuracy

* Error heatmap

* Consistency

* Correct typing

* Incorrect typing

* Backspaces

* Corrected errors

* Unicode/Hindi text

* Reset functionality

* Invalid timestamps

Current test suite:


5 test files passed

21 tests passed

Coverage:


Overall lines:       94.69%

Overall statements:  94.69%

Overall branches:    94.20%

Overall functions:  100.00%



Metrics lines:       98.01%

Metrics branches:    97.22%

Metrics functions:  100.00%

## License

MIT