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

@smartupcorp/onedollar-unistroke-recognizer

v1.0.0

Published

A modern, strongly-typed TypeScript implementation of the $1 Unistroke Recognizer.

Readme

$1 Unistroke Recognizer

npm version License

A modern, strongly-typed, and modular TypeScript implementation of the famous $1 Unistroke Recognizer algorithm.

This library allows you to easily recognize drawn shapes and gestures (such as circles, rectangles, arrows, etc.) based on 2D coordinates. It is extremely lightweight, requires no machine learning models, and works perfectly in the browser.

Installation

Install the package using your preferred package manager:

# npm
npm install @smartupcorp/onedollar-unistroke-recognizer

# yarn
yarn add @smartupcorp/onedollar-unistroke-recognizer

# pnpm
pnpm add @smartupcorp/onedollar-unistroke-recognizer

Quick Start

1. Recognizing Default Gestures

By default, the recognizer can load 16 standard gestures (triangle, x, rectangle, circle, check, caret, zig-zag, arrow, left/right square brackets, v, delete, left/right curly braces, star, pigtail).

import {
  Point,
  DollarRecognizer,
  DEFAULT_GESTURES,
} from "@smartupcorp/onedollar-unistroke-recognizer";

// Initialize with all default gestures
const recognizer = new DollarRecognizer(DEFAULT_GESTURES);

// Assume `userPoints` is an array of Point objects captured from pointer events
const userPoints = [new Point(10, 10), new Point(12, 15) /* ... */];

// Recognize the gesture (second argument is `useProtractor` for faster/accurate matching)
// Returns a sorted array of Result objects (highest score first)
const results = recognizer.recognize(userPoints, true);

if (results.length > 0) {
  const bestMatch = results[0];
  console.log(
    `Recognized as: ${bestMatch.name} (Score: ${Math.round(bestMatch.score * 100)}%)`,
  );

  // You can also check the second-best match
  if (results[1]) {
    console.log(`Second guess: ${results[1].name}`);
  }
}

2. Loading Specific Gestures Only (Recommended)

If your application only needs to recognize a specific shape (e.g., only a "circle"), you can pass it directly to the constructor. This prevents false positives from other shapes and improves performance.

import { Point, DollarRecognizer, CIRCLE_GESTURE } from '@smartupcorp/onedollar-unistroke-recognizer';

// Initialize with ONLY the circle gesture
const recognizer = new DollarRecognizer([CIRCLE_GESTURE]);

const results = recognizer.recognize(userPoints, true);

// Check if the best match meets your score threshold (e.g., 80%)
if (results.length > 0 && results[0].name === "circle" && results[0].score >= 0.8) {
    console.log("A circle was drawn!");
} else {
    console.log("Not a circle.");
}

3. Adding Custom Gestures

You can dynamically teach the recognizer new gestures created by users.

// Clear existing gestures and start fresh
const recognizer = new DollarRecognizer([]);

// Add a custom gesture (requires an array of Points representing the new shape)
recognizer.addGesture("my-custom-shape", userDrawnPoints);

License

This project is licensed under the New BSD License - see the LICENSE file for details.

Acknowledgements

The core algorithm is a TypeScript port of the $1 Unistroke Recognizer originally developed by:

  • Jacob O. Wobbrock, Ph.D. (University of Washington)
  • Andrew D. Wilson, Ph.D. (Microsoft Research)
  • Yang Li, Ph.D. (University of Washington)

Wobbrock, J.O., Wilson, A.D. and Li, Y. (2007). Gestures without libraries, toolkits or training: A $1 recognizer for user interface prototypes. Proceedings of the ACM Symposium on User Interface Software and Technology (UIST '07). Newport, Rhode Island (October 7-10, 2007). New York: ACM Press, pp. 159-168.

The Protractor enhancement was separately published by Yang Li: Li, Y. (2010). Protractor: A fast and accurate gesture recognizer. Proceedings of the ACM Conference on Human Factors in Computing Systems (CHI '10). Atlanta, Georgia (April 10-15, 2010). New York: ACM Press, pp. 2169-2172.

Original C#/JavaScript code is distributed under the New BSD License.